Skip to content

Commit 60a6836

Browse files
committed
Initial commit
1 parent 0daad72 commit 60a6836

File tree

6 files changed

+1250
-2
lines changed

6 files changed

+1250
-2
lines changed

README.md

Lines changed: 36 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,36 @@
1-
# M5Dial
2-
M5Dial ESPhome PoC
1+
# M5 Dial ESPHome with LVGL graphics
2+
3+
This is my PoC on how to use the M5 Dial in combination with Home Assistant entities. I want to use the M5 Dial as a remote for Home Assistant and this implementation shows the possibilities with, i think, some decent feedback from the interface. Its not perfect, but its a nice start for anyone looking for stuff like this.
4+
5+
Take a look at the video of this PoC
6+
https://youtu.be/dOgFMksxVvw
7+
8+
## Features
9+
10+
### Multi use rotary encoder
11+
12+
This PoC allows you to use the rotary encoder in different ways depending on the state it is in. The main goal is to create scrollable pages, and when a pages is entered (through clicking the M5 dial button), the scroll wheel can be used on a widget on that screen. This is done on the first page with the volume control of a media player. On the second page the thermostat can be set higher and lower, and on the third page a slider for the brightness can be altered after the pages is selected. To leave a page, a double click of the button needs to be used.
13+
14+
There is a template button sensor that is used as `enter_button` on the lvgl widget. This way that template button can be clicked when needed. Nothing is implemented, except that the button is not pushed when the rotary encoder is in page scroll mode. When it is in page specific widget scroll mode, it could be used as an enter button.
15+
16+
### Visual feedback
17+
18+
There are breadcrumbs to show on which page you are. This done with 3 arcs that are highlited based on the page that is visible. When the button is in widget scroll mode, an arc the size of all three breadcrumbs is layered over. And last but not least, when the screen goes idle, an arc in the color of the background is layed over. For now every action first unpauses the screen and immediately executes the action, these could be seperate actions.
19+
20+
The thermostat scroller and the thermostat label will go into blinking mode to show that it is waiting until Home Assistant reports the change back. The new state of the scroller and the target temperature are stored locally and displayed in the widgets, a script waits until the Home Assistant Component of the related entity reports the new setting back.
21+
22+
### Input select support
23+
24+
The select [example](https://esphome.io/components/select/lvgl.html) with a roller (or even a dropdown) will throw my M5 dial into a reboot, bacause of that I have created a function that converts the string of items of a lvgl roller into an array. This way a selected index can be converted into the corresponding text value and that can be sent to Home Assistant. This can also be done vica versa, when an update comes from Home Assistant, the correct index can be set at the roller widget.
25+
26+
### Idle activity
27+
28+
When the screen is in an idle state, the screen does not update when there is a new value from Home Assistant. A few components have the `resume_lvgl` so the screen will be updated. This is regardless of the active screen.
29+
30+
### Scripts
31+
32+
A script is used to alter an Home Assistant entry, this way a delay can be used and therefor not every action is sent to HA immediately. It also allows for canceling an action if needed.
33+
34+
### lv_color_hex
35+
36+
`lv_color_hex` does not work with color substitutes because they are `ESPHOME::Color` and not `lv_color_t`. This means defining the hex twice, but not with `esphomeColorToHex`. This converts the `ESPHOME::Color` to a hexadicmal value which can be used by `lv_color_hex`.

common/colors.yaml

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
color:
2+
- id: white_color
3+
hex: "FFFFFF"
4+
- id: lightsteel_blue
5+
hex: "CAD3F5"
6+
- id: very_dark_grey_color
7+
hex: "272828"
8+
- id: light_grey_color
9+
hex: "575858"
10+
- id: black_color
11+
hex: "000000"
12+
13+
# Green Colors
14+
- id: ice_green_color
15+
hex: "8ab65e"
16+
- id: ligt_green_color
17+
hex: "6e914b"
18+
- id: mid_green_color
19+
hex: "526d38"
20+
- id: dark_green_color
21+
hex: "374825"
22+
23+
# Blue Colors
24+
- id: ice_blue_color
25+
hex: "739BD0"
26+
- id: light_blue_color
27+
hex: "5c7ca6"
28+
- id: mid_blue_color
29+
hex: "455d7c"
30+
- id: dark_blue_color
31+
hex: "2e3e53"
32+
33+
# Red Colors
34+
- id: ice_red_color
35+
hex: "fc6d6d"
36+
- id: light_red_color
37+
hex: "c95757"
38+
- id: mid_red_color
39+
hex: "974141"
40+
- id: dark_red_color
41+
hex: "642b2b"
42+
43+
# Orange Colors
44+
- id: ice_orange_color
45+
hex: "ef9c5d"
46+
- id: light_orange_color
47+
hex: "bf7c4a"
48+
- id: mid_orange_color
49+
hex: "8f5d37"
50+
- id: dark_orange_color
51+
hex: "5f3e25"
52+
53+
# Yellow Colors
54+
- id: light_yellow_color
55+
hex: "B58B00"

fonts/Roboto-Medium.ttf

165 KB
Binary file not shown.

fonts/materialdesignicons-webfont.ttf

1.25 MB
Binary file not shown.

hfiles/m5dial.h

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
#include <sstream>
2+
#include <iostream>
3+
4+
unsigned long esphomeColorToHex(esphome::Color color)
5+
{
6+
return ((color.r & 0xff) << 16) + ((color.g & 0xff) << 8) + (color.b & 0xff);
7+
}
8+
9+
static std::vector<std::string> splitSelectValues(const char* lineToSplit)
10+
{
11+
std::stringstream origStream;
12+
origStream << lineToSplit;
13+
std::vector<std::string> lineList;
14+
std::string curLine;
15+
while (std::getline(origStream, curLine))
16+
{
17+
// Only add non empty lines.
18+
if (!curLine.empty())
19+
lineList.push_back(curLine);
20+
}
21+
22+
return lineList;
23+
}

0 commit comments

Comments
 (0)