Heizungsnamen nicht mehr umbrechen, Farbwahl für Lampen
Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
This commit is contained in:
1 parent
ecab22386e
commit
8bbd9a0dfe
2 files changed
+83
-8
No files matched your search
@@ -3,7 +3,7 @@
|
||||
Touch-Dashboard für das ESP32-2432S028R ("Cheap Yellow Display"), das Heizkörper und Lampen über Home Assistant steuert.
|
||||
|
||||
- **Heizung-Tab:** Ist- und Solltemperatur, Modus, Heizsymbol bei aktivem Heizen. Mit +/- stellst du die Solltemperatur ein; sie wird 1,2 s nach dem letzten Tippen gesendet und ist bis dahin gelb.
|
||||
- **Licht-Tab:** Ein/Aus-Schalter. Dimmbare Lampen bekommen automatisch einen Helligkeitsregler. `switch.*`-Entitäten funktionieren auch.
|
||||
- **Licht-Tab:** Ein/Aus-Schalter. Dimmbare Lampen bekommen automatisch einen Helligkeitsregler, Farblampen zusätzlich einen Farbregler (Knopf zeigt die Farbe) und "Ww" für Warmweiß. `switch.*`-Entitäten funktionieren auch.
|
||||
- Uhrzeit über NTP, WLAN-Signalstärke (Balken + dBm), WLAN- und HA-Status, Display geht nach 60 s ohne Bedienung aus (Tippen weckt es wieder).
|
||||
|
||||
## Einrichtung
|
||||
|
||||
+82
-7
@@ -56,6 +56,8 @@ struct ClimateUi {
|
||||
struct LightUi {
|
||||
lv_obj_t* sw = nullptr;
|
||||
lv_obj_t* slider = nullptr;
|
||||
lv_obj_t* hue = nullptr;
|
||||
lv_obj_t* white = nullptr;
|
||||
lv_obj_t* card = nullptr;
|
||||
uint32_t ignoreUntil = 0; // ignore poll results right after a command
|
||||
};
|
||||
@@ -225,18 +227,40 @@ static void applyLight(size_t i, JsonDocument& doc) {
|
||||
else lv_obj_clear_state(u.sw, LV_STATE_DISABLED);
|
||||
|
||||
if (!u.slider) return;
|
||||
// Only show the slider if the lamp is dimmable.
|
||||
// Only show the sliders if the lamp supports them.
|
||||
JsonArray modes = doc["attributes"]["supported_color_modes"];
|
||||
bool dimmable = !modes.isNull() && modes.size() > 0 && strcmp(modes[0] | "onoff", "onoff") != 0;
|
||||
bool dimmable = false, colorable = false;
|
||||
for (JsonVariant m : modes) {
|
||||
const char* ms = m | "onoff";
|
||||
if (strcmp(ms, "onoff")) dimmable = true;
|
||||
if (!strcmp(ms, "hs") || !strcmp(ms, "rgb") || !strcmp(ms, "rgbw") || !strcmp(ms, "rgbww") || !strcmp(ms, "xy"))
|
||||
colorable = true;
|
||||
}
|
||||
int h = 52;
|
||||
if (dimmable) {
|
||||
lv_obj_clear_flag(u.slider, LV_OBJ_FLAG_HIDDEN);
|
||||
lv_obj_set_height(u.card, 84);
|
||||
h += 32;
|
||||
int b = doc["attributes"]["brightness"] | 0;
|
||||
if (!lv_slider_is_dragged(u.slider)) lv_slider_set_value(u.slider, on ? max(1, b * 100 / 255) : 0, LV_ANIM_OFF);
|
||||
} else {
|
||||
lv_obj_add_flag(u.slider, LV_OBJ_FLAG_HIDDEN);
|
||||
lv_obj_set_height(u.card, 52);
|
||||
}
|
||||
if (colorable) {
|
||||
lv_obj_clear_flag(u.hue, LV_OBJ_FLAG_HIDDEN);
|
||||
lv_obj_clear_flag(u.white, LV_OBJ_FLAG_HIDDEN);
|
||||
lv_obj_align(u.hue, LV_ALIGN_TOP_LEFT, 4, h - 6);
|
||||
lv_obj_align(u.white, LV_ALIGN_TOP_RIGHT, 0, h - 14);
|
||||
h += 32;
|
||||
JsonArray hs = doc["attributes"]["hs_color"];
|
||||
if (!lv_slider_is_dragged(u.hue) && !hs.isNull() && hs.size() == 2) {
|
||||
lv_slider_set_value(u.hue, (int)(hs[0] | 0.0f), LV_ANIM_OFF);
|
||||
lv_event_send(u.hue, LV_EVENT_VALUE_CHANGED, nullptr);
|
||||
}
|
||||
} else {
|
||||
lv_obj_add_flag(u.hue, LV_OBJ_FLAG_HIDDEN);
|
||||
lv_obj_add_flag(u.white, LV_OBJ_FLAG_HIDDEN);
|
||||
}
|
||||
lv_obj_set_height(u.card, h);
|
||||
}
|
||||
|
||||
static bool pollEntity(size_t idx) {
|
||||
@@ -292,6 +316,34 @@ static void onLightSlider(lv_event_t* e) {
|
||||
}
|
||||
}
|
||||
|
||||
static void onHueChanged(lv_event_t* e) {
|
||||
lv_obj_t* sl = lv_event_get_target(e);
|
||||
lv_obj_set_style_bg_color(sl, lv_color_hsv_to_rgb(lv_slider_get_value(sl), 100, 100), LV_PART_KNOB);
|
||||
}
|
||||
|
||||
static void onHueReleased(lv_event_t* e) {
|
||||
size_t i = (size_t)(intptr_t)lv_event_get_user_data(e);
|
||||
JsonDocument doc;
|
||||
doc["entity_id"] = LIGHTS[i].entity;
|
||||
JsonArray hs = doc["hs_color"].to<JsonArray>();
|
||||
hs.add(lv_slider_get_value(lightUi[i].hue));
|
||||
hs.add(100);
|
||||
lightUi[i].ignoreUntil = millis() + 3000;
|
||||
lv_obj_add_state(lightUi[i].sw, LV_STATE_CHECKED);
|
||||
callService("light", "turn_on", doc);
|
||||
}
|
||||
|
||||
static void onWhite(lv_event_t* e) {
|
||||
size_t i = (size_t)(intptr_t)lv_event_get_user_data(e);
|
||||
JsonDocument doc;
|
||||
doc["entity_id"] = LIGHTS[i].entity;
|
||||
doc["color_temp_kelvin"] = 3000;
|
||||
lightUi[i].ignoreUntil = millis() + 3000;
|
||||
lv_obj_add_state(lightUi[i].sw, LV_STATE_CHECKED);
|
||||
if (!callService("light", "turn_on", doc)) return;
|
||||
lv_obj_set_style_bg_color(lightUi[i].hue, lv_color_hex(0xffd9a0), LV_PART_KNOB);
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------- UI construction
|
||||
static lv_obj_t* makeCard(lv_obj_t* parent, int h) {
|
||||
lv_obj_t* c = lv_obj_create(parent);
|
||||
@@ -382,7 +434,7 @@ static void populateUi() {
|
||||
lv_obj_t* name = lv_label_create(c);
|
||||
lv_obj_set_style_text_font(name, &lv_font_montserrat_20, 0);
|
||||
lv_label_set_long_mode(name, LV_LABEL_LONG_DOT);
|
||||
lv_obj_set_width(name, 125);
|
||||
lv_obj_set_size(name, 125, 26);
|
||||
lv_label_set_text(name, CLIMATES[i].name.c_str());
|
||||
lv_obj_align(name, LV_ALIGN_TOP_LEFT, 0, -2);
|
||||
|
||||
@@ -409,7 +461,7 @@ static void populateUi() {
|
||||
lv_obj_t* name = lv_label_create(c);
|
||||
lv_obj_set_style_text_font(name, &lv_font_montserrat_20, 0);
|
||||
lv_label_set_long_mode(name, LV_LABEL_LONG_DOT);
|
||||
lv_obj_set_width(name, 200);
|
||||
lv_obj_set_size(name, 200, 26);
|
||||
lv_label_set_text(name, LIGHTS[i].name.c_str());
|
||||
lv_obj_align(name, LV_ALIGN_TOP_LEFT, 0, 4);
|
||||
|
||||
@@ -422,9 +474,30 @@ static void populateUi() {
|
||||
lightUi[i].slider = lv_slider_create(c);
|
||||
lv_slider_set_range(lightUi[i].slider, 0, 100);
|
||||
lv_obj_set_width(lightUi[i].slider, lv_pct(92));
|
||||
lv_obj_align(lightUi[i].slider, LV_ALIGN_BOTTOM_MID, 0, -6);
|
||||
lv_obj_align(lightUi[i].slider, LV_ALIGN_TOP_MID, 0, 42);
|
||||
lv_obj_add_flag(lightUi[i].slider, LV_OBJ_FLAG_HIDDEN);
|
||||
lv_obj_add_event_cb(lightUi[i].slider, onLightSlider, LV_EVENT_RELEASED, (void*)(intptr_t)i);
|
||||
|
||||
// Colour: hue slider (knob shows the colour) + button for warm white
|
||||
lightUi[i].hue = lv_slider_create(c);
|
||||
lv_slider_set_range(lightUi[i].hue, 0, 360);
|
||||
lv_obj_set_width(lightUi[i].hue, lv_pct(78));
|
||||
lv_obj_set_style_bg_color(lightUi[i].hue, lv_color_hex(0x3a444e), LV_PART_MAIN);
|
||||
lv_obj_set_style_bg_opa(lightUi[i].hue, LV_OPA_COVER, LV_PART_MAIN);
|
||||
lv_obj_set_style_bg_opa(lightUi[i].hue, LV_OPA_TRANSP, LV_PART_INDICATOR);
|
||||
lv_obj_set_style_bg_color(lightUi[i].hue, lv_color_hex(0xffd9a0), LV_PART_KNOB);
|
||||
lv_obj_set_style_pad_all(lightUi[i].hue, 4, LV_PART_KNOB);
|
||||
lv_obj_add_flag(lightUi[i].hue, LV_OBJ_FLAG_HIDDEN);
|
||||
lv_obj_add_event_cb(lightUi[i].hue, onHueChanged, LV_EVENT_VALUE_CHANGED, nullptr);
|
||||
lv_obj_add_event_cb(lightUi[i].hue, onHueReleased, LV_EVENT_RELEASED, (void*)(intptr_t)i);
|
||||
|
||||
lightUi[i].white = lv_btn_create(c);
|
||||
lv_obj_set_size(lightUi[i].white, 44, 28);
|
||||
lv_obj_t* wl = lv_label_create(lightUi[i].white);
|
||||
lv_label_set_text(wl, "Ww");
|
||||
lv_obj_center(wl);
|
||||
lv_obj_add_flag(lightUi[i].white, LV_OBJ_FLAG_HIDDEN);
|
||||
lv_obj_add_event_cb(lightUi[i].white, onWhite, LV_EVENT_CLICKED, (void*)(intptr_t)i);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -482,6 +555,8 @@ static bool discoverDevices() {
|
||||
String id = ids[i] | "";
|
||||
String nm = asciiName(String(names[i] | ""));
|
||||
dst[n].entity = id;
|
||||
if (nm.startsWith("Heizung ") && nm.length() > 8) nm = nm.substring(8);
|
||||
else if (nm.startsWith("Licht ") && nm.length() > 6) nm = nm.substring(6);
|
||||
dst[n].name = nm.length() ? nm : id;
|
||||
n++;
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user