globals: - id: display_timeout type: int restore_value: true initial_value: "2" - id: current_language type: int restore_value: yes initial_value: '6' - id: vacuum_translations type: std::map - id: cover_translations type: std::map - id: climate_translations type: std::map - id: weather_translations type: std::map - id: alarm_panel_translations type: std::map text_sensor: - platform: homeassistant id: translations_lang entity_id: sensor.display_tools on_value: - lambda: |- std::string lang_code = x; int lang_index = id(flag_icon_mapping_index).get(lang_code); if (lang_index != 0 || lang_code == "de") { id(current_language) = lang_index; } - lvgl.dropdown.update: id: language_dropdown selected_index: !lambda |- int index = id(flag_icon_mapping_index).get(x); if (index != 0 || x == "de") { return index; } return 6; - lvgl.image.update: id: flag_language_image src: !lambda |- int index = id(flag_icon_mapping_index).get(x); if (index != 0 || x == "de") { return id(flag_icon_mapping_image)[index]; } return id(flag_icon_mapping_image)[6]; - platform: homeassistant id: translations_vacuum entity_id: sensor.display_tools attribute: vacuum on_value: then: - lambda: |- if (x.length() > 0) { JsonDocument doc; DeserializationError error = deserializeJson(doc, x); if (!error) { id(vacuum_translations).clear(); for (auto kv : doc.as()) { id(vacuum_translations)[kv.key().c_str()] = kv.value().as(); } } } - platform: homeassistant id: translations_cover entity_id: sensor.display_tools attribute: cover on_value: then: - lambda: |- if (x.length() > 0) { JsonDocument doc; DeserializationError error = deserializeJson(doc, x); if (!error) { id(cover_translations).clear(); for (auto kv : doc.as()) { id(cover_translations)[kv.key().c_str()] = kv.value().as(); } } } - platform: homeassistant id: translations_climate entity_id: sensor.display_tools attribute: climate on_value: then: - lambda: |- if (x.length() > 0) { JsonDocument doc; DeserializationError error = deserializeJson(doc, x); if (!error) { id(climate_translations).clear(); for (auto kv : doc.as()) { id(climate_translations)[kv.key().c_str()] = kv.value().as(); } } } - platform: homeassistant id: translations_weather entity_id: sensor.display_tools attribute: weather on_value: then: - lambda: |- if (x.length() > 0) { JsonDocument doc; DeserializationError error = deserializeJson(doc, x); if (!error) { id(weather_translations).clear(); for (auto kv : doc.as()) { id(weather_translations)[kv.key().c_str()] = kv.value().as(); } } } - platform: homeassistant id: translations_alarm_panel entity_id: sensor.display_tools attribute: alarm_control_panel on_value: then: - lambda: |- if (x.length() > 0) { JsonDocument doc; DeserializationError error = deserializeJson(doc, x); if (!error) { id(alarm_panel_translations).clear(); for (auto kv : doc.as()) { id(alarm_panel_translations)[kv.key().c_str()] = kv.value().as(); } } } script: - id: get_translation parameters: component_param: string key_param: string then: - lambda: |- std::string component = component_param; std::string key = key_param; std::string result = key; if (component == "vacuum") { auto it = id(vacuum_translations).find(key); if (it != id(vacuum_translations).end()) { result = it->second; } } else if (component == "cover") { auto it = id(cover_translations).find(key); if (it != id(cover_translations).end()) { result = it->second; } } else if (component == "climate") { auto it = id(climate_translations).find(key); if (it != id(climate_translations).end()) { result = it->second; } } else if (component == "weather") { auto it = id(weather_translations).find(key); if (it != id(weather_translations).end()) { result = it->second; } } else if (component == "alarm_panel") { auto it = id(alarm_panel_translations).find(key); if (it != id(alarm_panel_translations).end()) { result = it->second; } } lvgl: on_idle: timeout: !lambda "return (id(display_timeout_number).state * 60 * 1000);" then: - if: condition: lambda: 'return id(display_timeout_number).state >= 0;' then: - logger.log: "LVGL is idle" - light.turn_off: display_backlight - lvgl.pause: else: - logger.log: "LVGL idle, but backlight is on" pages: - id: settings_page bg_color: color_slate_blue_gray widgets: # language: - obj: id: language_bg x: 20 y: 20 width: 440 height: 100 align: TOP_LEFT pad_all: 0 bg_color: color_steel_blue bg_opa: 20% border_opa: TRANSP border_width: 0 shadow_opa: TRANSP radius: 10 widgets: - label: id: language_label x: 20 align: LEFT_MID text_font: nunito_20 text_color: color_misty_blue text: "Language" - image: id: flag_language_image x: 160 align: LEFT_MID src: !lambda return id(flag_icon_mapping_image)[id(current_language)]; - dropdown: id: language_dropdown x: 240 width: 200 align: LEFT_MID options: - Deutsch # de - Español # es - Français # fr - English (GB) # en-GB - Italiano # it - Português # pt - Русский # ru - English (US) # en - Polski # pl - Türkçe # tr - Svenska # sv - Română # ro - Nederlands # nl - Magyar # hu - Bahasa Indonesia # id - Tiếng Việt # vi - Čeština # cs - Suomi # fi bg_opa: TRANSP shadow_opa: TRANSP border_opa: TRANSP border_width: 0 text_font: nunito_20 text_color: color_misty_blue dropdown_list: bg_color: color_slate_blue_gray shadow_opa: TRANSP border_color: color_misty_blue border_width: 2 text_font: nunito_20 text_color: color_misty_blue text_line_space: 7 pad_all: 8 max_height: 280 selected: checked: bg_color: color_steel_blue bg_opa: 20% text_color: color_misty_blue pressed: bg_opa: TRANSP text_color: color_misty_blue indicator: text_opa: TRANSP on_value: - lvgl.image.update: id: flag_language_image src: !lambda return id(flag_icon_mapping_image)[x]; - homeassistant.action: action: display_tools.get_translations_esphome data: language: !lambda return id(flag_icon_mapping_name).get(x).c_str(); category: entity_component keys: '[ "component.vacuum.entity_component._.state.cleaning", "component.vacuum.entity_component._.state.docked", "component.vacuum.entity_component._.state.error", "component.vacuum.entity_component._.state.idle", "component.vacuum.entity_component._.state.off", "component.vacuum.entity_component._.state.on", "component.vacuum.entity_component._.state.paused", "component.vacuum.entity_component._.state.returning", "component.cover.entity_component._.state.closed", "component.cover.entity_component._.state.closing", "component.cover.entity_component._.state.open", "component.cover.entity_component._.state.opening", "component.cover.entity_component._.state.stopped", "component.climate.entity_component._.state_attributes.hvac_action.state.cooling", "component.climate.entity_component._.state_attributes.hvac_action.state.defrosting", "component.climate.entity_component._.state_attributes.hvac_action.state.drying", "component.climate.entity_component._.state_attributes.hvac_action.state.fan", "component.climate.entity_component._.state_attributes.hvac_action.state.heating", "component.climate.entity_component._.state_attributes.hvac_action.state.idle", "component.climate.entity_component._.state_attributes.hvac_action.state.off", "component.weather.entity_component._.state.clear-night", "component.weather.entity_component._.state.cloudy", "component.weather.entity_component._.state.exceptional", "component.weather.entity_component._.state.fog", "component.weather.entity_component._.state.hail", "component.weather.entity_component._.state.lightning", "component.weather.entity_component._.state.lightning-rainy", "component.weather.entity_component._.state.partlycloudy", "component.weather.entity_component._.state.pouring", "component.weather.entity_component._.state.rainy", "component.weather.entity_component._.state.snowy", "component.weather.entity_component._.state.snowy-rainy", "component.weather.entity_component._.state.sunny", "component.weather.entity_component._.state.windy", "component.weather.entity_component._.state.windy-variant", "component.alarm_control_panel.entity_component._.state.armed", "component.alarm_control_panel.entity_component._.state.armed_away", "component.alarm_control_panel.entity_component._.state.armed_custom_bypass", "component.alarm_control_panel.entity_component._.state.armed_home", "component.alarm_control_panel.entity_component._.state.armed_night", "component.alarm_control_panel.entity_component._.state.armed_vacation", "component.alarm_control_panel.entity_component._.state.arming", "component.alarm_control_panel.entity_component._.state.disarmed", "component.alarm_control_panel.entity_component._.state.disarming", "component.alarm_control_panel.entity_component._.state.pending", "component.alarm_control_panel.entity_component._.state.triggered" ]' # backlight: - obj: id: backlight_bg x: 20 y: 140 width: 440 height: 100 align: TOP_LEFT pad_all: 0 bg_color: color_steel_blue bg_opa: 20% border_opa: TRANSP border_width: 0 shadow_opa: TRANSP radius: 10 widgets: - label: id: display_backlight_label x: 20 align: LEFT_MID text_font: nunito_20 text_color: color_misty_blue text: "Backlight" - slider: id: display_backlight_brightness_slider x: -20 radius: 10 bg_color: color_slate_blue_gray align: RIGHT_MID width: 260 height: 60 min_value: 35 max_value: 100 value: 100 indicator: bg_color: color_misty_blue radius: 10 knob: bg_opa: TRANSP on_release: then: - light.turn_on: id: display_backlight brightness: !lambda return int(x)/ 100.0; # sleep mode: - obj: id: sleep_mode_bg x: 20 y: 260 width: 440 height: 100 align: TOP_LEFT pad_all: 0 bg_color: color_steel_blue bg_opa: 20% border_opa: TRANSP border_width: 0 shadow_opa: TRANSP radius: 10 widgets: - label: id: display_timeout_label x: 20 align: LEFT_MID text_font: nunito_20 text_color: color_misty_blue text: "Sleep mode" - dropdown: id: display_timeout_dropdown x: 220 width: 200 align: LEFT_MID selected_index: !lambda return id(display_timeout); options: - Never - 1 minute - 5 minutes - 10 minutes - 30 minutes - 1 hour - 6 hours - 12 hours bg_opa: TRANSP shadow_opa: TRANSP border_opa: TRANSP border_width: 0 text_font: nunito_20 text_color: color_misty_blue dropdown_list: align: CENTER bg_color: color_slate_blue_gray shadow_opa: TRANSP border_color: color_misty_blue border_width: 2 text_font: nunito_20 text_color: color_misty_blue text_line_space: 10 pad_all: 8 max_height: 360 selected: checked: bg_color: color_steel_blue bg_opa: 20% text_color: color_misty_blue pressed: bg_opa: TRANSP text_color: color_misty_blue indicator: text_opa: TRANSP on_value: then: - number.set: id: display_timeout_number value: !lambda |- static const int backlight_time[] = {-1, 1, 5, 10, 30, 60, 360, 720}; return backlight_time[x]; - globals.set: id: display_timeout value: !lambda return x; number: - platform: template id: display_timeout_number name: LVGL screen timeout optimistic: true unit_of_measurement: "m" initial_value: 10 restore_value: true min_value: -1 max_value: 720 step: 1 mode: box mapping: - id: flag_icon_mapping_image from: int to: image entries: 0: flags_de_img 1: flags_es_img 2: flags_fr_img 3: flags_gb_img 4: flags_it_img 5: flags_pt_img 6: flags_ru_img 7: flags_us_img 8: flags_pl_img 9: flags_tr_img 10: flags_sv_img 11: flags_ro_img 12: flags_nl_img 13: flags_hu_img 14: flags_id_img 15: flags_vi_img 16: flags_cs_img 17: flags_fi_img - id: flag_icon_mapping_name from: int to: string entries: 0: de 1: es 2: fr 3: en-GB 4: it 5: pt 6: ru 7: en 8: pl 9: tr 10: sv 11: ro 12: nl 13: hu 14: id 15: vi 16: cs 17: fi - id: flag_icon_mapping_index from: string to: int entries: de: 0 es: 1 fr: 2 en-GB: 3 it: 4 pt: 5 ru: 6 en: 7 pl: 8 tr: 9 sv: 10 ro: 11 nl: 12 hu: 13 id: 14 vi: 15 cs: 16 fi: 17 esphome: on_boot: - priority: -100 then: - homeassistant.action: action: display_tools.get_translations_esphome data: language: !lambda return id(flag_icon_mapping_name).get(id(current_language)).c_str(); category: entity_component keys: '[ "component.vacuum.entity_component._.state.cleaning", "component.vacuum.entity_component._.state.docked", "component.vacuum.entity_component._.state.error", "component.vacuum.entity_component._.state.idle", "component.vacuum.entity_component._.state.off", "component.vacuum.entity_component._.state.on", "component.vacuum.entity_component._.state.paused", "component.vacuum.entity_component._.state.returning", "component.cover.entity_component._.state.closed", "component.cover.entity_component._.state.closing", "component.cover.entity_component._.state.open", "component.cover.entity_component._.state.opening", "component.cover.entity_component._.state.stopped", "component.climate.entity_component._.state_attributes.hvac_action.state.cooling", "component.climate.entity_component._.state_attributes.hvac_action.state.defrosting", "component.climate.entity_component._.state_attributes.hvac_action.state.drying", "component.climate.entity_component._.state_attributes.hvac_action.state.fan", "component.climate.entity_component._.state_attributes.hvac_action.state.heating", "component.climate.entity_component._.state_attributes.hvac_action.state.idle", "component.climate.entity_component._.state_attributes.hvac_action.state.off", "component.weather.entity_component._.state.clear-night", "component.weather.entity_component._.state.cloudy", "component.weather.entity_component._.state.exceptional", "component.weather.entity_component._.state.fog", "component.weather.entity_component._.state.hail", "component.weather.entity_component._.state.lightning", "component.weather.entity_component._.state.lightning-rainy", "component.weather.entity_component._.state.partlycloudy", "component.weather.entity_component._.state.pouring", "component.weather.entity_component._.state.rainy", "component.weather.entity_component._.state.snowy", "component.weather.entity_component._.state.snowy-rainy", "component.weather.entity_component._.state.sunny", "component.weather.entity_component._.state.windy", "component.weather.entity_component._.state.windy-variant", "component.alarm_control_panel.entity_component._.state.armed", "component.alarm_control_panel.entity_component._.state.armed_away", "component.alarm_control_panel.entity_component._.state.armed_custom_bypass", "component.alarm_control_panel.entity_component._.state.armed_home", "component.alarm_control_panel.entity_component._.state.armed_night", "component.alarm_control_panel.entity_component._.state.armed_vacation", "component.alarm_control_panel.entity_component._.state.arming", "component.alarm_control_panel.entity_component._.state.disarmed", "component.alarm_control_panel.entity_component._.state.disarming", "component.alarm_control_panel.entity_component._.state.pending", "component.alarm_control_panel.entity_component._.state.triggered" ]' - lvgl.dropdown.update: id: display_timeout_dropdown selected_index: !lambda return id(display_timeout); api: on_client_connected: - lvgl.dropdown.update: id: display_timeout_dropdown selected_index: !lambda return id(display_timeout);