diff --git a/common/nspanel_terminal/action_tile.yaml b/common/nspanel_terminal/action_tile.yaml new file mode 100644 index 0000000..7e65180 --- /dev/null +++ b/common/nspanel_terminal/action_tile.yaml @@ -0,0 +1,14 @@ +# Package: tile on a grid page that calls a Home Assistant action on an entity (e.g. button.press). +# Its checked/disabled states are up to the owner (e.g. gate.yaml). Tiles fill the page in package order. +# vars: page, id, name, icon (MDI glyph, must be in icon_s), action, entity +lvgl: + pages: + - id: !extend ${page} + widgets: + - button: + <<: !include {file: tile.yaml, vars: {id: "${id}", name: "${name}", icon: "${icon}"}} + on_click: + - homeassistant.action: + action: ${action} + data: + entity_id: ${entity} diff --git a/common/nspanel_terminal/forecast_day.yaml b/common/nspanel_terminal/forecast_day.yaml new file mode 100644 index 0000000..e2fe640 --- /dev/null +++ b/common/nspanel_terminal/forecast_day.yaml @@ -0,0 +1,49 @@ +# One forecast row: day, icon, day/night temperature on two lines, all centred vertically. +# Not clickable, so a tap falls through to the home page. +obj: + clickable: false + width: SIZE_CONTENT + height: SIZE_CONTENT + bg_opa: TRANSP + border_width: 0 + pad_all: 0 + layout: + type: FLEX + flex_flow: ROW + flex_align_cross: CENTER + pad_column: 10 + widgets: + - label: + id: forecast_day_${i} + text: "" + text_font: font_s + text_color: 0xB4B4BA + width: 26 + text_align: RIGHT + - label: + id: forecast_icon_${i} + text: "" + text_font: icon_s + text_color: 0xFFFFFF + - obj: + clickable: false + width: SIZE_CONTENT + height: SIZE_CONTENT + bg_opa: TRANSP + border_width: 0 + pad_all: 0 + layout: + type: FLEX + flex_flow: COLUMN + pad_row: 0 + widgets: + - label: + id: forecast_high_${i} + text: "" + text_font: font_s + text_color: 0xFFFFFF + - label: + id: forecast_low_${i} + text: "" + text_font: font_s + text_color: 0x8E8E93 diff --git a/common/nspanel_terminal/gate.yaml b/common/nspanel_terminal/gate.yaml new file mode 100644 index 0000000..5ff68a0 --- /dev/null +++ b/common/nspanel_terminal/gate.yaml @@ -0,0 +1,55 @@ +# Package: gate state tile (two slots) on a grid page, and the state of the gate_open/gate_close action tiles +# vars: page, state (select with Open/Closed/Opening/Closing) +lvgl: + pages: + - id: !extend ${page} + widgets: + # highlighted while not closed + - obj: + id: gate_state_tile + clickable: false + width: 272 + height: 112 + styles: tile_style + checked: + bg_color: 0xF5B342 + text_color: 0x000000 + disabled: + bg_color: 0x161618 + text_color: 0x48484A + widgets: + - label: + id: gate_state_icon + text: "" + text_font: icon_l + align: LEFT_MID + - label: + id: gate_state_label + text: "" + align: LEFT_MID + x: 64 + +text_sensor: + - platform: homeassistant + id: gate_state + entity_id: ${state} + internal: true + on_value: + - lambda: |- + static const char *const STATES[][3] = {{"Open", "Otvorená", "\U000F116A"}, + {"Closed", "Zatvorená", "\U000F0299"}, + {"Opening", "Otvára sa", "\U000F1169"}, + {"Closing", "Zatvára sa", "\U000F17F7"}}; + const char *text = x.c_str(), *icon = "\U000F17F8"; + for (auto &s : STATES) + if (x == s[0]) text = s[1], icon = s[2]; + lv_label_set_text(id(gate_state_label), text); + lv_label_set_text(id(gate_state_icon), icon); + // highlighted unless closed + lv_obj_set_state(id(gate_state_tile), LV_STATE_CHECKED, x != "Closed"); + // the button of the running movement + lv_obj_set_state(id(gate_open), LV_STATE_CHECKED, x == "Opening"); + lv_obj_set_state(id(gate_close), LV_STATE_CHECKED, x == "Closing"); + // gate controller offline: grey out the whole gate page + for (lv_obj_t *o : {(lv_obj_t *) id(gate_open), (lv_obj_t *) id(gate_close), id(gate_state_tile)}) + lv_obj_set_state(o, LV_STATE_DISABLED, ha_unavailable(x)); diff --git a/common/nspanel_terminal/grid_page.yaml b/common/nspanel_terminal/grid_page.yaml new file mode 100644 index 0000000..cadd45d --- /dev/null +++ b/common/nspanel_terminal/grid_page.yaml @@ -0,0 +1,17 @@ +# Grid page (list item of lvgl pages): title and arrows; the 2x3 tiles come from the *_tile.yaml packages +# vars: id, title, prev, next (page ids for the arrows), skip (hidden page: out of the page cycle, no next arrow) +id: ${id} +skip: ${skip} +styles: page_style +layout: + type: FLEX + flex_flow: ROW_WRAP +widgets: + - label: + text: "${title}" + text_font: font_s + text_color: 0xB4B4BA + width: 100% + text_align: CENTER + - <<: !include {file: page_arrow.yaml, vars: {icon: "\U000F0141", align: TOP_LEFT, x: -16, to: "${prev}", hidden: false}} + - <<: !include {file: page_arrow.yaml, vars: {icon: "\U000F0142", align: TOP_RIGHT, x: 16, to: "${next}", hidden: "${skip}"}} diff --git a/common/nspanel_terminal/ha.h b/common/nspanel_terminal/ha.h new file mode 100644 index 0000000..522968c --- /dev/null +++ b/common/nspanel_terminal/ha.h @@ -0,0 +1,5 @@ +#pragma once +#include + +// Home Assistant entity state that means "no usable value": the tile is shown greyed out and disabled +inline bool ha_unavailable(const std::string &s) { return s.empty() || s == "unavailable" || s == "unknown"; } diff --git a/common/nspanel_terminal/light.h b/common/nspanel_terminal/light.h new file mode 100644 index 0000000..9effed5 --- /dev/null +++ b/common/nspanel_terminal/light.h @@ -0,0 +1,17 @@ +#pragma once +#include +#include +#include +#include + +// HA brightness 0..255 -> slider percent; NaN (light off) -> 0 +inline int brightness_pct(float b) { return std::isnan(b) ? 0 : int(std::lround(b * 100 / 255)); } + +// Hue from the hs_color attribute, "(30.0, 80.0)" or "[30.0, 80.0]"; -1 if missing +inline int parse_hue(const std::string &s) { + size_t p = s.find_first_of("(["); + if (p == std::string::npos) return -1; + char *end; + float h = std::strtof(s.c_str() + p + 1, &end); + return end == s.c_str() + p + 1 ? -1 : int(std::lround(h)); +} diff --git a/common/nspanel_terminal/light_tile.yaml b/common/nspanel_terminal/light_tile.yaml new file mode 100644 index 0000000..1c63762 --- /dev/null +++ b/common/nspanel_terminal/light_tile.yaml @@ -0,0 +1,63 @@ +# Package: Home Assistant light as a tile on a grid page, with its state. Tap toggles, long press opens page_light. +# Tiles fill the page in package order. +# vars: page, id, name, entity, icon (MDI glyph, must be in icon_s), +# dim (brightness), kmin (lowest colour temperature in K, 0 = none), hs (hue) +lvgl: + pages: + - id: !extend ${page} + widgets: + - button: + <<: !include {file: tile.yaml, vars: {id: "${id}", name: "${name}", icon: "${icon}"}} + # not checkable: the checked state comes only from Home Assistant + on_short_click: + - homeassistant.action: + action: light.toggle + data: + entity_id: ${entity} + on_long_press: + - script.execute: + id: open_light + entity: ${entity} + name: "${name}" + dim: ${dim} + kmin: ${kmin} + hs: ${hs} + is_on: !lambda return id(${id}_state).state == "on"; + bri: !lambda return id(${id}_bri).state; + ct: !lambda return id(${id}_ct).state; + hue: !lambda return id(${id}_hs).state; + +sensor: + - platform: homeassistant + id: ${id}_bri + entity_id: ${entity} + attribute: brightness + internal: true + on_value: + - lambda: 'if (id(cur_light) == "${entity}") lv_slider_set_value(id(detail_bri), brightness_pct(x), LV_ANIM_OFF);' + - platform: homeassistant + id: ${id}_ct + entity_id: ${entity} + attribute: color_temp_kelvin + internal: true + on_value: + - lambda: 'if (id(cur_light) == "${entity}") lv_slider_set_value(id(detail_ct), x, LV_ANIM_OFF);' + +text_sensor: + # text, not binary: a binary sensor drops "unavailable" + - platform: homeassistant + id: ${id}_state + entity_id: ${entity} + internal: true + on_value: + - lambda: |- + lv_obj_set_state(id(${id}), LV_STATE_CHECKED, x == "on"); + lv_obj_set_state(id(${id}), LV_STATE_DISABLED, ha_unavailable(x)); + if (id(cur_light) == "${entity}") lv_obj_set_state(id(detail_power), LV_STATE_CHECKED, x == "on"); + - platform: homeassistant + id: ${id}_hs + entity_id: ${entity} + attribute: hs_color + internal: true + on_value: + - lambda: 'if (id(cur_light) == "${entity}") lv_slider_set_value(id(detail_hue), parse_hue(x), LV_ANIM_OFF);' diff --git a/common/nspanel_terminal/nav_tile.yaml b/common/nspanel_terminal/nav_tile.yaml new file mode 100644 index 0000000..7512ef7 --- /dev/null +++ b/common/nspanel_terminal/nav_tile.yaml @@ -0,0 +1,19 @@ +# Package: tile on a grid page that opens another page, a big icon only (e.g. the robot for automations) +# vars: page, to (page id), icon (MDI glyph, must be in icon_l) +lvgl: + pages: + - id: !extend ${page} + widgets: + - button: + width: 130 + height: 112 + styles: tile_style + pressed: + bg_color: 0x48484A + on_click: + - lvgl.page.show: ${to} + widgets: + - label: + text: "${icon}" + text_font: icon_l + align: CENTER diff --git a/common/nspanel_terminal/page_arrow.yaml b/common/nspanel_terminal/page_arrow.yaml new file mode 100644 index 0000000..3921b89 --- /dev/null +++ b/common/nspanel_terminal/page_arrow.yaml @@ -0,0 +1,21 @@ +# Page switch arrow in a top corner; floats over the page's flex layout +# vars: icon, align, x, to (page id), hidden +obj: + floating: true + hidden: ${hidden} + align: ${align} + x: ${x} + y: -16 + width: 72 + height: 52 + bg_opa: TRANSP + border_width: 0 + pad_all: 0 + on_click: + - lvgl.page.show: ${to} + widgets: + - label: + text: "${icon}" + text_font: icon_s + text_color: 0xB4B4BA + align: CENTER diff --git a/common/nspanel_terminal/sleep_dim.yaml b/common/nspanel_terminal/sleep_dim.yaml new file mode 100644 index 0000000..a2db4bc --- /dev/null +++ b/common/nspanel_terminal/sleep_dim.yaml @@ -0,0 +1,50 @@ +--- +# nspanel-terminal version of common/nspanel_sleep_dim.yaml: the idle (dimmed) brightness drops to 0 at night +# (sun below -6°), unless the room light is on. Uses the dimmed global, the panel display and ${dim_brightness}. +# packages: +# sleep_dim: !include +# file: common/nspanel_terminal/sleep_dim.yaml +# vars: +# sleep_override_entity: light.bedroom_lights +globals: + # brightness the on_idle dim goes to + - id: idle_brightness + type: int + initial_value: ${dim_brightness} + +script: + - id: apply_sleep_dim + then: + - lambda: |- + bool day = id(sun_id).is_above_horizon(-6); + id(idle_brightness) = id(sleep_override).state == "on" || day ? ${dim_brightness} : 0; + if (id(dimmed)) + id(panel).request_brightness(id(idle_brightness)); + +time: + - id: !extend ha_time + on_time_sync: + - script.execute: apply_sleep_dim + +text_sensor: + # sleepOverride; text, not binary: a binary sensor drops "unavailable" + - platform: homeassistant + id: sleep_override + entity_id: ${sleep_override_entity} + internal: true + on_value: + - script.execute: apply_sleep_dim + +sun: + id: sun_id + time_id: ha_time + latitude: 48.15° + longitude: 17.11° + on_sunrise: + - elevation: -6° + then: + - script.execute: apply_sleep_dim + on_sunset: + - elevation: -6° + then: + - script.execute: apply_sleep_dim diff --git a/common/nspanel_terminal/spacer_tile.yaml b/common/nspanel_terminal/spacer_tile.yaml new file mode 100644 index 0000000..8034024 --- /dev/null +++ b/common/nspanel_terminal/spacer_tile.yaml @@ -0,0 +1,12 @@ +# Package: empty slot on a grid page (e.g. to start the next row) +# vars: page +lvgl: + pages: + - id: !extend ${page} + widgets: + - obj: + clickable: false + width: 130 + height: 112 + bg_opa: TRANSP + border_width: 0 diff --git a/common/nspanel_terminal/switch_tile.yaml b/common/nspanel_terminal/switch_tile.yaml new file mode 100644 index 0000000..b8f10f2 --- /dev/null +++ b/common/nspanel_terminal/switch_tile.yaml @@ -0,0 +1,25 @@ +# Package: on/off Home Assistant entity (switch, automation, ...) as a tile on a grid page, with its state. +# Tiles fill the page in package order. +# vars: page, id, name, entity, icon (MDI glyph, must be in icon_s), domain (tap calls .toggle) +lvgl: + pages: + - id: !extend ${page} + widgets: + - button: + <<: !include {file: tile.yaml, vars: {id: "${id}", name: "${name}", icon: "${icon}"}} + on_click: + - homeassistant.action: + action: ${domain}.toggle + data: + entity_id: ${entity} + +text_sensor: + # text, not binary: a binary sensor drops "unavailable" + - platform: homeassistant + id: ${id}_state + entity_id: ${entity} + internal: true + on_value: + - lambda: |- + lv_obj_set_state(id(${id}), LV_STATE_CHECKED, x == "on"); + lv_obj_set_state(id(${id}), LV_STATE_DISABLED, ha_unavailable(x)); diff --git a/common/nspanel_terminal/thermostat.h b/common/nspanel_terminal/thermostat.h new file mode 100644 index 0000000..e3bc2f5 --- /dev/null +++ b/common/nspanel_terminal/thermostat.h @@ -0,0 +1,25 @@ +#pragma once +#include +#include + +// HA list attribute as sent to ESPHome, "['none', 'away']" or '["none", "away"]' -> items +inline std::vector parse_list(const std::string &s) { + std::vector out; + for (size_t p = 0; (p = s.find_first_of("'\"", p)) != std::string::npos;) { + size_t end = s.find(s[p], p + 1); + if (end == std::string::npos) break; + out.push_back(s.substr(p + 1, end - p - 1)); + p = end + 1; + } + return out; +} + +// Display name for a climate preset; unknown presets are shown as they come +inline std::string preset_name(const std::string &p) { + static const char *const NAMES[][2] = {{"none", "Žiadny"}, {"home", "Doma"}, {"away", "Preč"}, + {"eco", "Eco"}, {"comfort", "Komfort"}, {"sleep", "Spánok"}, + {"activity", "Aktivita"}, {"boost", "Boost"}}; + for (auto &n : NAMES) + if (p == n[0]) return n[1]; + return p; +} diff --git a/common/nspanel_terminal/thermostat.yaml b/common/nspanel_terminal/thermostat.yaml new file mode 100644 index 0000000..92e1465 --- /dev/null +++ b/common/nspanel_terminal/thermostat.yaml @@ -0,0 +1,94 @@ +# Home Assistant state and target sending for the thermostat page (page_5). +# Package vars: entity (climate entity with heat/off and the Better Thermostat presets), boiler (switch enabling heating) +sensor: + - platform: homeassistant + id: thermo_target + entity_id: ${entity} + attribute: temperature + internal: true + on_value: + - lambda: |- + if (std::isnan(x)) return; + lv_arc_set_value(id(thermo_arc), std::lround(x * 2)); + lv_label_set_text_fmt(id(thermo_target_label), "%.1f", x); + - platform: homeassistant + id: thermo_current + entity_id: ${entity} + attribute: current_temperature + internal: true + on_value: + - lambda: 'lv_label_set_text_fmt(id(thermo_current_label), "teraz %.1f°C", x);' + +text_sensor: + # text, not binary: a binary sensor drops "unavailable" + - platform: homeassistant + id: heating_enabled + entity_id: ${boiler} + internal: true + on_value: + - lambda: |- + lv_obj_set_state(id(heating_enabled_button), LV_STATE_CHECKED, x == "on"); + lv_obj_set_state(id(heating_enabled_button), LV_STATE_DISABLED, ha_unavailable(x)); + - platform: homeassistant + id: thermo_mode + entity_id: ${entity} + internal: true + on_value: + - lambda: |- + lv_obj_set_state(id(thermo_power), LV_STATE_CHECKED, x == "heat"); + // thermostat unavailable: grey out its controls + for (lv_obj_t *o : {(lv_obj_t *) id(thermo_power), (lv_obj_t *) id(thermo_arc), id(thermo_minus), id(thermo_plus), + id(thermo_preset_dropdown)->obj}) + lv_obj_set_state(o, LV_STATE_DISABLED, ha_unavailable(x)); + - script.execute: thermo_update_action + - platform: homeassistant + id: thermo_action + entity_id: ${entity} + attribute: hvac_action + internal: true + on_value: + - script.execute: thermo_update_action + - platform: homeassistant + id: thermo_presets + entity_id: ${entity} + attribute: preset_modes + internal: true + on_value: + - lambda: |- + id(preset_list) = parse_list(x); + std::string options; + for (auto &p : id(preset_list)) options += (options.empty() ? "" : "\n") + preset_name(p); + lv_dropdown_set_options(id(thermo_preset_dropdown)->obj, options.c_str()); + - script.execute: thermo_select_preset + - platform: homeassistant + id: thermo_preset + entity_id: ${entity} + attribute: preset_mode + internal: true + on_value: + - script.execute: thermo_select_preset + +script: + # Arc and -/+ change the target locally; send once the user stops for a moment + - id: thermo_send_target + mode: restart + then: + - delay: 800ms + - homeassistant.action: + action: climate.set_temperature + data: + entity_id: ${entity} + temperature: !lambda return lv_arc_get_value(id(thermo_arc)) / 2.0f; + - id: thermo_update_action + then: + - lambda: |- + bool off = id(thermo_mode).state == "off"; + bool heating = id(thermo_action).state == "heating"; + lv_label_set_text(id(thermo_action_label), off ? "vypnuté" : heating ? "kúri" : "nekúri"); + lv_obj_set_style_arc_color(id(thermo_arc), lv_color_hex(heating ? 0xF5B342 : 0x8E8E93), LV_PART_INDICATOR); + - id: thermo_select_preset + then: + - lambda: |- + auto &list = id(preset_list); + auto it = std::find(list.begin(), list.end(), id(thermo_preset).state); + if (it != list.end()) lv_dropdown_set_selected(id(thermo_preset_dropdown)->obj, it - list.begin()); diff --git a/common/nspanel_terminal/tile.yaml b/common/nspanel_terminal/tile.yaml new file mode 100644 index 0000000..cea7d50 --- /dev/null +++ b/common/nspanel_terminal/tile.yaml @@ -0,0 +1,25 @@ +# Look of a 2x3 grid tile (button body): icon top left, name bottom left; merge it into a button with <<: +# checked = on (orange), disabled = entity unavailable (grey), pressed = touch feedback +# vars: id, name, icon (MDI glyph, must be in icon_s) +id: ${id} +width: 130 +height: 112 +styles: tile_style +pressed: + bg_color: 0x48484A +checked: + bg_color: 0xF5B342 + text_color: 0x000000 +disabled: + bg_color: 0x161618 + text_color: 0x48484A +widgets: + - label: + text: "${icon}" + text_font: icon_s + align: TOP_LEFT + - label: + text: "${name}" + align: BOTTOM_LEFT + long_mode: WRAP + width: 100% diff --git a/common/nspanel_terminal/weather.h b/common/nspanel_terminal/weather.h new file mode 100644 index 0000000..6cbd1e6 --- /dev/null +++ b/common/nspanel_terminal/weather.h @@ -0,0 +1,57 @@ +#pragma once +#include +#include +#include + +// Home Assistant weather condition -> MDI icon (glyphs listed in the font: config) +inline const char *weather_icon(const std::string &c) { + static const char *const MAP[][2] = { + {"clear-night", "\U000F0594"}, {"sunny", "\U000F0599"}, {"partlycloudy", "\U000F0595"}, + {"cloudy", "\U000F0590"}, {"fog", "\U000F0591"}, {"rainy", "\U000F0597"}, + {"pouring", "\U000F0596"}, {"snowy", "\U000F0598"}, {"snowy-rainy", "\U000F067F"}, + {"hail", "\U000F0592"}, {"lightning", "\U000F0593"}, {"lightning-rainy", "\U000F067E"}, + {"windy", "\U000F059D"}, {"windy-variant", "\U000F059E"}, {"exceptional", "\U000F05D6"}}; + for (auto &m : MAP) + if (c == m[0]) return m[1]; + return ""; +} + +// One day of the HA `forecast` attribute as sent to ESPHome (Python repr or JSON of a list of dicts). +struct ForecastDay { + std::string condition; + float high, low; +}; + +// Value after `key` in s, starting at pos; works for 'key': and "key": +static inline const char *forecast_value_(const std::string &s, size_t pos, const char *key, size_t end) { + size_t k = s.find(key, pos); + if (k == std::string::npos || k >= end) return nullptr; + k = s.find(':', k + std::strlen(key)); + if (k == std::string::npos || k >= end) return nullptr; + while (++k < end && (s[k] == ' ' || s[k] == '\'' || s[k] == '"')) { + } + return s.c_str() + k; +} + +// Fills up to n days starting at index `first`; returns how many were parsed. +inline int parse_forecast(const std::string &s, int first, ForecastDay *out, int n) { + int index = 0, got = 0; + size_t pos = 0; + while (got < n && (pos = s.find('{', pos)) != std::string::npos) { + size_t end = s.find('}', pos); + if (end == std::string::npos) break; + if (index++ >= first) { + const char *cond = forecast_value_(s, pos, "condition", end); + const char *high = forecast_value_(s, pos, "temperature", end); + const char *low = forecast_value_(s, pos, "templow", end); + if (cond && high && low) { + out[got].condition.assign(cond, std::strcspn(cond, "'\",")); + out[got].high = std::strtof(high, nullptr); + out[got].low = std::strtof(low, nullptr); + ++got; + } + } + pos = end; + } + return got; +} diff --git a/mcu-nspanel-dev.yaml b/mcu-nspanel-dev.yaml index fed6db1..1e9be08 100644 --- a/mcu-nspanel-dev.yaml +++ b/mcu-nspanel-dev.yaml @@ -17,33 +17,25 @@ substitutions: device: nspanel-dev name: NSPanel DEV area: DEV - comment: NSPanel - panel_recv_topic: "tele/${device}/RESULT" - panel_send_topic: "cmnd/${device}/CustomSend" - tft_url: !secret tft_url + comment: NSPanel (nspanel-terminal) + brightness: "80" + # backlight after 30 s idle, tune to taste + dim_brightness: "20" esphome: name: mcu-${device} friendly_name: ${name} area: ${area} comment: ${comment} + includes: + - common/nspanel_terminal/weather.h + - common/nspanel_terminal/ha.h + - common/nspanel_terminal/light.h + - common/nspanel_terminal/thermostat.h on_boot: - then: - - switch.turn_off: screen_power - - delay: 1s - - switch.turn_on: screen_power - - delay: 2s - - lambda: 'id(nspanel_id).set_display_dim(5, 80);' - - # priority: -100 - # then: - # - wait_until: - # api.connected - # - delay: 10s - # - homeassistant.service: - # service: automation.trigger - # data: - # entity_id: automation.nspanel_send_weather_to_nspanel + - priority: -100 + then: + - lvgl.page.show: page_7 esp32: variant: esp32 @@ -54,145 +46,138 @@ esp32: flash_chip: generic minimum_chip_revision: 3.0 sram1_as_iram: true + sdkconfig_options: + # NSPanel PSRAM on non-default pins + CONFIG_D0WD_PSRAM_CLK_IO: "5" + CONFIG_D0WD_PSRAM_CS_IO: "18" + +psram: + mode: quad + speed: 40MHz + ignore_not_found: false external_components: - # - source: - # type: git - # url: https://github.com/sairon/esphome-nspanel-lovelace-ui - # ref: dev - # refresh: 0s - # components: [nspanel_lovelace] + # https://github.com/ptaru/nspanel-terminal, local branch esphome-dev - source: - type: git - # url: https://github.com/olicooper/esphome-nspanel-lovelace-native - # ref: dev - url: https://github.com/randybb/esphome-nspanel-lovelace-native - ref: devices - refresh: 0s - components: [nspanel_lovelace] - # - source: components + type: local + path: /home/randy/Projects/repos/nspanel-terminal/components + components: [nspanel_terminal] packages: common: !include common/common.yaml ipv6_only: !include common/ipv6_only.yaml - nspanel_popup: !include common/nspanel_popup.yaml - # common: !include common/common_dev.yaml + sleep_dim: !include + file: common/nspanel_terminal/sleep_dim.yaml + vars: + sleep_override_entity: light.mcu_nspanel_office_r_light + # Grid page tiles: each package adds its tile to the page and fills it in this order + # page_1 Kuchyňa / Obývačka + l_kitchen: !include {file: common/nspanel_terminal/light_tile.yaml, vars: {page: page_1, id: l_kitchen, name: "Kuchyňa", entity: light.kitchen, icon: "\U000F0769", dim: true, kmin: 2700, hs: false}} + l_dining: !include {file: common/nspanel_terminal/light_tile.yaml, vars: {page: page_1, id: l_dining, name: "Stôl", entity: light.dining_table, icon: "\U000F1793", dim: true, kmin: 2700, hs: false}} + l_living: !include {file: common/nspanel_terminal/light_tile.yaml, vars: {page: page_1, id: l_living, name: "Gauč", entity: light.living_room, icon: "\U000F04B9", dim: true, kmin: 2700, hs: false}} + l_tv: !include {file: common/nspanel_terminal/light_tile.yaml, vars: {page: page_1, id: l_tv, name: "TV", entity: light.mcu_tv_light_light, icon: "\U000F0502", dim: false, kmin: 0, hs: false}} + l_dining_amb: !include {file: common/nspanel_terminal/light_tile.yaml, vars: {page: page_1, id: l_dining_amb, name: "(Stôl)", entity: light.dining_table_ambilight, icon: "\U000F1051", dim: true, kmin: 1700, hs: true}} + l_living_amb: !include {file: common/nspanel_terminal/light_tile.yaml, vars: {page: page_1, id: l_living_amb, name: "(Gauč)", entity: light.living_room_ambilight, icon: "\U000F1051", dim: true, kmin: 1700, hs: true}} + # page_2 Romanko + l_office: !include {file: common/nspanel_terminal/light_tile.yaml, vars: {page: page_2, id: l_office, name: "Svetlo", entity: light.mcu_nspanel_office_r_light, icon: "\U000F0769", dim: false, kmin: 0, hs: false}} + l_strip: !include {file: common/nspanel_terminal/light_tile.yaml, vars: {page: page_2, id: l_strip, name: "LED pásik", entity: light.office_r_desk_strip, icon: "\U000F1051", dim: true, kmin: 1700, hs: true}} + office_spacer: !include {file: common/nspanel_terminal/spacer_tile.yaml, vars: {page: page_2}} + l_monitor: !include {file: common/nspanel_terminal/light_tile.yaml, vars: {page: page_2, id: l_monitor, name: "Monitor", entity: light.office_r_display_lamp, icon: "\U000F0379", dim: true, kmin: 2700, hs: false}} + l_monitor_amb: !include {file: common/nspanel_terminal/light_tile.yaml, vars: {page: page_2, id: l_monitor_amb, name: "(Monitor)", entity: light.office_r_display_lamp_ambilight, icon: "\U000F1051", dim: true, kmin: 1700, hs: true}} + # page_3 Von (card_outside of the patio panel) + l_patio: !include {file: common/nspanel_terminal/light_tile.yaml, vars: {page: page_3, id: l_patio, name: "Terasa", entity: light.patio_lights, icon: "\U000F1253", dim: true, kmin: 2000, hs: false}} + s_patio_socket: !include {file: common/nspanel_terminal/switch_tile.yaml, vars: {page: page_3, id: s_patio_socket, name: "Terasa", entity: switch.mcu_patio_relay, icon: "\U000F1108", domain: switch}} + s_patio_back: !include {file: common/nspanel_terminal/switch_tile.yaml, vars: {page: page_3, id: s_patio_back, name: "Vzadu", entity: switch.mcu_nspanel_patio_outside_light_back, icon: "\U000F1987", domain: switch}} + s_shed_light: !include {file: common/nspanel_terminal/switch_tile.yaml, vars: {page: page_3, id: s_shed_light, name: "Z. domček", entity: switch.mcu_shed_light, icon: "\U000F091D", domain: switch}} + s_shed_socket: !include {file: common/nspanel_terminal/switch_tile.yaml, vars: {page: page_3, id: s_shed_socket, name: "Z. domček", entity: switch.mcu_shed_socket, icon: "\U000F1108", domain: switch}} + s_garden: !include {file: common/nspanel_terminal/switch_tile.yaml, vars: {page: page_3, id: s_garden, name: "Záhrada", entity: switch.mcu_shed_garden_light, icon: "\U000F1987", domain: switch}} + # page_4 Závlaha, robot -> page_irrigation_auto + v_a1: !include {file: common/nspanel_terminal/switch_tile.yaml, vars: {page: page_4, id: v_a1, name: "A1", entity: switch.mcu_well_irrigation_valve_a1, icon: "\U000F1066", domain: switch}} + v_a2: !include {file: common/nspanel_terminal/switch_tile.yaml, vars: {page: page_4, id: v_a2, name: "A2", entity: switch.mcu_well_irrigation_valve_a2, icon: "\U000F1066", domain: switch}} + v_a3: !include {file: common/nspanel_terminal/switch_tile.yaml, vars: {page: page_4, id: v_a3, name: "A3", entity: switch.mcu_well_irrigation_valve_a3, icon: "\U000F1066", domain: switch}} + v_a4: !include {file: common/nspanel_terminal/switch_tile.yaml, vars: {page: page_4, id: v_a4, name: "A4", entity: switch.mcu_well_irrigation_valve_a4, icon: "\U000F1066", domain: switch}} + v_a5: !include {file: common/nspanel_terminal/switch_tile.yaml, vars: {page: page_4, id: v_a5, name: "A5", entity: switch.mcu_well_irrigation_valve_a5, icon: "\U000F1066", domain: switch}} + irrigation_auto: !include {file: common/nspanel_terminal/nav_tile.yaml, vars: {page: page_4, to: page_irrigation_auto, icon: "\U000F06A9"}} + ir_morning: !include {file: common/nspanel_terminal/switch_tile.yaml, vars: {page: page_irrigation_auto, id: ir_morning, name: "Ráno", entity: automation.irrigation_morning, icon: "\U000F059C", domain: automation}} + ir_patio: !include {file: common/nspanel_terminal/switch_tile.yaml, vars: {page: page_irrigation_auto, id: ir_patio, name: "Terasa", entity: automation.irrigation_patio, icon: "\U000F024A", domain: automation}} + ir_grass: !include {file: common/nspanel_terminal/switch_tile.yaml, vars: {page: page_irrigation_auto, id: ir_grass, name: "Rast trávy", entity: automation.irrigation_grow_grass, icon: "\U000F1510", domain: automation}} + # page_6 Brána, robot -> page_gate_auto + gate_open: !include {file: common/nspanel_terminal/action_tile.yaml, vars: {page: page_6, id: gate_open, name: "Otvoriť", icon: "\U000F116A", action: button.press, entity: button.mcu_gate_open}} + gate_close: !include {file: common/nspanel_terminal/action_tile.yaml, vars: {page: page_6, id: gate_close, name: "Zatvoriť", icon: "\U000F0299", action: button.press, entity: button.mcu_gate_close}} + gate_spacer: !include {file: common/nspanel_terminal/spacer_tile.yaml, vars: {page: page_6}} + gate: !include {file: common/nspanel_terminal/gate.yaml, vars: {page: page_6, state: select.mcu_gate_state}} + gate_auto: !include {file: common/nspanel_terminal/nav_tile.yaml, vars: {page: page_6, to: page_gate_auto, icon: "\U000F06A9"}} + gate_auto_open: !include {file: common/nspanel_terminal/switch_tile.yaml, vars: {page: page_gate_auto, id: gate_auto_open, name: "Auto-otváranie", entity: switch.mcu_gate_auto_open, icon: "\U000F1169", domain: switch}} + gate_auto_close: !include {file: common/nspanel_terminal/switch_tile.yaml, vars: {page: page_gate_auto, id: gate_auto_close, name: "Auto-zatváranie", entity: switch.mcu_gate_auto_close, icon: "\U000F17F7", domain: switch}} + # page_5 Kúrenie + thermostat: !include {file: common/nspanel_terminal/thermostat.yaml, vars: {entity: climate.bt_trv_office_r, boiler: switch.heating_enabled}} -# web_server: -# port: 80 -# local: true +wifi: + power_save_mode: none + +# Flashing shows on the status page. The OTA blocks the main loop, so each step renders the screen itself +ota: + - id: !extend ota_esphome + on_begin: + - lvgl.page.show: page_7 + - lambda: |- + lv_obj_set_hidden(id(status_ota), false); + lv_obj_set_style_text_color(id(status_ota), lv_color_hex(0xFFB300), LV_PART_MAIN); + lv_label_set_text(id(status_ota), "Flashovanie: začína..."); + lv_refr_now(nullptr); + on_progress: + - lambda: |- + lv_label_set_text_fmt(id(status_ota), "Flashovanie: %.0f %%", x); + lv_refr_now(nullptr); + on_end: + - lambda: |- + lv_obj_set_style_text_color(id(status_ota), lv_color_hex(0x4DD966), LV_PART_MAIN); + lv_label_set_text(id(status_ota), "Flashovanie: hotovo, reštartujem"); + lv_refr_now(nullptr); + on_error: + - lambda: |- + lv_obj_set_style_text_color(id(status_ota), lv_color_hex(0xFF453A), LV_PART_MAIN); + lv_label_set_text_fmt(id(status_ota), "Flashovanie: chyba %u", x); + lv_refr_now(nullptr); api: - homeassistant_services: true - homeassistant_states: true + # status page until Home Assistant connects (log viewers don't subscribe to states) + on_client_connected: + - delay: 2s + - if: + condition: + api.connected: + state_subscription_only: true + then: + - lvgl.page.show: page_0 + on_client_disconnected: + - if: + condition: + not: + api.connected: + state_subscription_only: true + then: + - lvgl.page.show: page_7 actions: - # https://github.com/granadaxronos/120-SONG_NOKIA_RTTTL_RINGTONE_PLAYER_FOR_ARDUINO_UNO/blob/master/RTTTL_PLAYER/songs.h - - action: play_rtttl - variables: - song: string - then: - - rtttl.play: - rtttl: !lambda 'return song;' - + # same signatures as on the lovelace panels, so the HA automations keep working - action: notify variables: heading: string message: string song: string then: - - lambda: 'id(nspanel_id).notify_on_screensaver(heading, message, 10000);' - - rtttl.play: - rtttl: !lambda 'return song;' - # - delay: 10s - # - lambda: 'id(nspanel_id).send_custom_command("notify~~");' - - # DISABLED until https://github.com/olicooper/esphome-nspanel-lovelace-native/issues/20 is fixed - # - service: update_tft - # then: - # - lambda: |- - # id(nspanel_id).upload_tft("${tft_url}"); - - # - service: upload_tft - # variables: - # url: string - # then: - # - lambda: |- - # id(nspanel_id).upload_tft(url); - - # # Service to send a command directly to the display. Useful for testing - # - service: send_command - # variables: - # cmd: string - # then: - # - lambda: "id(nspanel_id).send_custom_command(cmd.c_str());" - - # # Service to pusblish to mqtt used for refreshin the panel - # - service: publish_to_recv_topic - # variables: - # cmd: string - # then: - # - mqtt.publish: - # topic: $panel_recv_topic - # payload: !lambda "return cmd;" - - # # Service to send a command wake the screen - # - service: wake - # then: - # - lambda: 'id(nspanel_id).send_custom_command("wake");' - - # # Service to send a command to show screensaver (some of the values are hardcoded) - # - service: show_screensaver - # then: - # - mqtt.publish: - # topic: $panel_recv_topic - # payload: '{"CustomRecv":"event,sleepReached,cardGrid"}' - - # # Service to navigate to screen - # - service: navigate_to_page - # variables: - # page: string - # then: - # - mqtt.publish_json: - # topic: $panel_recv_topic - # payload: |- - # root["CustomRecv"] = "event,buttonPress2,navigate." + page + ",button"; - - # # Service to send a command disable screensaver - # - service: disable_screensaver - # then: - # - lambda: 'id(nspanel_id).send_custom_command("timeout~0");' - - # # Service to send a command enabled screensaver - # - service: enable_screensaver - # then: - # - lambda: 'id(nspanel_id).send_custom_command("timeout~20");' - - # # Service to send a command wake the screen - # - service: dim_0_to_100 - # variables: - # intensity: string - # then: - # - lambda: 'id(nspanel_id).send_custom_command("dimmode~"+intensity+"~100");' - - # # Service to send a command To show the screen of a specific like - # - service: show_entity - # variables: - # entity: string - # title: string - # then: - # - lambda: 'id(nspanel_id).send_custom_command("pageType~popupLight~" + title + "~" + entity);' - - # # Service to send a command To show the screen of a specific like - # - service: notify_on_screensaver - # variables: - # line1: string - # line2: string - # then: - # - lambda: 'id(nspanel_id).send_custom_command("notify~" + line1 + "~" + line2);' - # # - rtttl.play: "short:d=4,o=5,b=100:16e6" - - # Service to send a command To show the screen of a specific like - # interaction of the buttons are on implemented yet + - script.execute: + id: notify_show + heading: !lambda return heading; + message: !lambda return message; + timeout_ms: 10000 + - if: + condition: + lambda: return !song.empty(); + then: + - rtttl.play: + rtttl: !lambda 'return song;' + # buttons and icon were never implemented on the lovelace panels either - action: notify_fullscreen variables: title: string @@ -202,267 +187,1104 @@ api: timeout: int icon: string then: - - lambda: 'id(nspanel_id).notify_on_screensaver(title, description, timeout);' - # show notification screen - # - lambda: 'id(nspanel_id).send_custom_command("pageType~popupNotify");' - # set values on notification screen - # color defined as number created in binary and converted to decimal (rrrrggggbbbbaaaa) - # - lambda: 'id(nspanel_id).send_custom_command("entityUpdateDetail~id~"+ title + "~65535~" + button1 +"~3840~" + button2 + "~61440~" + description + "~65535~" + timeout + "~3~" + icon + "~65535~");' + - script.execute: + id: notify_show + heading: !lambda return title; + message: !lambda return description; + timeout_ms: !lambda return timeout; - rtttl.play: "scale_up:d=32,o=5,b=100:c,c#,d#,e,f#,g#,a#,b" + - action: show_info + then: + - script.execute: info_popup + # https://github.com/granadaxronos/120-SONG_NOKIA_RTTTL_RINGTONE_PLAYER_FOR_ARDUINO_UNO/blob/master/RTTTL_PLAYER/songs.h + - action: play_rtttl + variables: + song: string + then: + - rtttl.play: + rtttl: !lambda 'return song;' + + - action: set_brightness + variables: + percent: int + then: + - lambda: 'id(panel).request_brightness(percent);' + # url empty = tft_url from secrets (terminal), rollback: http://ha.local/local/tft/lui.tft + - action: upload_tft + variables: + url: string + then: + - lambda: |- + if (!url.empty()) id(panel).set_tft_url(url); + id(panel).request_tft_upload(); uart: id: display_uart tx_pin: 16 rx_pin: 17 baud_rate: 115200 + rx_buffer_size: 4096 -nspanel_lovelace: - id: nspanel_id - sleep_timeout: 10 - experimental_vertical_ui: true - locale: - language: sk - temperature_unit: celcius - screensaver: - time_id: ha_time - time_format: '%H:%M' - date_format: '%A, %d. %b. %Y' - weather: - entity_id: sensor.weather_forecast_daily - # entity_id: weather.openweathermap - # forecast_method: service - icon_color: [255, 255, 255] - entities: - - entity_id: sensor.zigbee_office_r_temperature - icon: - value: home-thermometer-outline - color: [255, 255, 255] - precision: 1 - # type: screensaver2 - ## Custom entities, filled into the layout slots in order after the weather items. - ## Use 'entity_id: delete' to leave a slot empty. - ## screensaver: weather main + 4 forecast items, 1 extra entity switches to the alternative layout (max 6 items) - ## screensaver2: weather main only, then 3 left + 6 bottom + 5 indicator icons (max 15 items) - # entities: - # - entity_id: sensor.outside_humidity - # name: Humidity - # icon: water-percent - # - entity_id: delete - # - entity_id: binary_sensor.front_door +display: + - platform: nspanel_terminal + id: panel + uart_id: display_uart + width: 454 + height: 320 + update_interval: never + auto_clear_enabled: false + tft_url: !secret tft_url_terminal + brightness: ${brightness} - # type: screensaver2 - # statusIcon1: - # entity: switch.office_r_light - # icon: - # "on": mdi:sofa - # "off": mdi:sofa - # color: - # "on": [255, 255, 255] - # "off": [255, 255, 255] - # statusIcon2: - # entity: light.office_r_desk_strip - # icon: - # "on": mdi:table-furniture - # "off": mdi:table-furniture - # color: - # "on": [255, 255, 255] - # "off": [255, 255, 255] - # entities: - # - entity: sensor.weather_forecast_daily - # color: [255, 255, 255] - # - entity: delete - # - entity: delete - # - entity: delete - # - entity: sensor.weather_forecast_daily - # color: [255, 255, 255] - # type: 0 - # - entity: sensor.weather_forecast_daily - # color: [255, 255, 255] - # type: 1 - # - entity: sensor.weather_forecast_daily - # color: [255, 255, 255] - # type: 2 - # - entity: sensor.weather_forecast_daily - # color: [255, 255, 255] - # type: 3 - # - entity: delete - # - entity: sensor.zigbee_office_r_temperature - # color: [255, 255, 255] - # name: "" - # icon: mdi:home-thermometer - # - entity: switch.heating_relay_3 - # icon: - # "on": mdi:radiator - # "off": "text:" - # color: - # "on": [255, 255, 255] - # - entity: binary_sensor.heating_fireplace_fire - # icon: - # "on": mdi:fireplace - # "off": "text:" - # color: - # "on": [255, 255, 255] - # - entity: delete - # - entity: delete - # - entity: delete - cards: - - type: cardGrid - title: Kuchyňa / Obývačka - entities: - - name: Kuchyňa - entity_id: light.kitchen - icon: ceiling-light - - name: Stôl - entity_id: light.dining_table - icon: ceiling-light - - name: Gauč - entity_id: light.living_room - icon: ceiling-light - - name: TV - entity_id: light.mcu_tv_light_light - icon: led-strip-variant - - name: (Stôl) - entity_id: light.dining_table_ambilight - icon: ceiling-light-multiple-outline - - name: (Gauč) - entity_id: light.living_room_ambilight - icon: ceiling-light-multiple-outline - - type: cardGrid - title: Romanko - entities: - - name: Svetlo - entity_id: light.mcu_nspanel_office_r_light - icon: wall-sconce-flat - - name: LED pásik - entity_id: light.office_r_desk_strip - icon: led-strip-variant - - entity_id: delete - - name: Monitor - entity_id: light.office_r_display_lamp - icon: monitor-star - - name: (Monitor) - entity_id: light.office_r_display_lamp_ambilight - icon: monitor-star - - type: cardGrid - title: Von - entities: - - name: Terasa - entity_id: light.patio_lights - icon: lightbulb-group - - name: Terasa - entity_id: switch.mcu_patio_relay - icon: power-socket-fr - - name: Vzadu - entity_id: switch.mcu_nspanel_patio_outside_light_back - icon: light-flood-down - - name: Z. domček - entity_id: switch.mcu_shed_light - icon: wall-sconce-flat - # state_template: '{{ is_state("binary_sensor.shed_status", "off") }}' - - name: Z. domček - entity_id: switch.mcu_shed_socket - icon: power-socket-fr - # state_template: '{{ is_state("binary_sensor.shed_status", "off") }}' - - name: Záhrada - entity_id: switch.mcu_shed_garden_light - icon: light-flood-down - # state_template: '{{ is_state("binary_sensor.shed_status", "off") }}' - - type: cardGrid - title: Brána - entities: - - name: Otvoriť - entity_id: button.mcu_gate_open - icon: gate-open - - name: Zatvoriť - entity_id: button.mcu_gate_close - icon: gate - - name: Automatizácia - entity_id: navigate.card_gate_automation - - type: cardGrid - title: Závlaha - entities: - - name: A1 - entity_id: switch.mcu_well_irrigation_valve_a1 - icon: valve - - name: A2 - entity_id: switch.mcu_well_irrigation_valve_a2 - icon: valve - - name: A3 - entity_id: switch.mcu_well_irrigation_valve_a3 - icon: valve - - name: A4 - entity_id: switch.mcu_well_irrigation_valve_a4 - icon: valve - - name: A5 - entity_id: switch.mcu_well_irrigation_valve_a5 - icon: valve - - name: Automatizácia - entity_id: navigate.card_irrigation_automation - - type: cardThermo - title: Kúrenie - thermo_entity_id: climate.bt_trv_office_r - # - type: cardQR - # title: Guest Wifi - # qr_text: "WIFI:T:WPA;S:LAB;P:slniecko;;" - # # qrCode: "URL:https://www.johndoe.com/" - # # entities: - # # - entity_id: delete - # # - entity_id: iText.LAB - # # name: Name - # # icon: wifi - # # - entity_id: iText.slniecko - # # name: Password - # # icon: key - - type: cardEntities - title: Zwift - entities: - - name: Svetlo - entity_id: light.mcu_basement_light - icon: lightbulb-multiple - - name: LED - entity_id: light.exercise_room - icon: led-strip-variant - - name: Ventilátor - entity_id: light.mcu_dimmer_exercise_room_fan - icon: fan - - name: Automatizácia - entity_id: navigate.card_exercise_automation - - type: cardEntities - title: Automatizácia - id: card_exercise_automation - hidden: true - entities: - - name: Start - entity_id: automation.zwift_enable_fan - - name: End - entity_id: automation.zwift_disable_fan - - type: cardEntities - title: Automatizácia - id: card_gate_automation - hidden: true - entities: - - name: Auto-otváranie - entity_id: switch.gate_auto_open - - name: Auto-zatváranie - entity_id: switch.gate_auto_close - - type: cardEntities - title: Automatizácia - id: card_irrigation_automation - hidden: true - entities: - - name: Ráno - entity_id: automation.irrigation_morning - - name: Terasa - entity_id: automation.irrigation_patio - - name: Rast trávy - entity_id: automation.irrigation_grow_grass +touchscreen: + - platform: nspanel_terminal + id: panel_touch + display: panel + panel_id: panel + calibration: + x_min: 0 + x_max: 453 + y_min: 0 + y_max: 319 + on_touch: + - if: + condition: + lambda: return id(dimmed); + then: + - globals.set: + id: dimmed + value: "false" + - lambda: 'id(panel).request_brightness(${brightness});' - - type: cardEntities - title: Info - entities: - - name: Zariadenie - entity_id: button.nspanel_dev_info - icon: information-outline +globals: + - id: dimmed + type: bool + initial_value: "false" + # light shown on page_light and the index of the page to return to + - id: cur_light + type: std::string + - id: back_page + type: size_t + # preset_modes of the thermostat, in dropdown order + - id: preset_list + type: std::vector + +font: + - file: "gfonts://Inter@500" + id: font_clock + size: 112 + bpp: 4 + glyphs: "0123456789:" + - file: "gfonts://Inter@500" + id: font_big + size: 44 + bpp: 4 + glyphs: "0123456789.,-" + - file: "gfonts://Inter" + id: font_m + size: 22 + bpp: 4 + glyphsets: [GF_Latin_Core] + - file: "gfonts://Inter" + id: font_s + size: 17 + bpp: 4 + glyphsets: [GF_Latin_Core] + + - file: + type: web + url: https://github.com/Templarian/MaterialDesign-Webfont/raw/v7.4.47/fonts/materialdesignicons-webfont.ttf + id: icon_s + size: 30 + bpp: 4 + glyphs: + - "\U000F0594" + - "\U000F0599" + - "\U000F0595" + - "\U000F0590" + - "\U000F0591" + - "\U000F0597" + - "\U000F0596" + - "\U000F0598" + - "\U000F067F" + - "\U000F0592" + - "\U000F0593" + - "\U000F067E" + - "\U000F059D" + - "\U000F059E" + - "\U000F05D6" + - "\U000F0141" + - "\U000F0142" + - "\U000F0374" + - "\U000F0415" + - "\U000F0438" + - "\U000F0238" + - "\U000F0140" + - "\U000F1066" + - "\U000F059C" + - "\U000F024A" + - "\U000F1510" + - "\U000F1253" + - "\U000F1108" + - "\U000F1987" + - "\U000F091D" + - "\U000F0299" + - "\U000F116A" + - "\U000F1169" + - "\U000F17F7" + - "\U000F17F8" + - "\U000F06A9" + - "\U000F00DF" + - "\U000F05A8" + - "\U000F03D8" + - "\U000F0425" + - "\U000F0379" + - "\U000F04B9" + - "\U000F0502" + - "\U000F0769" + - "\U000F1051" + - "\U000F1793" + - file: + type: web + url: https://github.com/Templarian/MaterialDesign-Webfont/raw/v7.4.47/fonts/materialdesignicons-webfont.ttf + id: icon_l + size: 52 + bpp: 4 + glyphs: + - "\U000F0594" + - "\U000F0599" + - "\U000F0595" + - "\U000F0590" + - "\U000F0591" + - "\U000F0597" + - "\U000F0596" + - "\U000F0598" + - "\U000F067F" + - "\U000F0592" + - "\U000F0593" + - "\U000F067E" + - "\U000F059D" + - "\U000F059E" + - "\U000F05D6" + - "\U000F0299" + - "\U000F116A" + - "\U000F1169" + - "\U000F17F7" + - "\U000F17F8" + - "\U000F06A9" + +script: + # counts as activity: wakes the dimmed screen and restarts the idle timeout back to the home page + - id: wake_screen + then: + - lambda: |- + lv_display_trigger_activity(nullptr); + if (id(dimmed)) { + id(dimmed) = false; + id(panel).request_brightness(${brightness}); + } + # like the info popup of the other panels: device info is on the status page + # notification over every page (top layer); closes on tap or after the timeout + - id: notify_show + mode: restart + parameters: + heading: string + message: string + timeout_ms: int + then: + - lambda: |- + lv_label_set_text(id(notify_heading), heading.c_str()); + lv_label_set_text(id(notify_message), message.c_str()); + lv_obj_set_hidden(id(notify_popup), false); + - script.execute: wake_screen + - delay: !lambda 'return timeout_ms > 0 ? timeout_ms : 10000;' + - lvgl.widget.hide: notify_popup + - id: info_popup + then: + - lvgl.page.show: page_7 + - script.execute: wake_screen + # same as the status screens of the other LVGL devices (mcu-lvgl.yaml) + - id: update_status + then: + - lambda: |- + // ok green, waiting orange, details gray + static const uint32_t OK = 0x4DD966, WAIT = 0xFFB300; + auto set = [](lv_obj_t *label, const std::string &text, uint32_t color) { + lv_label_set_text(label, text.c_str()); + lv_obj_set_style_text_color(label, lv_color_hex(color), LV_PART_MAIN); + }; + + auto *wifi = wifi::global_wifi_component; + const bool wifi_ok = wifi->is_connected(); + // diagnostics for slow connects after a cold start: seconds to connect, AP association + static uint32_t connected_s = 0; + if (wifi_ok && !connected_s) + connected_s = std::max(1, millis() / 1000); + if (wifi_ok) { + set(id(status_wifi), str_sprintf("WiFi: pripojené za %u s (%d dBm)", connected_s, wifi->wifi_rssi()), OK); + } else { + auto bssid = wifi->wifi_bssid(); + bool associated = std::any_of(bssid.begin(), bssid.end(), [](uint8_t b) { return b != 0; }); + set(id(status_wifi), + str_sprintf("WiFi: pripájam... %s, %us", associated ? "AP ok, čakám na IP" : "bez AP", millis() / 1000), + WAIT); + } + + // IPv6 first (skip link-local), then IPv4 + std::string ips; + char buf[network::IP_ADDRESS_BUFFER_SIZE]; + for (bool v6 : {true, false}) { + for (auto &ip : wifi->get_ip_addresses()) { + if (!ip.is_set() || ip.is_ip6() != v6) + continue; + ip.str_to(buf); + if (v6 && strncmp(buf, "fe80", 4) == 0) + continue; + if (!ips.empty()) + ips += "\n"; + ips += buf; + } + } + lv_label_set_text(id(status_ips), ips.c_str()); + lv_obj_set_hidden(id(status_ips), ips.empty()); + + const bool api_ok = api::global_api_server->is_connected(true); + set(id(status_ha), api_ok ? "Home Assistant: pripojený" : "Home Assistant: čakám...", api_ok ? OK : WAIT); + + const uint32_t up = millis() / 1000; + static char build[Application::BUILD_TIME_STR_SIZE] = ""; + if (!build[0]) + App.get_build_time_string(build); + lv_label_set_text(id(status_footer), + str_sprintf("ESPHome %s · beží %ud %02u:%02u:%02u\n%s", ESPHOME_VERSION, up / 86400, + (up / 3600) % 24, (up / 60) % 60, up % 60, build).c_str()); + - id: open_light + parameters: + entity: string + name: string + dim: bool + kmin: int + hs: bool + is_on: bool + bri: float + ct: float + hue: string + then: + - lambda: |- + id(cur_light) = entity; + id(back_page) = id(lvgl_main)->get_current_page(); + lv_label_set_text(id(detail_title), name.c_str()); + lv_obj_set_state(id(detail_power), LV_STATE_CHECKED, is_on); + lv_obj_set_hidden(id(detail_bri_row), !dim); + // colour lights get hue only: brightness plus either colour temperature or hue + lv_obj_set_hidden(id(detail_ct_row), !kmin || hs); + lv_obj_set_hidden(id(detail_hue_row), !hs); + lv_slider_set_value(id(detail_bri), brightness_pct(bri), LV_ANIM_OFF); + if (kmin) { + lv_slider_set_range(id(detail_ct), kmin, 6500); + lv_slider_set_value(id(detail_ct), std::isnan(ct) ? kmin : ct, LV_ANIM_OFF); + } + lv_slider_set_value(id(detail_hue), std::max(0, parse_hue(hue)), LV_ANIM_OFF); + - lvgl.page.show: page_light + - id: update_forecast + then: + - lambda: |- + static const char *const DAYS[] = {"ne", "po", "ut", "st", "št", "pi", "so"}; + lv_obj_t *const DAY[] = {id(forecast_day_0), id(forecast_day_1), id(forecast_day_2)}; + lv_obj_t *const ICON[] = {id(forecast_icon_0), id(forecast_icon_1), id(forecast_icon_2)}; + lv_obj_t *const HIGH[] = {id(today_high), id(forecast_high_0), id(forecast_high_1), id(forecast_high_2)}; + lv_obj_t *const LOW[] = {id(today_low), id(forecast_low_0), id(forecast_low_1), id(forecast_low_2)}; + auto now = id(ha_time).now(); + ForecastDay days[4]; + // index 0 is today + int n = now.is_valid() ? parse_forecast(id(forecast).state, 0, days, 4) : 0; + for (int i = 0; i < 4; i++) { + if (i < n) { + lv_label_set_text_fmt(HIGH[i], "%.1f°C", days[i].high); + lv_label_set_text_fmt(LOW[i], "%.1f°C", days[i].low); + } else { + lv_label_set_text(HIGH[i], ""); + lv_label_set_text(LOW[i], ""); + } + if (i == 0) continue; + lv_label_set_text(DAY[i - 1], i < n ? DAYS[(now.day_of_week + i - 1) % 7] : ""); + lv_label_set_text(ICON[i - 1], i < n ? weather_icon(days[i].condition) : ""); + } + - id: update_clock + then: + - lambda: |- + static const char *const DAYS[] = {"nedeľa", "pondelok", "utorok", "streda", "štvrtok", "piatok", "sobota"}; + static const char *const MONTHS[] = {"januára", "februára", "marca", "apríla", "mája", "júna", + "júla", "augusta", "septembra", "októbra", "novembra", "decembra"}; + auto now = id(ha_time).now(); + if (!now.is_valid()) return; + lv_label_set_text(id(clock_label), now.strftime("%H:%M").c_str()); + lv_label_set_text_fmt(id(date_label), "%s, %u. %s", DAYS[now.day_of_week - 1], now.day_of_month, + MONTHS[now.month - 1]); + +time: + - id: !extend ha_time + on_time_sync: + - script.execute: update_clock + - script.execute: update_forecast + on_time: + - seconds: 0 + then: + - script.execute: update_clock + +image: + - platform: file + file: assets/images/made-for-esphome-white-on-black.svg + id: esphome_logo + resize: 300x88 + type: RGB565 + transparency: alpha_channel + +interval: + - interval: 1s + then: + - if: + condition: + lvgl.page.is_showing: page_7 + then: + - script.execute: update_status + +lvgl: + id: lvgl_main + displays: panel + # 1/8 screen draw buffer in internal RAM; a full-screen PSRAM buffer renders much slower + buffer_size: 12.5% + touchscreens: + - touchscreen_id: panel_touch + color_depth: 16 + bg_color: 0x000000 + text_color: 0xFFFFFF + text_font: font_m + gradients: + - id: ct_grad + direction: HOR + stops: + - {color: 0xFF9A3C, position: 0%} + - {color: 0xFFE4C4, position: 50%} + - {color: 0xCFDCFF, position: 100%} + - id: hue_grad + direction: HOR + stops: + - {color: 0xFF0000, position: 0%} + - {color: 0xFFFF00, position: 17%} + - {color: 0x00FF00, position: 33%} + - {color: 0x00FFFF, position: 50%} + - {color: 0x0000FF, position: 67%} + - {color: 0xFF00FF, position: 83%} + - {color: 0xFF0000, position: 100%} + style_definitions: + - id: tile_style + bg_color: 0x1C1C1E + bg_opa: COVER + radius: 14 + border_width: 0 + shadow_width: 0 + pad_all: 14 + text_color: 0xFFFFFF + text_font: font_m + - id: page_style + bg_color: 0x000000 + bg_opa: COVER + text_font: font_m + text_color: 0xFFFFFF + border_width: 0 + pad_all: 16 + pad_row: 12 + pad_column: 12 + on_idle: + timeout: 30s + then: + # without Home Assistant the status page stays + - if: + condition: + api.connected: + state_subscription_only: true + then: + - lvgl.page.show: page_0 + - globals.set: + id: dimmed + value: "true" + - lambda: 'id(panel).request_brightness(id(idle_brightness));' + top_layer: + widgets: + - obj: + id: notify_popup + hidden: true + width: 100% + height: 100% + bg_color: 0x000000 + bg_opa: 70% + border_width: 0 + radius: 0 + pad_all: 24 + on_click: + - script.stop: notify_show + - lvgl.widget.hide: notify_popup + widgets: + - obj: + clickable: false + width: 100% + height: 100% + styles: tile_style + pad_all: 20 + layout: + type: FLEX + flex_flow: COLUMN + pad_row: 12 + widgets: + - label: + id: notify_heading + text: "" + text_color: 0xF5B342 + width: 100% + long_mode: WRAP + - label: + id: notify_message + text: "" + width: 100% + long_mode: WRAP + # Pages, not a tileview: a tile switch made LVGL render the whole screen three times. No animation, + # every frame of one would be a full-screen redraw over UART (~290 kB). + pages: + - id: page_0 + styles: page_style + on_click: + - lvgl.page.show: page_1 + widgets: + - label: + id: clock_label + text: "--:--" + text_font: font_clock + align: TOP_LEFT + x: 4 + y: -10 + - label: + id: date_label + text: "" + text_color: 0xB4B4BA + align: TOP_LEFT + x: 10 + y: 118 + - label: + id: nameday_label + text: "" + text_font: font_s + text_color: 0x8E8E93 + align: TOP_LEFT + x: 10 + y: 148 + - obj: + clickable: false + align: TOP_RIGHT + width: SIZE_CONTENT + height: SIZE_CONTENT + bg_opa: TRANSP + border_width: 0 + pad_all: 0 + layout: + type: FLEX + flex_flow: COLUMN + pad_row: 10 + widgets: + - <<: !include {file: common/nspanel_terminal/forecast_day.yaml, vars: {i: 0}} + - <<: !include {file: common/nspanel_terminal/forecast_day.yaml, vars: {i: 1}} + - <<: !include {file: common/nspanel_terminal/forecast_day.yaml, vars: {i: 2}} + - obj: + clickable: false + align: BOTTOM_LEFT + x: 8 + y: -22 + width: SIZE_CONTENT + height: SIZE_CONTENT + bg_opa: TRANSP + border_width: 0 + pad_all: 0 + text_color: 0xFFFFFF + layout: + type: FLEX + pad_column: 2 + flex_flow: ROW + flex_align_cross: START + widgets: + - label: + id: in_temp_label + text: "-" + text_font: font_big + text_color: 0xFFFFFF + - label: + text: "°C" + y: 6 + text_color: 0xB4B4BA + - label: + text: "dnu" + text_font: font_s + text_color: 0x8E8E93 + align: BOTTOM_LEFT + x: 10 + - obj: + clickable: false + align: BOTTOM_LEFT + x: 158 + y: -22 + width: SIZE_CONTENT + height: SIZE_CONTENT + bg_opa: TRANSP + border_width: 0 + pad_all: 0 + text_color: 0xFFFFFF + layout: + type: FLEX + pad_column: 2 + flex_flow: ROW + flex_align_cross: START + widgets: + - label: + id: out_temp_label + text: "-" + text_font: font_big + text_color: 0xFFFFFF + - label: + text: "°C" + y: 6 + text_color: 0xB4B4BA + - label: + text: "von" + text_font: font_s + text_color: 0x8E8E93 + align: BOTTOM_LEFT + x: 160 + - obj: + clickable: false + align: BOTTOM_RIGHT + # same bottom offset as the temperatures; the boxes are equally tall, so the centres line up + y: -22 + width: SIZE_CONTENT + height: SIZE_CONTENT + bg_opa: TRANSP + border_width: 0 + pad_all: 0 + layout: + type: FLEX + flex_flow: ROW + flex_align_cross: CENTER + pad_column: 10 + widgets: + - label: + id: weather_icon_label + text: "" + text_font: icon_l + text_color: 0xFFFFFF + - obj: + clickable: false + width: SIZE_CONTENT + height: SIZE_CONTENT + bg_opa: TRANSP + border_width: 0 + pad_all: 0 + layout: + type: FLEX + flex_flow: COLUMN + pad_row: 0 + widgets: + - label: + id: today_high + text: "" + text_color: 0xFFFFFF + - label: + id: today_low + text: "" + text_color: 0x8E8E93 + - <<: !include {file: common/nspanel_terminal/grid_page.yaml, vars: {id: page_1, title: "Kuchyňa / Obývačka", prev: page_0, next: page_2, skip: false}} + - <<: !include {file: common/nspanel_terminal/grid_page.yaml, vars: {id: page_2, title: "Romanko", prev: page_1, next: page_3, skip: false}} + - <<: !include {file: common/nspanel_terminal/grid_page.yaml, vars: {id: page_3, title: "Von", prev: page_2, next: page_4, skip: false}} + - <<: !include {file: common/nspanel_terminal/grid_page.yaml, vars: {id: page_4, title: "Závlaha", prev: page_3, next: page_5, skip: false}} + - <<: !include {file: common/nspanel_terminal/grid_page.yaml, vars: {id: page_irrigation_auto, title: "Automatizácia závlahy", prev: page_4, next: page_4, skip: true}} + # Thermostat, Office R (Better Thermostat); state and actions in common/nspanel_terminal/thermostat.yaml + - id: page_5 + styles: page_style + widgets: + - label: + text: "Kúrenie Romanko" + text_font: font_s + text_color: 0xB4B4BA + width: 100% + text_align: CENTER + - <<: !include + file: common/nspanel_terminal/page_arrow.yaml + vars: {icon: "\U000F0141", align: TOP_LEFT, x: -16, to: page_4, hidden: false} + - <<: !include + file: common/nspanel_terminal/page_arrow.yaml + vars: {icon: "\U000F0142", align: TOP_RIGHT, x: 16, to: page_6, hidden: false} + # target temperature in half degrees, 10..30 °C + - arc: + id: thermo_arc + disabled: + arc_color: 0x161618 + align: BOTTOM_LEFT + y: -20 + width: 220 + height: 220 + min_value: 20 + max_value: 60 + arc_width: 16 + arc_color: 0x2C2C2E + indicator: + arc_width: 16 + arc_color: 0x8E8E93 + knob: + bg_color: 0xFFFFFF + pad_all: 2 + on_value: + - lambda: 'lv_label_set_text_fmt(id(thermo_target_label), "%.1f", x / 2.0f);' + on_release: + - script.execute: thermo_send_target + widgets: + - obj: + clickable: false + align: CENTER + y: -8 + width: SIZE_CONTENT + height: SIZE_CONTENT + bg_opa: TRANSP + border_width: 0 + pad_all: 0 + text_color: 0xFFFFFF + layout: + type: FLEX + flex_flow: ROW + flex_align_cross: START + pad_column: 2 + widgets: + - label: + id: thermo_target_label + text: "-" + text_font: font_big + text_color: 0xFFFFFF + - label: + text: "°C" + y: 6 + text_color: 0xB4B4BA + - label: + id: thermo_current_label + text: "" + text_font: font_s + text_color: 0xB4B4BA + align: CENTER + y: 34 + - label: + id: thermo_action_label + text: "" + text_font: font_s + text_color: 0x8E8E93 + align: CENTER + y: -50 + - button: + id: thermo_minus + align: BOTTOM_LEFT + x: 46 + width: 56 + height: 44 + styles: tile_style + disabled: + bg_color: 0x161618 + text_color: 0x48484A + pad_all: 0 + on_click: + - lambda: |- + lv_arc_set_value(id(thermo_arc), lv_arc_get_value(id(thermo_arc)) - 1); + lv_label_set_text_fmt(id(thermo_target_label), "%.1f", lv_arc_get_value(id(thermo_arc)) / 2.0f); + - script.execute: thermo_send_target + widgets: + - label: + text: "\U000F0374" + text_font: icon_s + align: CENTER + - button: + id: thermo_plus + align: BOTTOM_LEFT + x: 118 + width: 56 + height: 44 + styles: tile_style + disabled: + bg_color: 0x161618 + text_color: 0x48484A + pad_all: 0 + on_click: + - lambda: |- + lv_arc_set_value(id(thermo_arc), lv_arc_get_value(id(thermo_arc)) + 1); + lv_label_set_text_fmt(id(thermo_target_label), "%.1f", lv_arc_get_value(id(thermo_arc)) / 2.0f); + - script.execute: thermo_send_target + widgets: + - label: + text: "\U000F0415" + text_font: icon_s + align: CENTER + - button: + id: thermo_power + align: TOP_RIGHT + x: -90 + y: 36 + width: 82 + height: 44 + styles: tile_style + disabled: + bg_color: 0x161618 + text_color: 0x48484A + pad_all: 0 + checked: + bg_color: 0xF5B342 + text_color: 0x000000 + on_click: + - homeassistant.action: + action: climate.set_hvac_mode + data: + entity_id: climate.bt_trv_office_r + hvac_mode: !lambda 'return id(thermo_mode).state == "heat" ? "off" : "heat";' + widgets: + - label: + text: "\U000F0438" + text_font: icon_s + align: LEFT_MID + x: 6 + - label: + text: "Izba" + text_font: font_s + align: RIGHT_MID + x: -8 + # the boiler only fires with this switch on + - button: + id: heating_enabled_button + align: TOP_RIGHT + x: 0 + y: 36 + width: 82 + height: 44 + styles: tile_style + disabled: + bg_color: 0x161618 + text_color: 0x48484A + pad_all: 0 + checked: + bg_color: 0xF5B342 + text_color: 0x000000 + on_click: + - homeassistant.action: + action: switch.toggle + data: + entity_id: switch.heating_enabled + widgets: + - label: + text: "\U000F0238" + text_font: icon_s + align: LEFT_MID + x: 6 + - label: + text: "Kotol" + text_font: font_s + align: RIGHT_MID + x: -8 + # options come from the preset_modes attribute (thermostat.yaml) + - dropdown: + id: thermo_preset_dropdown + disabled: + text_color: 0x48484A + align: TOP_RIGHT + y: 92 + width: 172 + options: ["-"] + styles: tile_style + pad_all: 10 + symbol: "\U000F0140" + indicator: + text_font: icon_s + dropdown_list: + bg_color: 0x2C2C2E + text_color: 0xFFFFFF + text_font: font_m + border_width: 0 + radius: 14 + selected: + checked: + bg_color: 0xF5B342 + text_color: 0x000000 + on_value: + - homeassistant.action: + action: climate.set_preset_mode + data: + entity_id: climate.bt_trv_office_r + preset_mode: !lambda 'return x < id(preset_list).size() ? id(preset_list)[x] : std::string();' + - <<: !include {file: common/nspanel_terminal/grid_page.yaml, vars: {id: page_6, title: "Brána", prev: page_5, next: page_7, skip: false}} + - <<: !include {file: common/nspanel_terminal/grid_page.yaml, vars: {id: page_gate_auto, title: "Automatizácia brány", prev: page_6, next: page_6, skip: true}} + # Status: boot screen until Home Assistant connects, then the last (diagnostic) page + - id: page_7 + styles: page_style + on_load: + - script.execute: update_status + widgets: + - <<: !include + file: common/nspanel_terminal/page_arrow.yaml + vars: {icon: "\U000F0141", align: TOP_LEFT, x: -16, to: page_6, hidden: false} + - image: + src: esphome_logo + align: TOP_MID + - label: + align: TOP_MID + y: 96 + text: !lambda return App.get_name(); + - obj: + clickable: false + align: TOP_LEFT + x: 8 + y: 136 + width: 100% + height: SIZE_CONTENT + bg_opa: TRANSP + border_width: 0 + pad_all: 0 + layout: + type: FLEX + flex_flow: COLUMN + pad_row: 6 + widgets: + - label: + id: status_wifi + text_font: font_s + text: "" + - label: + id: status_ips + text_font: font_s + text_color: 0x8E8E93 + pad_left: 20 + text: "" + - label: + id: status_ha + text_font: font_s + text: "" + # shown only while flashing (ota: above) + - label: + id: status_ota + text_font: font_s + text: "" + hidden: true + - label: + id: status_footer + text_font: font_s + text_color: 0x8E8E93 + text: "" + # Light detail, opened by a long press on a light button (script open_light) + - id: page_light + styles: page_style + layout: + type: FLEX + flex_flow: COLUMN + pad_row: 26 + widgets: + - obj: + clickable: false + width: 100% + height: 44 + bg_opa: TRANSP + border_width: 0 + pad_all: 0 + widgets: + - obj: + align: LEFT_MID + x: -16 + width: 72 + height: 52 + bg_opa: TRANSP + border_width: 0 + pad_all: 0 + on_click: + - lambda: 'id(lvgl_main)->show_page(id(back_page), LV_SCREEN_LOAD_ANIM_NONE, 0);' + widgets: + - label: + text: "\U000F0141" + text_font: icon_s + text_color: 0xB4B4BA + align: CENTER + - label: + id: detail_title + text: "" + align: CENTER + - button: + id: detail_power + align: RIGHT_MID + width: 64 + height: 44 + styles: tile_style + pad_all: 0 + checked: + bg_color: 0xF5B342 + text_color: 0x000000 + on_click: + - homeassistant.action: + action: light.toggle + data: + entity_id: !lambda return id(cur_light); + widgets: + - label: + text: "\U000F0425" + text_font: icon_s + align: CENTER + - obj: + id: detail_bri_row + clickable: false + width: 100% + height: SIZE_CONTENT + bg_opa: TRANSP + border_width: 0 + pad_all: 0 + layout: + type: FLEX + flex_flow: ROW + flex_align_cross: CENTER + pad_column: 14 + widgets: + - label: + text: "\U000F00DF" + text_font: icon_s + text_color: 0xB4B4BA + - slider: + id: detail_bri + flex_grow: 1 + height: 44 + min_value: 1 + max_value: 100 + radius: 22 + bg_color: 0x2C2C2E + indicator: + bg_color: 0xF5B342 + radius: 22 + knob: + bg_color: 0xFFFFFF + pad_all: 2 + on_release: + - homeassistant.action: + action: light.turn_on + data: + entity_id: !lambda return id(cur_light); + brightness_pct: !lambda return (int) x; + - obj: + id: detail_ct_row + clickable: false + width: 100% + height: SIZE_CONTENT + bg_opa: TRANSP + border_width: 0 + pad_all: 0 + layout: + type: FLEX + flex_flow: ROW + flex_align_cross: CENTER + pad_column: 14 + widgets: + - label: + text: "\U000F05A8" + text_font: icon_s + text_color: 0xB4B4BA + - slider: + id: detail_ct + flex_grow: 1 + height: 44 + min_value: 1700 + max_value: 6500 + radius: 22 + bg_grad: ct_grad + bg_opa: COVER + indicator: + bg_opa: TRANSP + radius: 22 + knob: + bg_color: 0xFFFFFF + pad_all: 2 + on_release: + - homeassistant.action: + action: light.turn_on + data: + entity_id: !lambda return id(cur_light); + color_temp_kelvin: !lambda return (int) x; + - obj: + id: detail_hue_row + clickable: false + width: 100% + height: SIZE_CONTENT + bg_opa: TRANSP + border_width: 0 + pad_all: 0 + layout: + type: FLEX + flex_flow: ROW + flex_align_cross: CENTER + pad_column: 14 + widgets: + - label: + text: "\U000F03D8" + text_font: icon_s + text_color: 0xB4B4BA + - slider: + id: detail_hue + flex_grow: 1 + height: 44 + min_value: 0 + max_value: 360 + radius: 22 + bg_grad: hue_grad + bg_opa: COVER + indicator: + bg_opa: TRANSP + radius: 22 + knob: + bg_color: 0xFFFFFF + pad_all: 2 + on_release: + - homeassistant.action: + action: light.turn_on + data: + entity_id: !lambda return id(cur_light); + data_template: + hs_color: "{{ [hue | int, 100] }}" + variables: + hue: !lambda return (int) x; + +text_sensor: + - platform: homeassistant + id: forecast + entity_id: sensor.weather_forecast_daily + attribute: forecast + internal: true + on_value: + - script.execute: update_forecast + - platform: homeassistant + id: nameday + entity_id: sensor.nameday_sk + internal: true + on_value: + - lvgl.label.update: + id: nameday_label + text: !lambda return x; + - platform: homeassistant + id: weather + entity_id: weather.outside + internal: true + on_value: + - lambda: |- + lv_label_set_text(id(weather_icon_label), weather_icon(x)); + +button: + # as on the other panels: put button._info on a dashboard, HA presses it + - platform: template + name: Info + id: info_button + entity_category: diagnostic + on_press: + - script.execute: info_popup binary_sensor: - platform: gpio @@ -470,12 +1292,14 @@ binary_sensor: pin: number: 14 inverted: true - on_press: - - switch.toggle: relay_1 - # - homeassistant.service: - # service: switch.toggle - # data: - # entity_id: switch.gate_open + # like the other panels: toggle the office light and show the page with its tile + on_click: + - homeassistant.action: + action: light.toggle + data: + entity_id: light.mcu_nspanel_office_r_light + - lvgl.page.show: page_2 + - script.execute: wake_screen - platform: gpio name: Right Button @@ -501,29 +1325,12 @@ switch: id: relay_1 pin: number: 22 - on_turn_on: - # show a light on the panel when we swich on the light - # - lambda: 'id(nspanel).send_custom_command("pageType~popupLight~[TITLE TO SHOW ON SCREEN]~[ENTITY NAME]");' - - lambda: 'id(nspanel_id).send_display_command("pageType~popupLight~Light 1~light.bed_light");' - # on_turn_off: - # # send to screensaver when switch off the light - # - mqtt.publish: - # topic: $panel_recv_topic - # payload: '{"CustomRecv":"event,sleepReached,cardGrid"}' - platform: gpio name: Relay 2 id: relay_2 pin: number: 19 - on_turn_on: - # show a light on the panel when we swich on the light - - lambda: 'id(nspanel_id).send_display_command("pageType~popupLight~Light 2~light.bed_light2");' - # on_turn_off: - # # send to screensaver when switch off the light - # - mqtt.publish: - # topic: $panel_recv_topic - # payload: '{"CustomRecv":"event,sleepReached,cardGrid"}' # Turn screen power on/off. Easy way to configure the screen power control, but this should not be used from HA, as all components must be re-initialized afterwards. For lights, names of lights etc. this practically means that the state must change once to happen. - platform: gpio @@ -559,20 +1366,28 @@ sensor: b_constant: 3950 reference_temperature: 25°C reference_resistance: 10kOhm - name: Living Room Temperature Entry + + - platform: homeassistant + id: inside_temperature + entity_id: sensor.zigbee_office_r_temperature + internal: true + on_value: + - lvgl.label.update: + id: in_temp_label + text: !lambda 'return std::isnan(x) ? std::string("--") : str_sprintf("%.1f", x);' + + - platform: homeassistant + id: outside_temperature + entity_id: sensor.zigbee_outside_temperature + internal: true + on_value: + - lvgl.label.update: + id: out_temp_label + text: !lambda 'return std::isnan(x) ? std::string("--") : str_sprintf("%.1f", x);' - platform: template id: room_temperature_id -text_sensor: - - platform: homeassistant - id: name_day - entity_id: sensor.nameday_sk - on_value: - - lambda: |- - id(nspanel_id).set_time_format("%H:%M~" + x); - id(nspanel_id).update_time(); - # esp32_ble_tracker: # scan_parameters: # duration: 1min