diff --git a/advanced/esphome/nspanel_esphome_core.yaml b/advanced/esphome/nspanel_esphome_core.yaml index 2ac320b..7dcabd6 100644 --- a/advanced/esphome/nspanel_esphome_core.yaml +++ b/advanced/esphome/nspanel_esphome_core.yaml @@ -144,606 +144,607 @@ time: api: id: api_server reboot_timeout: 0s + services: - ##### Service to send a command "printf" directly to the display ##### - - service: send_command_printf - variables: - cmd: string - then: - - lambda: 'disp1->send_command_printf("%s", cmd.c_str());' + ##### Service to send a command "printf" directly to the display ##### + - service: send_command_printf + variables: + cmd: string + then: + - lambda: 'disp1->send_command_printf("%s", cmd.c_str());' - ##### Service to send a command "text_printf" directly to the display ##### - - service: send_command_text_printf - variables: - component: string - message: string - then: - - lambda: 'disp1->set_component_text_printf(component.c_str(), "%s", message.c_str());' + ##### Service to send a command "text_printf" directly to the display ##### + - service: send_command_text_printf + variables: + component: string + message: string + then: + - lambda: 'disp1->set_component_text_printf(component.c_str(), "%s", message.c_str());' - ##### Service to send a command "component_value (Dualstate Button)" directly to the display ##### - - service: send_command_value - variables: - component: string - val: int - then: - - lambda: |- - disp1->set_component_value(component.c_str(), val); + ##### Service to send a command "component_value (Dualstate Button)" directly to the display ##### + - service: send_command_value + variables: + component: string + val: int + then: + - lambda: |- + disp1->set_component_value(component.c_str(), val); - ##### Service to send a command "hide componente" directly to the display ##### - - service: send_command_hide ### unused ### - variables: - component: string - then: - - lambda: 'disp1->hide_component(component.c_str());' + ##### Service to send a command "hide componente" directly to the display ##### + - service: send_command_hide ### unused ### + variables: + component: string + then: + - lambda: 'disp1->hide_component(component.c_str());' - ##### Service to send a command "show componente" directly to the display ##### - - service: send_command_show ### unused ### - variables: - component: string - then: - - lambda: 'disp1->show_component(component.c_str());' + ##### Service to send a command "show componente" directly to the display ##### + - service: send_command_show ### unused ### + variables: + component: string + then: + - lambda: 'disp1->show_component(component.c_str());' - ##### Service to send a command "font color" directly to the display ##### - - service: set_component_color - variables: - component: string - foreground: int[] - then: - - lambda: set_component_color->execute(component, foreground); + ##### Service to send a command "font color" directly to the display ##### + - service: set_component_color + variables: + component: string + foreground: int[] + then: + - lambda: set_component_color->execute(component, foreground); - ##### Service to play a rtttl tones ##### - # Example tones : https://codebender.cc/sketch:109888#RTTTL%20Songs.ino - - service: play_rtttl - variables: - song_str: string - then: - - rtttl.play: - rtttl: !lambda 'return song_str;' + ##### Service to play a rtttl tones ##### + # Example tones : https://codebender.cc/sketch:109888#RTTTL%20Songs.ino + - service: play_rtttl + variables: + song_str: string + then: + - rtttl.play: + rtttl: !lambda 'return song_str;' - #### Service to populate the alarm settings page ##### - - service: alarm_settings - variables: - page_title: string - state: string - supported_features: int - code_format: string - code_arm_required: bool - entity: string - mui_alarm: string[] #std::vector #std::map - then: - - lambda: |- - // Is page Alarm visible? - if (current_page->state == "alarm") // To do: This page constructor should be moved to Blueprint - { // Update alarm page - detailed_entity->publish_state(entity); - - // Alarm page - Header - update_alarm_icon->execute("icon_state", state.c_str()); - if (page_title.find("\\r") != std::string::npos) { - page_title = page_title.replace(page_title.find("\\r"), 2, " "); - } - disp1->set_component_text_printf("page_label", "%s", page_title.c_str()); - disp1->set_component_text_printf("code_format", "%s", code_format.c_str()); - if (code_arm_required) disp1->set_component_text_printf("code_arm_req", "1"); else disp1->set_component_text_printf("code_arm_req", "0"); - - // Alarm page - Button's text - display_wrapped_text->execute("bt_home_text", mui_alarm[0].c_str(), 10); - display_wrapped_text->execute("bt_away_text", mui_alarm[1].c_str(), 10); - display_wrapped_text->execute("bt_night_text", mui_alarm[2].c_str(), 10); - display_wrapped_text->execute("bt_vacat_text", mui_alarm[3].c_str(), 10); - display_wrapped_text->execute("bt_bypass_text", mui_alarm[4].c_str(), 10); - display_wrapped_text->execute("bt_disarm_text", mui_alarm[5].c_str(), 10); - - // Alarm page - Buttons - if (supported_features & 1 or state == "armed_home") // Alarm - Button - Home - { - disp1->send_command_printf("bt_home_pic.pic=%i", (state == "armed_home") ? 43 : 42); - disp1->set_component_background_color("bt_home_text", (state == "armed_home") ? 19818 : 52857); - disp1->set_component_background_color("bt_home_icon", (state == "armed_home") ? 19818 : 52857); - disp1->set_component_font_color("bt_home_text", (state == "armed_home") ? 65535 : 0); - disp1->set_component_font_color("bt_home_icon", (state == "armed_home") ? 65535 : 0); - if (state == "armed_home") disp1->hide_component("bt_home"); else disp1->show_component("bt_home"); - } - if (supported_features & 2 or state == "armed_away") // Alarm - Button - Away - { - disp1->send_command_printf("bt_away_pic.pic=%i", (state == "armed_away") ? 43 : 42); - disp1->set_component_background_color("bt_away_text", (state == "armed_away") ? 19818 : 52857); - disp1->set_component_background_color("bt_away_icon", (state == "armed_away") ? 19818 : 52857); - disp1->set_component_font_color("bt_away_text", (state == "armed_away") ? 65535 : 0); - disp1->set_component_font_color("bt_away_icon", (state == "armed_away") ? 65535 : 0); - if (state == "armed_away") disp1->hide_component("bt_away"); else disp1->show_component("bt_away"); - } - if (supported_features & 4 or state == "armed_night") // Alarm - Button - Night - { - disp1->send_command_printf("bt_night_pic.pic=%i", (state == "armed_night") ? 43 : 42); - disp1->set_component_background_color("bt_night_text", (state == "armed_night") ? 19818 : 52857); - disp1->set_component_background_color("bt_night_icon", (state == "armed_night") ? 19818 : 52857); - disp1->set_component_font_color("bt_night_text", (state == "armed_night") ? 65535 : 0); - disp1->set_component_font_color("bt_night_icon", (state == "armed_night") ? 65535 : 0); - if (state == "armed_night") disp1->hide_component("bt_night"); else disp1->show_component("bt_night"); - } - if (supported_features & 32 or state == "armed_vacation") // Alarm - Button - Vacation - { - disp1->send_command_printf("bt_vacat_pic.pic=%i", (state == "armed_vacation") ? 43 : 42); - disp1->set_component_background_color("bt_vacat_text", (state == "armed_vacation") ? 19818 : 52857); - disp1->set_component_background_color("bt_vacat_icon", (state == "armed_vacation") ? 19818 : 52857); - disp1->set_component_font_color("bt_vacat_text", (state == "armed_vacation") ? 65535 : 0); - disp1->set_component_font_color("bt_vacat_icon", (state == "armed_vacation") ? 65535 : 0); - if (state == "armed_vacation") disp1->hide_component("bt_vacat"); else disp1->show_component("bt_vacat"); - } - if (supported_features & 16 or state == "armed_bypass") // Alarm - Button - Custom bypass - { - disp1->send_command_printf("bt_bypass_pic.pic=%i", (state == "armed_bypass") ? 43 : 42); - disp1->set_component_background_color("bt_bypass_text", (state == "armed_bypass") ? 19818 : 52857); - disp1->set_component_background_color("bt_bypass_icon", (state == "armed_bypass") ? 19818 : 52857); - disp1->set_component_font_color("bt_bypass_text", (state == "armed_bypass") ? 65535 : 0); - disp1->set_component_font_color("bt_bypass_icon", (state == "armed_bypass") ? 65535 : 0); - if (state == "armed_bypass") disp1->hide_component("bt_bypass"); else disp1->show_component("bt_bypass"); - } - if ( true ) // Alarm - Button - Disarm - { - disp1->send_command_printf("bt_disarm_pic.pic=%i", (state == "disarmed") ? 43 : 42); - disp1->set_component_background_color("bt_disarm_text", (state == "disarmed") ? 19818 : 52857); - disp1->set_component_background_color("bt_disarm_icon", (state == "disarmed") ? 19818 : 52857); - disp1->set_component_font_color("bt_disarm_text", (state == "disarmed") ? 65535 : 0); - disp1->set_component_font_color("bt_disarm_icon", (state == "disarmed") ? 65535 : 0); - if (state == "disarmed") disp1->hide_component("bt_disarm"); else disp1->show_component("bt_disarm"); - } - } - - ##### Service for transferring global settings from the blueprint to ESPHome ##### - - service: global_settings - variables: - blueprint_version: string - relay1_local_control: bool - relay1_icon: string - relay1_icon_color: int - relay1_fallback: bool - relay2_local_control: bool - relay2_icon: string - relay2_icon_color: int - relay2_fallback: bool - embedded_climate: bool - embedded_climate_friendly_name: string - embedded_indoor_temperature: bool - temperature_unit_is_fahrenheit: bool - mui_please_confirm: string - then: - - lambda: |- - static const char *const TAG = "service.global_settings"; - // Blueprint version - ESP_LOGV(TAG, "Check Blueprint version"); - id(version_blueprint) = blueprint_version; - check_versions->execute(); - - // Relays - ESP_LOGV(TAG, "Setup relays"); - relay1_local->publish_state(relay1_local_control); - relay2_local->publish_state(relay2_local_control); - id(relay_1_fallback) = relay1_fallback; - id(relay_2_fallback) = relay2_fallback; - disp1->set_component_font_color("home.icon_top_01", relay1_icon_color); - disp1->set_component_font_color("home.icon_top_02", relay2_icon_color); - disp1->set_component_text_printf("home.icon_top_01", "%s", relay1_icon.c_str()); - disp1->set_component_text_printf("home.icon_top_02", "%s", relay2_icon.c_str()); - id(home_relay1_icon) = relay1_icon.c_str(); - id(home_relay2_icon) = relay2_icon.c_str(); - id(home_relay1_icon_color) = relay1_icon_color; - id(home_relay2_icon_color) = relay2_icon_color; - - // Embedded thermostat - ESP_LOGV(TAG, "Load embedded thermostat"); - id(is_embedded_thermostat) = embedded_climate; - addon_climate_set_climate_friendly_name->execute(embedded_climate_friendly_name.c_str()); - - // Indoor temperature - ESP_LOGV(TAG, "Set indoor temperature"); - id(embedded_indoor_temp) = embedded_indoor_temperature; - id(temp_unit_fahrenheit) = temperature_unit_is_fahrenheit; - display_embedded_temp->execute(); - - // Confirm page - ESP_LOGV(TAG, "Setup confirm page"); - display_wrapped_text->execute("confirm.title", mui_please_confirm.c_str(), 15); - - // Update home page - ESP_LOGV(TAG, "Update home page"); - page_home->execute(); - - ESP_LOGV(TAG, "Current page: %s", current_page->state.c_str()); - - - if: - condition: - - text_sensor.state: # Is boot page visible? - id: current_page - state: boot - then: - - lambda: |- - ESP_LOGV("service.global_settings", "Boot page is visible"); - disp1->set_component_text_printf("boot.bluep_version", "%s", blueprint_version.c_str()); - - wait_until: - condition: - - not: - - text_sensor.state: # Is boot page visible? - id: current_page - state: 'boot' - timeout: 2s - - if: - condition: - - text_sensor.state: # Avoid this being called twice by multiple boot triggers - id: current_page - state: 'boot' - then: - - lambda: |- - ESP_LOGV("service.global_settings", "Boot page still visible"); - - if: - condition: - switch.is_on: notification_sound - then: - - rtttl.play: - rtttl: 'two short:d=4,o=5,b=100:16e6,16e6' - - lambda: |- - ESP_LOGD("service.global_settings", "Jump to wake-up page: %s", wakeup_page_name->state.c_str()); - disp1->goto_page(wakeup_page_name->state.c_str()); - timer_reset_all->execute(wakeup_page_name->state.c_str()); - - ##### Service to show a notification-message on the screen ##### - - service: notification_show - variables: - label: string - message: string - then: - - lambda: |- - ESP_LOGV("service.notification_show", "Starting"); - - disp1->send_command_printf("is_notification=1"); - disp1->goto_page("notification"); - disp1->set_component_text_printf("notification.notifi_label", "%s", label.c_str()); - - display_wrapped_text->execute("notification.notifi_text01", message.c_str(), id(display_mode) == 2 ? 23 : 32); - - notification_label->publish_state(label.c_str()); - notification_text->publish_state(message.c_str()); - timer_reset_all->execute(current_page->state.c_str()); - notification_unread->turn_on(); - if (notification_sound->state) buzzer->play("two short:d=4,o=5,b=100:16e6,16e6"); - - ##### Service to clear the notification ##### - - service: notification_clear - then: - - logger.log: "Service: notification_clear" - - script.execute: notification_clear - - ##### Service to open information for settings-page(s) - - service: open_entity_settings_page - variables: - page: string - page_label: string - page_icon: string - page_icon_color: int[] - entity: string - back_page: string - then: - - lambda: |- - detailed_entity->publish_state(entity); - if (page == "alarm_control_panel") page = "alarm"; - std::string cmd_page = std::string("page ") + page.c_str(); - disp1->send_command_printf(cmd_page.c_str()); - if (page_label.find("\\r") != std::string::npos) { - page_label = page_label.replace(page_label.find("\\r"), 2, " "); - } - disp1->set_component_text_printf("page_label", "%s", page_label.c_str()); - disp1->set_component_text_printf("back_page", "%s", back_page.c_str()); - if (page == "climate") - { - if (entity == "embedded_climate") addon_climate_set_climate_friendly_name->execute(page_label.c_str()); - disp1->set_component_value("embedded", (entity == "embedded_climate") ? 1 : 0); - } - else - { - if ((page_icon != std::string()) and (page_icon != "")) - disp1->set_component_text_printf("icon_state", "%s", page_icon.c_str()); - set_component_color->execute("icon_state", page_icon_color); - } - - # Service to show a QR code on the display (ex. for WiFi password) - - service: qrcode - variables: - title: string - qrcode: string - show: bool - then: - - lambda: |- - disp1->set_component_text_printf("qrcode.qrcode_label", "%s", title.c_str()); - disp1->set_component_text_printf("qrcode.qrcode_value", "%s", qrcode.c_str()); - if (show) disp1->goto_page("qrcode"); - - #### Service to set climate state #### - - service: set_climate - variables: - current_temp: float - target_temp: float - temp_step: int - total_steps: int - temp_offset: int - climate_icon: string - embedded_climate: bool - entity: string - then: - - lambda: |- - if (current_page->state == "climate") detailed_entity->publish_state(entity); - - - script.execute: - id: set_climate - current_temp: !lambda "return current_temp;" - target_temp: !lambda "return target_temp;" - temp_step: !lambda "return temp_step;" - total_steps: !lambda "return total_steps;" - temp_offset: !lambda "return temp_offset;" - climate_icon: !lambda "return climate_icon;" - embedded_climate: !lambda "return embedded_climate;" - - #### Service to set the buttons #### - - service: set_button - variables: - page: string - id: string - state: bool - icon: string - icon_color: int[] - icon_font: int - bri: string - label: string - then: - - lambda: |- - static const char *const TAG = "service.set_button"; - if (page == current_page->state) { - std::string btnicon = id.c_str() + std::string("icon"); - std::string btntext = id.c_str() + std::string("text"); - std::string btnbri = id.c_str() + std::string("bri"); - uint8_t bg_pic = state ? 47 : 46; - uint16_t txt_color = state ? 10597 : 65535; - disp1->send_command_printf("%spic.picc=%u", id.c_str(), bg_pic); - disp1->send_command_printf("%sbri.picc=%u", id.c_str(), bg_pic); - disp1->send_command_printf("%stext.picc=%u", id.c_str(), bg_pic); - disp1->send_command_printf("%sicon.picc=%u", id.c_str(), bg_pic); - disp1->send_command_printf("%sicon.font=%" PRIu32, id.c_str(), icon_font); - disp1->set_component_foreground_color(btnbri.c_str(), txt_color); - disp1->set_component_foreground_color(btntext.c_str(), txt_color); - set_component_color->execute(btnicon.c_str(), icon_color); - disp1->set_component_text_printf(btnicon.c_str(), "%s", icon.c_str()); - display_wrapped_text->execute(btntext.c_str(), label.c_str(), 10); - if (strcmp(bri.c_str(), "0") != 0) - disp1->set_component_text_printf(btnbri.c_str(), "%s", bri.c_str()); - else - disp1->set_component_text_printf(btnbri.c_str(), " "); - } else { - ESP_LOGW(TAG, "Skipping button `%s.%s` as page has changed to %s.", page.c_str(), id.c_str(), current_page->state.c_str()); - } - - ##### SERVICE TO WAKE UP THE DISPLAY ##### - - service: wake_up - variables: - reset_timer: bool - then: - - lambda: |- - if (current_page->state == "screensaver") disp1->goto_page(wakeup_page_name->state.c_str()); - if (reset_timer) - timer_reset_all->execute(wakeup_page_name->state.c_str()); - else { - timer_sleep->execute(wakeup_page_name->state.c_str(), int(timeout_sleep->state)); - timer_dim->execute(wakeup_page_name->state.c_str(), int(timeout_dim->state)); - } - - #### Service to set the entities #### - - service: set_entity - variables: - ent_id: string - ent_icon: string - ent_label: string - ent_value: string - ent_value_xcen: string - then: - - lambda: |- - std::string enticon = ent_id.c_str() + std::string("_pic"); - std::string entlabel = ent_id.c_str() + std::string("_label"); - std::string entxcen = ent_id.c_str() + std::string(".xcen=") + ent_value_xcen.c_str(); - disp1->set_component_text_printf(enticon.c_str(), "%s", ent_icon.c_str()); - if (strcmp(ent_icon.c_str(), "0") != 0) disp1->set_component_text_printf(enticon.c_str(), "%s", ent_icon.c_str()); - disp1->set_component_text_printf(entlabel.c_str(), "%s", ent_label.c_str()); - disp1->set_component_text_printf(ent_id.c_str(), "%s", ent_value.c_str()); - if (strcmp(ent_value_xcen.c_str(), "0") != 0) disp1->send_command_printf("%s", entxcen.c_str()); - - #### Service to populate the page Home ##### - - service: page_home - variables: - date_color: int - time_format: string - time_color: int - chip_font_size: int - notification_icon: string - notification_icon_color_normal: int[] - notification_icon_color_unread: int[] - qrcode: bool - qrcode_icon: string - qrcode_icon_color: int[] - entities_pages: bool - entities_pages_icon: string - entities_pages_icon_color: int[] - then: - - lambda: |- - static const char *const TAG = "service.page_home"; - - // Localization - ESP_LOGV(TAG, "Load localization"); - id(mui_time_format) = time_format; - - // Date/Time colors - ESP_LOGV(TAG, "Load date/time colors"); - disp1->set_component_font_color("home.date", date_color); - disp1->set_component_font_color("home.time", time_color); - id(home_date_color) = date_color; - id(home_time_color) = time_color; - - // Chips icon size - ESP_LOGV(TAG, "Chips size"); - for (int i = 1; i <= 10; ++i) { - disp1->send_command_printf("home.icon_top_%02d.font=%" PRIu32, i, chip_font_size); - } - disp1->send_command_printf("home.wifi_icon.font=%" PRIu32, chip_font_size); - id(home_chip_font_size) = chip_font_size; - - // Notification button - ESP_LOGV(TAG, "Set Notification button"); - disp1->send_command_printf("is_notification=%i", (notification_text->state.empty() and notification_label->state.empty()) ? 0 : 1); - disp1->set_component_text_printf("home.bt_notific", "%s", notification_icon.c_str()); - set_component_color->execute("home.bt_notific", notification_unread->state ? notification_icon_color_unread : notification_icon_color_normal); - id(home_notify_icon_color_normal) = notification_icon_color_normal; - id(home_notify_icon_color_unread) = notification_icon_color_unread; - - // QRCode button - ESP_LOGV(TAG, "Set QRCode button"); - disp1->send_command_printf("is_qrcode=%i", qrcode ? 1 : 0); - disp1->set_component_text_printf("home.bt_qrcode", "%s", qrcode_icon.c_str()); - set_component_color->execute("home.bt_qrcode", qrcode_icon_color); - - // Entities pages button - ESP_LOGV(TAG, "Set Entities button"); - disp1->send_command_printf("is_entities=%i", entities_pages ? 1 : 0); - disp1->set_component_text_printf("home.bt_entities", "%s", entities_pages_icon.c_str()); - //set_component_color->execute("home.bt_entities", entities_pages_icon_color); - set_component_color->execute("home.bt_entities", entities_pages_icon_color); - - #### Service to populate the page Settings ##### - - service: page_settings - variables: - reboot: string - #sleep_mode: string - brightness: string - bright: string - dim: string - then: - - lambda: |- - if (not reboot.empty()) disp1->set_component_text_printf("settings.lbl_reboot", " %s", reboot.c_str()); - disp1->set_component_text_printf("settings.lbl_brightness", " %s", brightness.c_str()); - display_wrapped_text->execute("settings.lbl_bright", bright.c_str(), id(display_mode) == 2 ? 25 : 10); - display_wrapped_text->execute("settings.lbl_dim", dim.c_str(), id(display_mode) == 2 ? 25 : 10); - - #### Service to populate the media player page ##### - - service: media_player - variables: - entity: string - state: string - is_volume_muted: bool - friendly_name: string - volume_level: int - media_title: string - media_artist: string - media_duration: float - media_position: float - media_position_delta: float - supported_features: int - then: - - lambda: |- - if (current_page->state == "media_player") - { + #### Service to populate the alarm settings page ##### + - service: alarm_settings + variables: + page_title: string + state: string + supported_features: int + code_format: string + code_arm_required: bool + entity: string + mui_alarm: string[] #std::vector #std::map + then: + - lambda: |- + // Is page Alarm visible? + if (current_page->state == "alarm") // To do: This page constructor should be moved to Blueprint + { // Update alarm page detailed_entity->publish_state(entity); - disp1->set_component_text_printf("page_label", "%s", friendly_name.c_str()); - display_wrapped_text->execute("track", media_title.c_str(), id(display_mode) == 2 ? 16 : 27); - display_wrapped_text->execute("artist", media_artist.c_str(), id(display_mode) == 2 ? 26 : 40); - // on/off button - if (supported_features & 128 and state == "off") //TURN_ON - { - disp1->set_component_foreground_color("bt_on_off", 65535); - disp1->show_component("bt_on_off"); - } - else if (supported_features & 256 and state != "off") //TURN_OFF - { - disp1->set_component_foreground_color("bt_on_off", 10597); - disp1->show_component("bt_on_off"); - } - else disp1->hide_component("bt_on_off"); + // Alarm page - Header + update_alarm_icon->execute("icon_state", state.c_str()); + if (page_title.find("\\r") != std::string::npos) { + page_title = page_title.replace(page_title.find("\\r"), 2, " "); + } + disp1->set_component_text_printf("page_label", "%s", page_title.c_str()); + disp1->set_component_text_printf("code_format", "%s", code_format.c_str()); + if (code_arm_required) disp1->set_component_text_printf("code_arm_req", "1"); else disp1->set_component_text_printf("code_arm_req", "0"); - // play/pause button - if ((supported_features & 512 or supported_features & 16384) and state != "playing" and state != "off") //PLAY_MEDIA+PLAY - { - disp1->set_component_text_printf("bt_play_pause", "%s", "\uE409"); // mdi:play - disp1->show_component("bt_play_pause"); - } - else if (supported_features & 1 and state == "playing" ) //PAUSE - { - disp1->set_component_text_printf("bt_play_pause", "%s", "\uE3E3"); // mdi:pause - disp1->show_component("bt_play_pause"); - } - else disp1->hide_component("bt_play_pause"); + // Alarm page - Button's text + display_wrapped_text->execute("bt_home_text", mui_alarm[0].c_str(), 10); + display_wrapped_text->execute("bt_away_text", mui_alarm[1].c_str(), 10); + display_wrapped_text->execute("bt_night_text", mui_alarm[2].c_str(), 10); + display_wrapped_text->execute("bt_vacat_text", mui_alarm[3].c_str(), 10); + display_wrapped_text->execute("bt_bypass_text", mui_alarm[4].c_str(), 10); + display_wrapped_text->execute("bt_disarm_text", mui_alarm[5].c_str(), 10); - // bt_prev button - PREVIOUS_TRACK - if (supported_features & 16 and state != "off") disp1->show_component("bt_prev"); else disp1->hide_component("bt_prev"); - // bt_next button - NEXT_TRACK - if (supported_features & 32 and state != "off") disp1->show_component("bt_next"); else disp1->hide_component("bt_next"); + // Alarm page - Buttons + if (supported_features & 1 or state == "armed_home") // Alarm - Button - Home + { + disp1->send_command_printf("bt_home_pic.pic=%i", (state == "armed_home") ? 43 : 42); + disp1->set_component_background_color("bt_home_text", (state == "armed_home") ? 19818 : 52857); + disp1->set_component_background_color("bt_home_icon", (state == "armed_home") ? 19818 : 52857); + disp1->set_component_font_color("bt_home_text", (state == "armed_home") ? 65535 : 0); + disp1->set_component_font_color("bt_home_icon", (state == "armed_home") ? 65535 : 0); + if (state == "armed_home") disp1->hide_component("bt_home"); else disp1->show_component("bt_home"); + } + if (supported_features & 2 or state == "armed_away") // Alarm - Button - Away + { + disp1->send_command_printf("bt_away_pic.pic=%i", (state == "armed_away") ? 43 : 42); + disp1->set_component_background_color("bt_away_text", (state == "armed_away") ? 19818 : 52857); + disp1->set_component_background_color("bt_away_icon", (state == "armed_away") ? 19818 : 52857); + disp1->set_component_font_color("bt_away_text", (state == "armed_away") ? 65535 : 0); + disp1->set_component_font_color("bt_away_icon", (state == "armed_away") ? 65535 : 0); + if (state == "armed_away") disp1->hide_component("bt_away"); else disp1->show_component("bt_away"); + } + if (supported_features & 4 or state == "armed_night") // Alarm - Button - Night + { + disp1->send_command_printf("bt_night_pic.pic=%i", (state == "armed_night") ? 43 : 42); + disp1->set_component_background_color("bt_night_text", (state == "armed_night") ? 19818 : 52857); + disp1->set_component_background_color("bt_night_icon", (state == "armed_night") ? 19818 : 52857); + disp1->set_component_font_color("bt_night_text", (state == "armed_night") ? 65535 : 0); + disp1->set_component_font_color("bt_night_icon", (state == "armed_night") ? 65535 : 0); + if (state == "armed_night") disp1->hide_component("bt_night"); else disp1->show_component("bt_night"); + } + if (supported_features & 32 or state == "armed_vacation") // Alarm - Button - Vacation + { + disp1->send_command_printf("bt_vacat_pic.pic=%i", (state == "armed_vacation") ? 43 : 42); + disp1->set_component_background_color("bt_vacat_text", (state == "armed_vacation") ? 19818 : 52857); + disp1->set_component_background_color("bt_vacat_icon", (state == "armed_vacation") ? 19818 : 52857); + disp1->set_component_font_color("bt_vacat_text", (state == "armed_vacation") ? 65535 : 0); + disp1->set_component_font_color("bt_vacat_icon", (state == "armed_vacation") ? 65535 : 0); + if (state == "armed_vacation") disp1->hide_component("bt_vacat"); else disp1->show_component("bt_vacat"); + } + if (supported_features & 16 or state == "armed_bypass") // Alarm - Button - Custom bypass + { + disp1->send_command_printf("bt_bypass_pic.pic=%i", (state == "armed_bypass") ? 43 : 42); + disp1->set_component_background_color("bt_bypass_text", (state == "armed_bypass") ? 19818 : 52857); + disp1->set_component_background_color("bt_bypass_icon", (state == "armed_bypass") ? 19818 : 52857); + disp1->set_component_font_color("bt_bypass_text", (state == "armed_bypass") ? 65535 : 0); + disp1->set_component_font_color("bt_bypass_icon", (state == "armed_bypass") ? 65535 : 0); + if (state == "armed_bypass") disp1->hide_component("bt_bypass"); else disp1->show_component("bt_bypass"); + } + if ( true ) // Alarm - Button - Disarm + { + disp1->send_command_printf("bt_disarm_pic.pic=%i", (state == "disarmed") ? 43 : 42); + disp1->set_component_background_color("bt_disarm_text", (state == "disarmed") ? 19818 : 52857); + disp1->set_component_background_color("bt_disarm_icon", (state == "disarmed") ? 19818 : 52857); + disp1->set_component_font_color("bt_disarm_text", (state == "disarmed") ? 65535 : 0); + disp1->set_component_font_color("bt_disarm_icon", (state == "disarmed") ? 65535 : 0); + if (state == "disarmed") disp1->hide_component("bt_disarm"); else disp1->show_component("bt_disarm"); + } + } - // Stop button - STOP - //if (supported_features & 4096 and (state == "playing" or state == "paused")) disp1->show_component("bt_stop"); else disp1->hide_component("bt_stop"); + ##### Service for transferring global settings from the blueprint to ESPHome ##### + - service: global_settings + variables: + blueprint_version: string + relay1_local_control: bool + relay1_icon: string + relay1_icon_color: int + relay1_fallback: bool + relay2_local_control: bool + relay2_icon: string + relay2_icon_color: int + relay2_fallback: bool + embedded_climate: bool + embedded_climate_friendly_name: string + embedded_indoor_temperature: bool + temperature_unit_is_fahrenheit: bool + mui_please_confirm: string + then: + - lambda: |- + static const char *const TAG = "service.global_settings"; + // Blueprint version + ESP_LOGV(TAG, "Check Blueprint version"); + id(version_blueprint) = blueprint_version; + check_versions->execute(); - // mute/unmute button - VOLUME_MUTE - disp1->set_component_value("is_muted", is_volume_muted ? 1 : 0); - if (supported_features & 8 and is_volume_muted) // unmute - { - disp1->set_component_text_printf("bt_mute", "%s", "\uEE07"); // mdi:volume-variant-off - disp1->show_component("bt_mute"); - } - else if (supported_features & 8) // mute - { - disp1->set_component_text_printf("bt_mute", "%s", "\uE57E"); // mdi:volume-low - disp1->show_component("bt_mute"); - } - else disp1->hide_component("bt_mute"); + // Relays + ESP_LOGV(TAG, "Setup relays"); + relay1_local->publish_state(relay1_local_control); + relay2_local->publish_state(relay2_local_control); + id(relay_1_fallback) = relay1_fallback; + id(relay_2_fallback) = relay2_fallback; + disp1->set_component_font_color("home.icon_top_01", relay1_icon_color); + disp1->set_component_font_color("home.icon_top_02", relay2_icon_color); + disp1->set_component_text_printf("home.icon_top_01", "%s", relay1_icon.c_str()); + disp1->set_component_text_printf("home.icon_top_02", "%s", relay2_icon.c_str()); + id(home_relay1_icon) = relay1_icon.c_str(); + id(home_relay2_icon) = relay2_icon.c_str(); + id(home_relay1_icon_color) = relay1_icon_color; + id(home_relay2_icon_color) = relay2_icon_color; - // VOLUME_SET - if (supported_features & 4) - { - if (volume_level != id(last_volume_level)) - { - id(last_volume_level) = volume_level; - disp1->set_component_text_printf("vol_text", "%" PRIu32 "%%", volume_level); - disp1->set_component_value("vol_slider", volume_level); - } - disp1->show_component("vol_slider"); - disp1->show_component("bt_vol_down"); - disp1->show_component("bt_vol_up"); - disp1->show_component("vol_text"); - } - else - { - disp1->hide_component("vol_slider"); - disp1->hide_component("bt_vol_down"); - disp1->hide_component("bt_vol_up"); - disp1->hide_component("vol_text"); - } + // Embedded thermostat + ESP_LOGV(TAG, "Load embedded thermostat"); + id(is_embedded_thermostat) = embedded_climate; + addon_climate_set_climate_friendly_name->execute(embedded_climate_friendly_name.c_str()); - if (media_duration > 0) - { - if (media_duration != id(last_media_duration) or media_position != id(last_media_position)) - { - id(last_media_duration) = media_duration; - id(last_media_position) = media_position; - disp1->set_component_value("prg_current", int(round(min(media_position + media_position_delta, media_duration)))); - } - disp1->set_component_value("prg_total", int(round(media_duration))); - disp1->send_command_printf("prg_timer.en=%i", (state == "playing") ? 1 : 0); - disp1->show_component("time_current"); - disp1->show_component("time_total"); - disp1->show_component("time_progress"); - } - else - { - disp1->send_command_printf("prg_timer.en=0"); - disp1->hide_component("time_current"); - disp1->hide_component("time_total"); - disp1->hide_component("time_progress"); - } - } + // Indoor temperature + ESP_LOGV(TAG, "Set indoor temperature"); + id(embedded_indoor_temp) = embedded_indoor_temperature; + id(temp_unit_fahrenheit) = temperature_unit_is_fahrenheit; + display_embedded_temp->execute(); + + // Confirm page + ESP_LOGV(TAG, "Setup confirm page"); + display_wrapped_text->execute("confirm.title", mui_please_confirm.c_str(), 15); + + // Update home page + ESP_LOGV(TAG, "Update home page"); + page_home->execute(); + + ESP_LOGV(TAG, "Current page: %s", current_page->state.c_str()); + + - if: + condition: + - text_sensor.state: # Is boot page visible? + id: current_page + state: boot + then: + - lambda: |- + ESP_LOGV("service.global_settings", "Boot page is visible"); + disp1->set_component_text_printf("boot.bluep_version", "%s", blueprint_version.c_str()); + - wait_until: + condition: + - not: + - text_sensor.state: # Is boot page visible? + id: current_page + state: 'boot' + timeout: 2s + - if: + condition: + - text_sensor.state: # Avoid this being called twice by multiple boot triggers + id: current_page + state: 'boot' + then: + - lambda: |- + ESP_LOGV("service.global_settings", "Boot page still visible"); + - if: + condition: + switch.is_on: notification_sound + then: + - rtttl.play: + rtttl: 'two short:d=4,o=5,b=100:16e6,16e6' + - lambda: |- + ESP_LOGD("service.global_settings", "Jump to wake-up page: %s", wakeup_page_name->state.c_str()); + disp1->goto_page(wakeup_page_name->state.c_str()); + timer_reset_all->execute(wakeup_page_name->state.c_str()); + + ##### Service to show a notification-message on the screen ##### + - service: notification_show + variables: + label: string + message: string + then: + - lambda: |- + ESP_LOGV("service.notification_show", "Starting"); + + disp1->send_command_printf("is_notification=1"); + disp1->goto_page("notification"); + disp1->set_component_text_printf("notification.notifi_label", "%s", label.c_str()); + + display_wrapped_text->execute("notification.notifi_text01", message.c_str(), id(display_mode) == 2 ? 23 : 32); + + notification_label->publish_state(label.c_str()); + notification_text->publish_state(message.c_str()); + timer_reset_all->execute(current_page->state.c_str()); + notification_unread->turn_on(); + if (notification_sound->state) buzzer->play("two short:d=4,o=5,b=100:16e6,16e6"); + + ##### Service to clear the notification ##### + - service: notification_clear + then: + - logger.log: "Service: notification_clear" + - script.execute: notification_clear + + ##### Service to open information for settings-page(s) + - service: open_entity_settings_page + variables: + page: string + page_label: string + page_icon: string + page_icon_color: int[] + entity: string + back_page: string + then: + - lambda: |- + detailed_entity->publish_state(entity); + if (page == "alarm_control_panel") page = "alarm"; + std::string cmd_page = std::string("page ") + page.c_str(); + disp1->send_command_printf(cmd_page.c_str()); + if (page_label.find("\\r") != std::string::npos) { + page_label = page_label.replace(page_label.find("\\r"), 2, " "); + } + disp1->set_component_text_printf("page_label", "%s", page_label.c_str()); + disp1->set_component_text_printf("back_page", "%s", back_page.c_str()); + if (page == "climate") + { + if (entity == "embedded_climate") addon_climate_set_climate_friendly_name->execute(page_label.c_str()); + disp1->set_component_value("embedded", (entity == "embedded_climate") ? 1 : 0); + } + else + { + if ((page_icon != std::string()) and (page_icon != "")) + disp1->set_component_text_printf("icon_state", "%s", page_icon.c_str()); + set_component_color->execute("icon_state", page_icon_color); + } + + # Service to show a QR code on the display (ex. for WiFi password) + - service: qrcode + variables: + title: string + qrcode: string + show: bool + then: + - lambda: |- + disp1->set_component_text_printf("qrcode.qrcode_label", "%s", title.c_str()); + disp1->set_component_text_printf("qrcode.qrcode_value", "%s", qrcode.c_str()); + if (show) disp1->goto_page("qrcode"); + + #### Service to set climate state #### + - service: set_climate + variables: + current_temp: float + target_temp: float + temp_step: int + total_steps: int + temp_offset: int + climate_icon: string + embedded_climate: bool + entity: string + then: + - lambda: |- + if (current_page->state == "climate") detailed_entity->publish_state(entity); + + - script.execute: + id: set_climate + current_temp: !lambda "return current_temp;" + target_temp: !lambda "return target_temp;" + temp_step: !lambda "return temp_step;" + total_steps: !lambda "return total_steps;" + temp_offset: !lambda "return temp_offset;" + climate_icon: !lambda "return climate_icon;" + embedded_climate: !lambda "return embedded_climate;" + + #### Service to set the buttons #### + - service: set_button + variables: + page: string + id: string + state: bool + icon: string + icon_color: int[] + icon_font: int + bri: string + label: string + then: + - lambda: |- + static const char *const TAG = "service.set_button"; + if (page == current_page->state) { + std::string btnicon = id.c_str() + std::string("icon"); + std::string btntext = id.c_str() + std::string("text"); + std::string btnbri = id.c_str() + std::string("bri"); + uint8_t bg_pic = state ? 47 : 46; + uint16_t txt_color = state ? 10597 : 65535; + disp1->send_command_printf("%spic.picc=%u", id.c_str(), bg_pic); + disp1->send_command_printf("%sbri.picc=%u", id.c_str(), bg_pic); + disp1->send_command_printf("%stext.picc=%u", id.c_str(), bg_pic); + disp1->send_command_printf("%sicon.picc=%u", id.c_str(), bg_pic); + disp1->send_command_printf("%sicon.font=%" PRIu32, id.c_str(), icon_font); + disp1->set_component_foreground_color(btnbri.c_str(), txt_color); + disp1->set_component_foreground_color(btntext.c_str(), txt_color); + set_component_color->execute(btnicon.c_str(), icon_color); + disp1->set_component_text_printf(btnicon.c_str(), "%s", icon.c_str()); + display_wrapped_text->execute(btntext.c_str(), label.c_str(), 10); + if (strcmp(bri.c_str(), "0") != 0) + disp1->set_component_text_printf(btnbri.c_str(), "%s", bri.c_str()); + else + disp1->set_component_text_printf(btnbri.c_str(), " "); + } else { + ESP_LOGW(TAG, "Skipping button `%s.%s` as page has changed to %s.", page.c_str(), id.c_str(), current_page->state.c_str()); + } + + ##### SERVICE TO WAKE UP THE DISPLAY ##### + - service: wake_up + variables: + reset_timer: bool + then: + - lambda: |- + if (current_page->state == "screensaver") disp1->goto_page(wakeup_page_name->state.c_str()); + if (reset_timer) + timer_reset_all->execute(wakeup_page_name->state.c_str()); + else { + timer_sleep->execute(wakeup_page_name->state.c_str(), int(timeout_sleep->state)); + timer_dim->execute(wakeup_page_name->state.c_str(), int(timeout_dim->state)); + } + + #### Service to set the entities #### + - service: set_entity + variables: + ent_id: string + ent_icon: string + ent_label: string + ent_value: string + ent_value_xcen: string + then: + - lambda: |- + std::string enticon = ent_id.c_str() + std::string("_pic"); + std::string entlabel = ent_id.c_str() + std::string("_label"); + std::string entxcen = ent_id.c_str() + std::string(".xcen=") + ent_value_xcen.c_str(); + disp1->set_component_text_printf(enticon.c_str(), "%s", ent_icon.c_str()); + if (strcmp(ent_icon.c_str(), "0") != 0) disp1->set_component_text_printf(enticon.c_str(), "%s", ent_icon.c_str()); + disp1->set_component_text_printf(entlabel.c_str(), "%s", ent_label.c_str()); + disp1->set_component_text_printf(ent_id.c_str(), "%s", ent_value.c_str()); + if (strcmp(ent_value_xcen.c_str(), "0") != 0) disp1->send_command_printf("%s", entxcen.c_str()); + + #### Service to populate the page Home ##### + - service: page_home + variables: + date_color: int + time_format: string + time_color: int + chip_font_size: int + notification_icon: string + notification_icon_color_normal: int[] + notification_icon_color_unread: int[] + qrcode: bool + qrcode_icon: string + qrcode_icon_color: int[] + entities_pages: bool + entities_pages_icon: string + entities_pages_icon_color: int[] + then: + - lambda: |- + static const char *const TAG = "service.page_home"; + + // Localization + ESP_LOGV(TAG, "Load localization"); + id(mui_time_format) = time_format; + + // Date/Time colors + ESP_LOGV(TAG, "Load date/time colors"); + disp1->set_component_font_color("home.date", date_color); + disp1->set_component_font_color("home.time", time_color); + id(home_date_color) = date_color; + id(home_time_color) = time_color; + + // Chips icon size + ESP_LOGV(TAG, "Chips size"); + for (int i = 1; i <= 10; ++i) { + disp1->send_command_printf("home.icon_top_%02d.font=%" PRIu32, i, chip_font_size); + } + disp1->send_command_printf("home.wifi_icon.font=%" PRIu32, chip_font_size); + id(home_chip_font_size) = chip_font_size; + + // Notification button + ESP_LOGV(TAG, "Set Notification button"); + disp1->send_command_printf("is_notification=%i", (notification_text->state.empty() and notification_label->state.empty()) ? 0 : 1); + disp1->set_component_text_printf("home.bt_notific", "%s", notification_icon.c_str()); + set_component_color->execute("home.bt_notific", notification_unread->state ? notification_icon_color_unread : notification_icon_color_normal); + id(home_notify_icon_color_normal) = notification_icon_color_normal; + id(home_notify_icon_color_unread) = notification_icon_color_unread; + + // QRCode button + ESP_LOGV(TAG, "Set QRCode button"); + disp1->send_command_printf("is_qrcode=%i", qrcode ? 1 : 0); + disp1->set_component_text_printf("home.bt_qrcode", "%s", qrcode_icon.c_str()); + set_component_color->execute("home.bt_qrcode", qrcode_icon_color); + + // Entities pages button + ESP_LOGV(TAG, "Set Entities button"); + disp1->send_command_printf("is_entities=%i", entities_pages ? 1 : 0); + disp1->set_component_text_printf("home.bt_entities", "%s", entities_pages_icon.c_str()); + //set_component_color->execute("home.bt_entities", entities_pages_icon_color); + set_component_color->execute("home.bt_entities", entities_pages_icon_color); + + #### Service to populate the page Settings ##### + - service: page_settings + variables: + reboot: string + #sleep_mode: string + brightness: string + bright: string + dim: string + then: + - lambda: |- + if (not reboot.empty()) disp1->set_component_text_printf("settings.lbl_reboot", " %s", reboot.c_str()); + disp1->set_component_text_printf("settings.lbl_brightness", " %s", brightness.c_str()); + display_wrapped_text->execute("settings.lbl_bright", bright.c_str(), id(display_mode) == 2 ? 25 : 10); + display_wrapped_text->execute("settings.lbl_dim", dim.c_str(), id(display_mode) == 2 ? 25 : 10); + + #### Service to populate the media player page ##### + - service: media_player + variables: + entity: string + state: string + is_volume_muted: bool + friendly_name: string + volume_level: int + media_title: string + media_artist: string + media_duration: float + media_position: float + media_position_delta: float + supported_features: int + then: + - lambda: |- + if (current_page->state == "media_player") + { + detailed_entity->publish_state(entity); + disp1->set_component_text_printf("page_label", "%s", friendly_name.c_str()); + display_wrapped_text->execute("track", media_title.c_str(), id(display_mode) == 2 ? 16 : 27); + display_wrapped_text->execute("artist", media_artist.c_str(), id(display_mode) == 2 ? 26 : 40); + + // on/off button + if (supported_features & 128 and state == "off") //TURN_ON + { + disp1->set_component_foreground_color("bt_on_off", 65535); + disp1->show_component("bt_on_off"); + } + else if (supported_features & 256 and state != "off") //TURN_OFF + { + disp1->set_component_foreground_color("bt_on_off", 10597); + disp1->show_component("bt_on_off"); + } + else disp1->hide_component("bt_on_off"); + + // play/pause button + if ((supported_features & 512 or supported_features & 16384) and state != "playing" and state != "off") //PLAY_MEDIA+PLAY + { + disp1->set_component_text_printf("bt_play_pause", "%s", "\uE409"); // mdi:play + disp1->show_component("bt_play_pause"); + } + else if (supported_features & 1 and state == "playing" ) //PAUSE + { + disp1->set_component_text_printf("bt_play_pause", "%s", "\uE3E3"); // mdi:pause + disp1->show_component("bt_play_pause"); + } + else disp1->hide_component("bt_play_pause"); + + // bt_prev button - PREVIOUS_TRACK + if (supported_features & 16 and state != "off") disp1->show_component("bt_prev"); else disp1->hide_component("bt_prev"); + // bt_next button - NEXT_TRACK + if (supported_features & 32 and state != "off") disp1->show_component("bt_next"); else disp1->hide_component("bt_next"); + + // Stop button - STOP + //if (supported_features & 4096 and (state == "playing" or state == "paused")) disp1->show_component("bt_stop"); else disp1->hide_component("bt_stop"); + + // mute/unmute button - VOLUME_MUTE + disp1->set_component_value("is_muted", is_volume_muted ? 1 : 0); + if (supported_features & 8 and is_volume_muted) // unmute + { + disp1->set_component_text_printf("bt_mute", "%s", "\uEE07"); // mdi:volume-variant-off + disp1->show_component("bt_mute"); + } + else if (supported_features & 8) // mute + { + disp1->set_component_text_printf("bt_mute", "%s", "\uE57E"); // mdi:volume-low + disp1->show_component("bt_mute"); + } + else disp1->hide_component("bt_mute"); + + // VOLUME_SET + if (supported_features & 4) + { + if (volume_level != id(last_volume_level)) + { + id(last_volume_level) = volume_level; + disp1->set_component_text_printf("vol_text", "%" PRIu32 "%%", volume_level); + disp1->set_component_value("vol_slider", volume_level); + } + disp1->show_component("vol_slider"); + disp1->show_component("bt_vol_down"); + disp1->show_component("bt_vol_up"); + disp1->show_component("vol_text"); + } + else + { + disp1->hide_component("vol_slider"); + disp1->hide_component("bt_vol_down"); + disp1->hide_component("bt_vol_up"); + disp1->hide_component("vol_text"); + } + + if (media_duration > 0) + { + if (media_duration != id(last_media_duration) or media_position != id(last_media_position)) + { + id(last_media_duration) = media_duration; + id(last_media_position) = media_position; + disp1->set_component_value("prg_current", int(round(min(media_position + media_position_delta, media_duration)))); + } + disp1->set_component_value("prg_total", int(round(media_duration))); + disp1->send_command_printf("prg_timer.en=%i", (state == "playing") ? 1 : 0); + disp1->show_component("time_current"); + disp1->show_component("time_total"); + disp1->show_component("time_progress"); + } + else + { + disp1->send_command_printf("prg_timer.en=0"); + disp1->hide_component("time_current"); + disp1->hide_component("time_total"); + disp1->hide_component("time_progress"); + } + } ##### START - DISPLAY START CONFIGURATION ##### display: