diff --git a/ReleaseNotes.md b/ReleaseNotes.md
new file mode 100644
index 0000000..cd14e2b
--- /dev/null
+++ b/ReleaseNotes.md
@@ -0,0 +1,90 @@
+# (DRAFT) v4.1 - Easier TFT transfer
+
+## Support this project
+
+### As always, we would like to thank everyone who donated to this project and remind you that every donation helps to support this project - so if you haven't made a donation yet, now would be a good time ;)
+
+[](https://www.paypal.com/donate/?hosted_button_id=S974SWQMB8PB2)
+
+
+## General
+The focus this time was on making easier to transfer the TFT files.
+
+As this project grows with features, it becomes more hungry of resources from all sides (ESPHome, your Home Assistant server and even the Nextion display) and with that the chances of something going wrong when updating increased.
+
+So at this release we concentrated on cleaning up de code everywhere and shave some unnecessary elements, making the system easier to install and opening some space for future features.
+
+
+## Updating
+Since in this update lots of input to the blueprint changed, we highly recommend you review your settings and make sure all fields have the correct selection. We did our best to support your legacy settings and avoid breaking your system, but please double check your settings if you see something not working as expected.
+
+### Files that need to be reloaded:
+1. nspanel_eu.tft, nspanel_us.tft or nspanel_us_land.tft - v4.1
+2. nspanel_esphome.yaml - v4.1
+3. nspanel_blueprint.yaml - v4.1
+
+####
+
+### Instructions
+ _You can find the update procedures following here:_
+- [(EN) How To - All important thing you should know - Update](https://github.com/Blackymas/NSPanel_HA_Blueprint/wiki/(EN)-HowTo---All-important-thing-you-should-know#2-update-blueprint)
+- [(DE) How To - Alle wichtigen Dinge die man wissen sollte - Update](https://github.com/Blackymas/NSPanel_HA_Blueprint/wiki/(DE)-HowTo---Alle-wichtigen-Dinge-die-man-wissen-sollte#2-update-blueprint)
+
+
+## Breaking changes
+1. The following components are now deprecated:
+ - Buttons:
+ - Exit reparse (`button.xxxxx_exit_reparse`) - It shouldn't be necessary with the new TFT upload engine
+ - Services:
+ - Play rtttl (`esphome.xxxxx_play_rtttl`)
+ - Sensors:
+ - API uptime
+ - Device uptime
+ - RSSI
+ - ESPhome Version
+ - IP
+ - SSID
+ - BSSID
+
+ You can still add these components by adding the file `nspanel_esphome_advanced.yaml` in your ESPHome settings as in the example bellow, but please have in mind that these are not used by the blueprint and will be using some memory of your ESPHome.
+```yaml
+...
+packages:
+ remote_package:
+ url: https://github.com/Blackymas/NSPanel_HA_Blueprint
+ ref: main
+ files:
+ - nspanel_esphome.yaml # Core package
+ - nspanel_esphome_advanced.yaml # activate advanced (legacy) elements - can be useful for troubleshooting
+...
+```
+2.
+
+## Overview of all changes
+1. New Upload TFT engine
+2. Smaller TFT file size
+
+
+## Details of all changes
+
+### 1. New Upload TFT engine
+We rebuilt the Upload TFT engine and now it will be using less resources from ESPHome during the transfer and, in addition, will provide more logs for troubleshooting.
+
+The original engine from Nextion component still as a fallback in case the new engine fails, but it might be removed in a future version.
+
+### 2. Smaller TFT file size
+The TFT files are now 15 to 20% smaller when compared to the previous version. This was achieved by removing some icon font sizes, so you will notice difference (a smaller icon) in the following components:
+| Pages | Components |
+| :--: | :--: |
+| settings | bt_reboot
bt_sleep |
+| cover | cover_open
cover_close
cover_stop |
+| notification
confirm | bt_accept
bt_clear |
+| fan | button_up
button_down
button_on
button_off |
+
+
+## Next topics we are currently working on
+See here: https://github.com/Blackymas/NSPanel_HA_Blueprint/labels/roadmap
+
+## Special thanks to:
+
+## New Contributors
diff --git a/nspanel_blueprint.yaml b/nspanel_blueprint.yaml
index c97ac82..ff4d5e7 100644
--- a/nspanel_blueprint.yaml
+++ b/nspanel_blueprint.yaml
@@ -3628,17 +3628,13 @@ variables:
unavailable: [6339] #'6339'
command:
alarm_settings: 'esphome.{{ nspanel_name }}_alarm_settings'
- #background_color: 'esphome.{{ nspanel_name }}_send_command_background_color'
- #font_color: 'esphome.{{ nspanel_name }}_send_command_font_color'
global_settings: 'esphome.{{ nspanel_name }}_global_settings'
hide: 'esphome.{{ nspanel_name }}_send_command_hide'
media_player: 'esphome.{{ nspanel_name }}_media_player'
notification_clear: 'esphome.{{ nspanel_name }}_notification_clear'
- #notification_show: 'esphome.{{ nspanel_name }}_notification_show'
open_entity_settings_page: 'esphome.{{ nspanel_name }}_open_entity_settings_page'
page_home: 'esphome.{{ nspanel_name }}_page_home'
page_settings: 'esphome.{{ nspanel_name }}_page_settings'
- #play_rtttl: 'esphome.{{ nspanel_name }}_play_rtttl'
printf: 'esphome.{{ nspanel_name }}_send_command_printf'
qrcode: 'esphome.{{ nspanel_name }}_qrcode'
set_button: 'esphome.{{ nspanel_name }}_set_button'
diff --git a/nspanel_esphome.yaml b/nspanel_esphome.yaml
index f4c9219..4b4d830 100644
--- a/nspanel_esphome.yaml
+++ b/nspanel_esphome.yaml
@@ -29,6 +29,14 @@ wifi:
ssid: "${device_name}"
password: ${wifi_password}
+##### WEB SERVER SETUP - Required for json parsing and tft upload #####
+web_server:
+ id: web_server_std
+ port: 80
+ auth:
+ username: admin
+ password: ${wifi_password}
+
##### ESPHOME CONFIGURATION #####
esphome:
name: ${device_name}
@@ -60,15 +68,6 @@ esphome:
esp32:
board: esp32dev
-captive_portal:
-
-web_server:
- id: web_server_std
- port: 80
- auth:
- username: admin
- password: ${wifi_password}
-
##### OTA PASSWORD #####
ota:
id: ota_std
@@ -112,8 +111,6 @@ time:
id: refresh_datetime
on_time_sync:
then:
- - component.update: api_timestamp
- - component.update: device_timestamp
- logger.log: "System clock synchronized"
- script.execute:
id: refresh_datetime
@@ -139,642 +136,616 @@ button:
- delay: 16ms
- lambda: id(upload_tft).execute("${nextion_update_url}");
- ##### EXIT REPARSE TFT DISPLAY #####
- - name: ${device_name} Exit reparse
- platform: template
- icon: mdi:file-sync
- id: tft_reparse_off
- entity_category: config
- on_press:
- - logger.log: "Button pressed: Exit reparse"
- - uart.write:
- id: tf_uart
- data: "DRAKJHSUYDGBNCJHGJKSHBDN"
- - uart.write:
- id: tf_uart
- data: [0xFF, 0xFF, 0xFF]
-
##### START - API CONFIGURATION #####
api:
id: api_server
reboot_timeout: 0s
-
services:
+ #### 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: |-
+ // set alarm icon on home page
+ id(disp1).send_command_printf("is_alarm=%i", (state == "" or state.empty()) ? 0 : 1);
+ id(update_alarm_icon).execute("home.bt_alarm", state.c_str());
- ##### SERVICE TO UPDATE THE HMI FILE ##############
- - service: upload_tft
- then:
- - logger.log: "Service: upload_tft"
- - binary_sensor.template.publish:
- id: nextion_init
- state: false
- - lambda: 'id(upload_tft).execute("${nextion_update_url}");'
+ // Is page Alarm visible?
+ if (id(current_page).state == "alarm")
+ { // Update alarm page
+ id(entity_id) = entity;
- ##### SERVICE TO UPDATE THE TFT FILE from URL #####
- - service: upload_tft_url
- variables:
- url: string
- then:
- - logger.log: "Service: upload_tft_url"
- - binary_sensor.template.publish:
- id: nextion_init
- state: false
- - lambda: 'id(upload_tft).execute(url.c_str());'
+ // Alarm page - Header
+ id(update_alarm_icon).execute("icon_state", state.c_str());
+ id(disp1).set_component_text_printf("page_label", "%s", page_title.c_str());
+ id(disp1).set_component_text_printf("code_format", "%s", code_format.c_str());
+ if (code_arm_required) id(disp1).set_component_text_printf("code_arm_req", "1"); else id(disp1).set_component_text_printf("code_arm_req", "0");
- ##### Service to send a command "printf" directly to the display #####
- - service: send_command_printf
- variables:
- cmd: string
- then:
- - lambda: 'id(disp1).send_command_printf("%s", cmd.c_str());'
+ // Alarm page - Button's icons
+ id(disp1).set_component_text_printf("bt_home_icon", "\uE689"); //mdi:shield-home
+ id(disp1).set_component_text_printf("bt_away_icon", "\uE99C"); //mdi:shield-lock
+ id(disp1).set_component_text_printf("bt_night_icon", "\uF827"); //mdi:shield-moon
+ id(disp1).set_component_text_printf("bt_vacat_icon", "\uE6BA"); //mdi:shield-airplane
+ id(disp1).set_component_text_printf("bt_bypass_icon", "\uE77F"); //mdi:shield-half-full
+ id(disp1).set_component_text_printf("bt_disarm_icon", "\uE99D"); //mdi:shield-off
- ##### Service to send a command "text_printf" directly to the display #####
- - service: send_command_text_printf
- variables:
- component: string
- message: string
- then:
- - lambda: 'id(disp1).set_component_text_printf(component.c_str(), "%s", message.c_str());'
+ // Alarm page - Button's text
+ id(display_wrapped_text).execute("bt_home_text", mui_alarm[0].c_str(), 10);
+ id(display_wrapped_text).execute("bt_away_text", mui_alarm[1].c_str(), 10);
+ id(display_wrapped_text).execute("bt_night_text", mui_alarm[2].c_str(), 10);
+ id(display_wrapped_text).execute("bt_vacat_text", mui_alarm[3].c_str(), 10);
+ id(display_wrapped_text).execute("bt_bypass_text", mui_alarm[4].c_str(), 10);
+ id(display_wrapped_text).execute("bt_disarm_text", mui_alarm[5].c_str(), 10);
- ##### Service to send a command "component_value (Dualstate Button)" directly to the display #####
- - service: send_command_value
- variables:
- component: string
- message: int
- then:
- - lambda: 'id(disp1).set_component_value(component.c_str(), message);'
+ // Alarm page - Buttons
+ if (supported_features & 1) // Alarm - Button - Home
+ {
+ id(disp1).send_command_printf("bt_home_pic.pic=%i", (state == "armed_home") ? 43 : 42);
+ id(disp1).set_component_background_color("bt_home_text", (state == "armed_home") ? 19818 : 52857);
+ id(disp1).set_component_background_color("bt_home_icon", (state == "armed_home") ? 19818 : 52857);
+ id(disp1).set_component_font_color("bt_home_text", (state == "armed_home") ? 65535 : 0);
+ id(disp1).set_component_font_color("bt_home_icon", (state == "armed_home") ? 65535 : 0);
+ if (state == "armed_home") id(disp1).hide_component("bt_home"); else id(disp1).show_component("bt_home");
+ }
+ if (supported_features & 2) // Alarm - Button - Away
+ {
+ id(disp1).send_command_printf("bt_away_pic.pic=%i", (state == "armed_away") ? 43 : 42);
+ id(disp1).set_component_background_color("bt_away_text", (state == "armed_away") ? 19818 : 52857);
+ id(disp1).set_component_background_color("bt_away_icon", (state == "armed_away") ? 19818 : 52857);
+ id(disp1).set_component_font_color("bt_away_text", (state == "armed_away") ? 65535 : 0);
+ id(disp1).set_component_font_color("bt_away_icon", (state == "armed_away") ? 65535 : 0);
+ if (state == "armed_away") id(disp1).hide_component("bt_away"); else id(disp1).show_component("bt_away");
+ }
+ if (supported_features & 4) // Alarm - Button - Night
+ {
+ id(disp1).send_command_printf("bt_night_pic.pic=%i", (state == "armed_night") ? 43 : 42);
+ id(disp1).set_component_background_color("bt_night_text", (state == "armed_night") ? 19818 : 52857);
+ id(disp1).set_component_background_color("bt_night_icon", (state == "armed_night") ? 19818 : 52857);
+ id(disp1).set_component_font_color("bt_night_text", (state == "armed_night") ? 65535 : 0);
+ id(disp1).set_component_font_color("bt_night_icon", (state == "armed_night") ? 65535 : 0);
+ if (state == "armed_night") id(disp1).hide_component("bt_night"); else id(disp1).show_component("bt_night");
+ }
+ if (supported_features & 32) // Alarm - Button - Vacation
+ {
+ id(disp1).send_command_printf("bt_vacat_pic.pic=%i", (state == "armed_vacation") ? 43 : 42);
+ id(disp1).set_component_background_color("bt_vacat_text", (state == "armed_vacation") ? 19818 : 52857);
+ id(disp1).set_component_background_color("bt_vacat_icon", (state == "armed_vacation") ? 19818 : 52857);
+ id(disp1).set_component_font_color("bt_vacat_text", (state == "armed_vacation") ? 65535 : 0);
+ id(disp1).set_component_font_color("bt_vacat_icon", (state == "armed_vacation") ? 65535 : 0);
+ if (state == "armed_vacation") id(disp1).hide_component("bt_vacat"); else id(disp1).show_component("bt_vacat");
+ }
+ if (supported_features & 16) // Alarm - Button - Custom bypass
+ {
+ id(disp1).send_command_printf("bt_bypass_pic.pic=%i", (state == "armed_bypass") ? 43 : 42);
+ id(disp1).set_component_background_color("bt_bypass_text", (state == "armed_bypass") ? 19818 : 52857);
+ id(disp1).set_component_background_color("bt_bypass_icon", (state == "armed_bypass") ? 19818 : 52857);
+ id(disp1).set_component_font_color("bt_bypass_text", (state == "armed_bypass") ? 65535 : 0);
+ id(disp1).set_component_font_color("bt_bypass_icon", (state == "armed_bypass") ? 65535 : 0);
+ if (state == "armed_bypass") id(disp1).hide_component("bt_bypass"); else id(disp1).show_component("bt_bypass");
+ }
+ if ( true ) // Alarm - Button - Disarm
+ {
+ id(disp1).send_command_printf("bt_disarm_pic.pic=%i", (state == "disarmed") ? 43 : 42);
+ id(disp1).set_component_background_color("bt_disarm_text", (state == "disarmed") ? 19818 : 52857);
+ id(disp1).set_component_background_color("bt_disarm_icon", (state == "disarmed") ? 19818 : 52857);
+ id(disp1).set_component_font_color("bt_disarm_text", (state == "disarmed") ? 65535 : 0);
+ id(disp1).set_component_font_color("bt_disarm_icon", (state == "disarmed") ? 65535 : 0);
+ if (state == "disarmed") id(disp1).hide_component("bt_disarm"); else id(disp1).show_component("bt_disarm");
+ }
+ }
- ##### Service to send a command "hide componente" directly to the display #####
- - service: send_command_hide ### unused ###
- variables:
- component: string
- then:
- - lambda: 'id(disp1).hide_component(component.c_str());'
+ ##### 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
+ date_color: int
+ time_format: string
+ time_color: int
+ embedded_climate: bool
+ embedded_indoor_temperature: bool
+ temperature_unit_is_fahrenheit: bool
+ mui_please_confirm: string
+ then:
+ - lambda: |-
+ // Blueprint version
+ ESP_LOGV("service.global_settings", "Check Blueprint version");
+ id(version_blueprint) = blueprint_version;
+ id(check_versions).execute();
- ##### Service to send a command "show componente" directly to the display #####
- - service: send_command_show ### unused ###
- variables:
- component: string
- then:
- - lambda: 'id(disp1).show_component(component.c_str());'
+ // Relays
+ ESP_LOGV("service.global_settings", "Setup relays");
+ id(relay1_local).publish_state(relay1_local_control);
+ id(relay2_local).publish_state(relay2_local_control);
+ 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;
+ id(relay_1_fallback) = relay1_fallback;
+ id(relay_2_fallback) = relay2_fallback;
- ##### Service to send a command "show ALL componente" directly to the display #####
- - service: send_command_show_all ### unused ###
- then:
- - lambda: id(disp1).show_component("255");
+ // Localization
+ ESP_LOGV("service.global_settings", "Load localization");
+ id(mui_time_format) = time_format;
- ##### Service to send a command "font color" directly to the display #####
- - service: set_component_color
- variables:
- component: string
- foreground: int[]
- background: int[]
- then:
- - lambda: id(set_component_color).execute(component, foreground, background);
+ // Date/Time colors
+ ESP_LOGV("service.global_settings", "Load date/time colors");
+ id(home_date_color) = date_color;
+ id(home_time_color) = time_color;
- ##### Service to show a notification-message on the screen #####
- - service: notification_show
- variables:
- label: string
- text: string
- then:
- - lambda: |-
- ESP_LOGV("service.notification_show", "Starting");
+ // Embedded thermostat
+ ESP_LOGV("service.global_settings", "Load embedded thermostat");
+ id(is_embedded_thermostat) = embedded_climate;
- id(disp1).send_command_printf("is_notification=1");
- id(disp1).goto_page("notification");
- id(disp1).set_component_text_printf("notification.notifi_label", "%s", label.c_str());
+ // Indoor temperature
+ ESP_LOGV("service.global_settings", "Set indoor temperature");
+ id(embedded_indoor_temp) = embedded_indoor_temperature;
+ id(temp_unit_fahrenheit) = temperature_unit_is_fahrenheit;
+ id(display_embedded_temp).execute();
- id(display_wrapped_text).execute("notification.notifi_text01", text.c_str(), id(display_mode) == 2 ? 23 : 32);
+ // Confirm page
+ ESP_LOGV("service.global_settings", "Setup confirm page");
+ id(display_wrapped_text).execute("confirm.title", mui_please_confirm.c_str(), 15);
- id(notification_label).publish_state(label.c_str());
- id(notification_text).publish_state(text.c_str());
- id(timer_reset_all).execute(id(current_page).state.c_str());
- id(notification_unread).turn_on();
- if (id(notification_sound).state) id(buzzer).play("two short:d=4,o=5,b=100:16e6,16e6");
+ // Refresh colors of global components
+ ESP_LOGV("service.global_settings", "Refresh color of global components");
+ id(disp1).set_component_font_color("home.date", id(home_date_color));
+ id(disp1).set_component_font_color("home.time", id(home_time_color));
+ id(disp1).set_component_font_color("home.icon_top_01", id(home_relay1_icon_color));
+ id(disp1).set_component_font_color("home.icon_top_02", id(home_relay2_icon_color));
- ##### Service to clear the notification #####
- - service: notification_clear
- then:
- - logger.log: "Service: notification_clear"
- - ¬ification_clear
- lambda: |-
- id(disp1).send_command_printf("is_notification=0");
- if (id(current_page).state == "home") id(disp1).hide_component("bt_notific");
- id(notification_label).publish_state("");
- id(notification_text).publish_state("");
- id(notification_unread).turn_off();
+ // Update home page
+ ESP_LOGV("service.global_settings", "Update home page");
+ id(update_page_home).execute();
- ##### 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: |-
- id(entity_id) = entity;
- std::string cmd_page = std::string("page ") + page.c_str();
- id(disp1).send_command_printf(cmd_page.c_str());
- id(disp1).set_component_text_printf("page_label", "%s", page_label.c_str());
- id(disp1).set_component_text_printf("back_page", "%s", back_page.c_str());
- if (page == "climate")
- {
- if (entity == "embedded_climate") id(addon_climate_set_climate_friendly_name).execute(page_label.c_str());
- id(disp1).set_component_value("embedded", (entity == "embedded_climate") ? 1 : 0);
- }
- else
- {
- if ((page_icon.c_str() != std::string()) and (page_icon.c_str() != ""))
- id(disp1).set_component_text_printf("icon_state", "%s", page_icon.c_str());
- id(set_component_color).execute("icon_state", page_icon_color, {});
- }
+ ESP_LOGV("service.global_settings", "Current page: %s", id(current_page).state.c_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 show a QR code on the display (ex. for WiFi password)
- - service: qrcode
- variables:
- title: string
- qrcode: string
- show: bool
- then:
- - lambda: |-
- id(disp1).set_component_text_printf("qrcode.qrcode_label", "%s", title.c_str());
- id(disp1).set_component_text_printf("qrcode.qrcode_value", "%s", qrcode.c_str());
- if (show) id(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 (id(current_page).state == "climate") id(entity_id) = 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:
- btn_id: string
- btn_pic: int
- btn_bg: int[]
- btn_icon_font: int[]
- btn_txt_font: int[]
- btn_bri_font: int[]
- btn_icon: string
- btn_label: string
- btn_bri_txt: string
- then:
- - lambda: |-
- std::string btnicon = btn_id.c_str() + std::string("icon");
- std::string btntext = btn_id.c_str() + std::string("text");
- std::string btnbri = btn_id.c_str() + std::string("bri");
- id(disp1).send_command_printf("%spic.pic=%i", btn_id.c_str(), btn_pic);
- id(set_component_color).execute(btnicon.c_str(), btn_icon_font, btn_bg);
- id(set_component_color).execute(btntext.c_str(), btn_txt_font, btn_bg);
- id(set_component_color).execute(btnbri.c_str(), btn_bri_font, btn_bg);
- id(disp1).set_component_text_printf(btnicon.c_str(), "%s", btn_icon.c_str());
- id(display_wrapped_text).execute(btntext.c_str(), btn_label.c_str(), 10);
- if (strcmp(btn_bri_txt.c_str(), "0") != 0)
- id(disp1).set_component_text_printf(btnbri.c_str(), "%s", btn_bri_txt.c_str());
- else
- id(disp1).set_component_text_printf(btnbri.c_str(), " ");
-
- ##### SERVICE TO WAKE UP THE DISPLAY #####
- - service: wake_up
- variables:
- reset_timer: bool
- then:
- - lambda: |-
- if (id(current_page).state == "screensaver") id(disp1).goto_page(id(wakeup_page_name).state.c_str());
- if (reset_timer)
- id(timer_reset_all).execute(id(wakeup_page_name).state.c_str());
- else
- {
- id(timer_sleep).execute(id(wakeup_page_name).state.c_str(), int(id(timeout_sleep).state));
- id(timer_dim).execute(id(wakeup_page_name).state.c_str(), int(id(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();
- id(disp1).set_component_text_printf(enticon.c_str(), "%s", ent_icon.c_str());
- if (strcmp(ent_icon.c_str(), "0") != 0) id(disp1).set_component_text_printf(enticon.c_str(), "%s", ent_icon.c_str());
- id(disp1).set_component_text_printf(entlabel.c_str(), "%s", ent_label.c_str());
- id(disp1).set_component_text_printf(ent_id.c_str(), "%s", ent_value.c_str());
- if (strcmp(ent_value_xcen.c_str(), "0") != 0) id(disp1).send_command_printf("%s", entxcen.c_str());
-
- ##### 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
- date_color: int
- time_format: string
- time_color: int
- embedded_climate: bool
- embedded_indoor_temperature: bool
- temperature_unit_is_fahrenheit: bool
- mui_please_confirm: string
- then:
- - lambda: |-
- // Blueprint version
- ESP_LOGV("service.global_settings", "Check Blueprint version");
- id(version_blueprint) = blueprint_version;
- id(check_versions).execute();
-
- // Relays
- ESP_LOGV("service.global_settings", "Setup relays");
- id(relay1_local).publish_state(relay1_local_control);
- id(relay2_local).publish_state(relay2_local_control);
- 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;
- id(relay_1_fallback) = relay1_fallback;
- id(relay_2_fallback) = relay2_fallback;
-
- // Localization
- ESP_LOGV("service.global_settings", "Load localization");
- id(mui_time_format) = time_format;
-
- // Date/Time colors
- ESP_LOGV("service.global_settings", "Load date/time colors");
- id(home_date_color) = date_color;
- id(home_time_color) = time_color;
-
- // Embedded thermostat
- ESP_LOGV("service.global_settings", "Load embedded thermostat");
- id(is_embedded_thermostat) = embedded_climate;
-
- // Indoor temperature
- ESP_LOGV("service.global_settings", "Set indoor temperature");
- id(embedded_indoor_temp) = embedded_indoor_temperature;
- id(temp_unit_fahrenheit) = temperature_unit_is_fahrenheit;
- id(display_embedded_temp).execute();
-
- // Confirm page
- ESP_LOGV("service.global_settings", "Setup confirm page");
- id(display_wrapped_text).execute("confirm.title", mui_please_confirm.c_str(), 15);
-
- // Refresh colors of global components
- ESP_LOGV("service.global_settings", "Refresh color of global components");
- id(disp1).set_component_font_color("home.date", id(home_date_color));
- id(disp1).set_component_font_color("home.time", id(home_time_color));
- id(disp1).set_component_font_color("home.icon_top_01", id(home_relay1_icon_color));
- id(disp1).set_component_font_color("home.icon_top_02", id(home_relay2_icon_color));
-
- // Update home page
- ESP_LOGV("service.global_settings", "Update home page");
- id(update_page_home).execute();
-
- ESP_LOGV("service.global_settings", "Current page: %s", id(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");
- id(disp1).set_component_text_printf("boot.bluep_version", "%s", blueprint_version.c_str());
- - wait_until:
- condition:
- - not:
- - text_sensor.state: # Is boot page visible?
+ - 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");
+ id(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'
- 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", id(wakeup_page_name).state.c_str());
- id(disp1).goto_page(id(wakeup_page_name).state.c_str());
- id(timer_reset_all).execute(id(wakeup_page_name).state.c_str());
+ 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", id(wakeup_page_name).state.c_str());
+ id(disp1).goto_page(id(wakeup_page_name).state.c_str());
+ id(timer_reset_all).execute(id(wakeup_page_name).state.c_str());
- #### Service to populate the page Home #####
- - service: page_home
- variables:
- 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[]
- alarm_state: string
- then:
- - lambda: |-
- // Notification button
- id(disp1).send_command_printf("is_notification=%i", (id(notification_text).state.empty() and id(notification_label).state.empty()) ? 0 : 1);
- id(disp1).set_component_text_printf("home.bt_notific", "%s", notification_icon.c_str());
- id(set_component_color).execute("home.bt_notific", id(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;
+ ##### SERVICE TO UPDATE THE HMI FILE ##############
+ - service: upload_tft
+ then:
+ - logger.log: "Service: upload_tft"
+ - binary_sensor.template.publish:
+ id: nextion_init
+ state: false
+ - lambda: 'id(upload_tft).execute("${nextion_update_url}");'
- // QRCode button
- id(disp1).send_command_printf("is_qrcode=%i", (qrcode) ? 1 : 0);
- id(disp1).set_component_text_printf("home.bt_qrcode", "%s", qrcode_icon.c_str());
- id(set_component_color).execute("home.bt_qrcode", qrcode_icon_color, {});
+ ##### SERVICE TO UPDATE THE TFT FILE from URL #####
+ - service: upload_tft_url
+ variables:
+ url: string
+ then:
+ - logger.log: "Service: upload_tft_url"
+ - binary_sensor.template.publish:
+ id: nextion_init
+ state: false
+ - lambda: 'id(upload_tft).execute(url.c_str());'
- // Entities pages button
- id(disp1).send_command_printf("is_entities=%i", (entities_pages) ? 1 : 0);
- id(disp1).set_component_text_printf("home.bt_entities", "%s", entities_pages_icon.c_str());
- id(set_component_color).execute("home.bt_entities", entities_pages_icon_color, {});
+ ##### Service to send a command "printf" directly to the display #####
+ - service: send_command_printf
+ variables:
+ cmd: string
+ then:
+ - lambda: 'id(disp1).send_command_printf("%s", cmd.c_str());'
- // Alarm button
- id(disp1).send_command_printf("is_alarm=%i", (alarm_state == "" or alarm_state.empty()) ? 0 : 1);
- id(update_alarm_icon).execute("home.bt_alarm", alarm_state.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: 'id(disp1).set_component_text_printf(component.c_str(), "%s", message.c_str());'
- #### 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()) id(disp1).set_component_text_printf("settings.lbl_reboot", " %s", reboot.c_str());
- id(disp1).set_component_text_printf("settings.lbl_brightness", " %s", brightness.c_str());
- id(display_wrapped_text).execute("settings.lbl_bright", bright.c_str(), id(display_mode) == 2 ? 25 : 10);
- id(display_wrapped_text).execute("settings.lbl_dim", dim.c_str(), id(display_mode) == 2 ? 25 : 10);
+ ##### Service to send a command "component_value (Dualstate Button)" directly to the display #####
+ - service: send_command_value
+ variables:
+ component: string
+ message: int
+ then:
+ - lambda: 'id(disp1).set_component_value(component.c_str(), message);'
- #### 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: |-
- // set alarm icon on home page
- id(disp1).send_command_printf("is_alarm=%i", (state == "" or state.empty()) ? 0 : 1);
- id(update_alarm_icon).execute("home.bt_alarm", state.c_str());
+ ##### Service to send a command "hide componente" directly to the display #####
+ - service: send_command_hide ### unused ###
+ variables:
+ component: string
+ then:
+ - lambda: 'id(disp1).hide_component(component.c_str());'
- // Is page Alarm visible?
- if (id(current_page).state == "alarm")
- { // Update alarm page
+ ##### Service to send a command "show componente" directly to the display #####
+ - service: send_command_show ### unused ###
+ variables:
+ component: string
+ then:
+ - lambda: 'id(disp1).show_component(component.c_str());'
+
+ ##### Service to send a command "show ALL componente" directly to the display #####
+ - service: send_command_show_all ### unused ###
+ then:
+ - lambda: id(disp1).show_component("255");
+
+ ##### Service to send a command "font color" directly to the display #####
+ - service: set_component_color
+ variables:
+ component: string
+ foreground: int[]
+ background: int[]
+ then:
+ - lambda: id(set_component_color).execute(component, foreground, background);
+
+ ##### Service to show a notification-message on the screen #####
+ - service: notification_show
+ variables:
+ label: string
+ text: string
+ then:
+ - lambda: |-
+ ESP_LOGV("service.notification_show", "Starting");
+
+ id(disp1).send_command_printf("is_notification=1");
+ id(disp1).goto_page("notification");
+ id(disp1).set_component_text_printf("notification.notifi_label", "%s", label.c_str());
+
+ id(display_wrapped_text).execute("notification.notifi_text01", text.c_str(), id(display_mode) == 2 ? 23 : 32);
+
+ id(notification_label).publish_state(label.c_str());
+ id(notification_text).publish_state(text.c_str());
+ id(timer_reset_all).execute(id(current_page).state.c_str());
+ id(notification_unread).turn_on();
+ if (id(notification_sound).state) id(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"
+ - ¬ification_clear
+ lambda: |-
+ id(disp1).send_command_printf("is_notification=0");
+ if (id(current_page).state == "home") id(disp1).hide_component("bt_notific");
+ id(notification_label).publish_state("");
+ id(notification_text).publish_state("");
+ id(notification_unread).turn_off();
+
+ ##### 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: |-
+ id(entity_id) = entity;
+ std::string cmd_page = std::string("page ") + page.c_str();
+ id(disp1).send_command_printf(cmd_page.c_str());
+ id(disp1).set_component_text_printf("page_label", "%s", page_label.c_str());
+ id(disp1).set_component_text_printf("back_page", "%s", back_page.c_str());
+ if (page == "climate")
+ {
+ if (entity == "embedded_climate") id(addon_climate_set_climate_friendly_name).execute(page_label.c_str());
+ id(disp1).set_component_value("embedded", (entity == "embedded_climate") ? 1 : 0);
+ }
+ else
+ {
+ if ((page_icon.c_str() != std::string()) and (page_icon.c_str() != ""))
+ id(disp1).set_component_text_printf("icon_state", "%s", page_icon.c_str());
+ id(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: |-
+ id(disp1).set_component_text_printf("qrcode.qrcode_label", "%s", title.c_str());
+ id(disp1).set_component_text_printf("qrcode.qrcode_value", "%s", qrcode.c_str());
+ if (show) id(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 (id(current_page).state == "climate") id(entity_id) = 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:
+ btn_id: string
+ btn_pic: int
+ btn_bg: int[]
+ btn_icon_font: int[]
+ btn_txt_font: int[]
+ btn_bri_font: int[]
+ btn_icon: string
+ btn_label: string
+ btn_bri_txt: string
+ then:
+ - lambda: |-
+ std::string btnicon = btn_id.c_str() + std::string("icon");
+ std::string btntext = btn_id.c_str() + std::string("text");
+ std::string btnbri = btn_id.c_str() + std::string("bri");
+ id(disp1).send_command_printf("%spic.pic=%i", btn_id.c_str(), btn_pic);
+ id(set_component_color).execute(btnicon.c_str(), btn_icon_font, btn_bg);
+ id(set_component_color).execute(btntext.c_str(), btn_txt_font, btn_bg);
+ id(set_component_color).execute(btnbri.c_str(), btn_bri_font, btn_bg);
+ id(disp1).set_component_text_printf(btnicon.c_str(), "%s", btn_icon.c_str());
+ id(display_wrapped_text).execute(btntext.c_str(), btn_label.c_str(), 10);
+ if (strcmp(btn_bri_txt.c_str(), "0") != 0)
+ id(disp1).set_component_text_printf(btnbri.c_str(), "%s", btn_bri_txt.c_str());
+ else
+ id(disp1).set_component_text_printf(btnbri.c_str(), " ");
+
+ ##### SERVICE TO WAKE UP THE DISPLAY #####
+ - service: wake_up
+ variables:
+ reset_timer: bool
+ then:
+ - lambda: |-
+ if (id(current_page).state == "screensaver") id(disp1).goto_page(id(wakeup_page_name).state.c_str());
+ if (reset_timer)
+ id(timer_reset_all).execute(id(wakeup_page_name).state.c_str());
+ else
+ {
+ id(timer_sleep).execute(id(wakeup_page_name).state.c_str(), int(id(timeout_sleep).state));
+ id(timer_dim).execute(id(wakeup_page_name).state.c_str(), int(id(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();
+ id(disp1).set_component_text_printf(enticon.c_str(), "%s", ent_icon.c_str());
+ if (strcmp(ent_icon.c_str(), "0") != 0) id(disp1).set_component_text_printf(enticon.c_str(), "%s", ent_icon.c_str());
+ id(disp1).set_component_text_printf(entlabel.c_str(), "%s", ent_label.c_str());
+ id(disp1).set_component_text_printf(ent_id.c_str(), "%s", ent_value.c_str());
+ if (strcmp(ent_value_xcen.c_str(), "0") != 0) id(disp1).send_command_printf("%s", entxcen.c_str());
+
+ #### Service to populate the page Home #####
+ - service: page_home
+ variables:
+ 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[]
+ alarm_state: string
+ then:
+ - lambda: |-
+ // Notification button
+ id(disp1).send_command_printf("is_notification=%i", (id(notification_text).state.empty() and id(notification_label).state.empty()) ? 0 : 1);
+ id(disp1).set_component_text_printf("home.bt_notific", "%s", notification_icon.c_str());
+ id(set_component_color).execute("home.bt_notific", id(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
+ id(disp1).send_command_printf("is_qrcode=%i", (qrcode) ? 1 : 0);
+ id(disp1).set_component_text_printf("home.bt_qrcode", "%s", qrcode_icon.c_str());
+ id(set_component_color).execute("home.bt_qrcode", qrcode_icon_color, {});
+
+ // Entities pages button
+ id(disp1).send_command_printf("is_entities=%i", (entities_pages) ? 1 : 0);
+ id(disp1).set_component_text_printf("home.bt_entities", "%s", entities_pages_icon.c_str());
+ id(set_component_color).execute("home.bt_entities", entities_pages_icon_color, {});
+
+ // Alarm button
+ id(disp1).send_command_printf("is_alarm=%i", (alarm_state == "" or alarm_state.empty()) ? 0 : 1);
+ id(update_alarm_icon).execute("home.bt_alarm", alarm_state.c_str());
+
+ #### 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()) id(disp1).set_component_text_printf("settings.lbl_reboot", " %s", reboot.c_str());
+ id(disp1).set_component_text_printf("settings.lbl_brightness", " %s", brightness.c_str());
+ id(display_wrapped_text).execute("settings.lbl_bright", bright.c_str(), id(display_mode) == 2 ? 25 : 10);
+ id(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 (id(current_page).state == "media_player")
+ {
id(entity_id) = entity;
+ id(disp1).set_component_text_printf("page_label", "%s", friendly_name.c_str());
+ id(display_wrapped_text).execute("track", media_title.c_str(), id(display_mode) == 2 ? 16 : 27);
+ id(display_wrapped_text).execute("artist", media_artist.c_str(), id(display_mode) == 2 ? 26 : 40);
- // Alarm page - Header
- id(update_alarm_icon).execute("icon_state", state.c_str());
- id(disp1).set_component_text_printf("page_label", "%s", page_title.c_str());
- id(disp1).set_component_text_printf("code_format", "%s", code_format.c_str());
- if (code_arm_required) id(disp1).set_component_text_printf("code_arm_req", "1"); else id(disp1).set_component_text_printf("code_arm_req", "0");
-
- // Alarm page - Button's icons
- id(disp1).set_component_text_printf("bt_home_icon", "\uE689"); //mdi:shield-home
- id(disp1).set_component_text_printf("bt_away_icon", "\uE99C"); //mdi:shield-lock
- id(disp1).set_component_text_printf("bt_night_icon", "\uF827"); //mdi:shield-moon
- id(disp1).set_component_text_printf("bt_vacat_icon", "\uE6BA"); //mdi:shield-airplane
- id(disp1).set_component_text_printf("bt_bypass_icon", "\uE77F"); //mdi:shield-half-full
- id(disp1).set_component_text_printf("bt_disarm_icon", "\uE99D"); //mdi:shield-off
-
- // Alarm page - Button's text
- id(display_wrapped_text).execute("bt_home_text", mui_alarm[0].c_str(), 10);
- id(display_wrapped_text).execute("bt_away_text", mui_alarm[1].c_str(), 10);
- id(display_wrapped_text).execute("bt_night_text", mui_alarm[2].c_str(), 10);
- id(display_wrapped_text).execute("bt_vacat_text", mui_alarm[3].c_str(), 10);
- id(display_wrapped_text).execute("bt_bypass_text", mui_alarm[4].c_str(), 10);
- id(display_wrapped_text).execute("bt_disarm_text", mui_alarm[5].c_str(), 10);
-
- // Alarm page - Buttons
- if (supported_features & 1) // Alarm - Button - Home
+ // on/off button
+ if (supported_features & 128 and state == "off") //TURN_ON
{
- id(disp1).send_command_printf("bt_home_pic.pic=%i", (state == "armed_home") ? 43 : 42);
- id(disp1).set_component_background_color("bt_home_text", (state == "armed_home") ? 19818 : 52857);
- id(disp1).set_component_background_color("bt_home_icon", (state == "armed_home") ? 19818 : 52857);
- id(disp1).set_component_font_color("bt_home_text", (state == "armed_home") ? 65535 : 0);
- id(disp1).set_component_font_color("bt_home_icon", (state == "armed_home") ? 65535 : 0);
- if (state == "armed_home") id(disp1).hide_component("bt_home"); else id(disp1).show_component("bt_home");
+ id(set_component_color).execute("bt_on_off", { 65535 }, {} );
+ id(disp1).show_component("bt_on_off");
}
- if (supported_features & 2) // Alarm - Button - Away
+ else if (supported_features & 256 and state != "off") //TURN_OFF
{
- id(disp1).send_command_printf("bt_away_pic.pic=%i", (state == "armed_away") ? 43 : 42);
- id(disp1).set_component_background_color("bt_away_text", (state == "armed_away") ? 19818 : 52857);
- id(disp1).set_component_background_color("bt_away_icon", (state == "armed_away") ? 19818 : 52857);
- id(disp1).set_component_font_color("bt_away_text", (state == "armed_away") ? 65535 : 0);
- id(disp1).set_component_font_color("bt_away_icon", (state == "armed_away") ? 65535 : 0);
- if (state == "armed_away") id(disp1).hide_component("bt_away"); else id(disp1).show_component("bt_away");
+ id(set_component_color).execute("bt_on_off", { 10597 }, {} );
+ id(disp1).show_component("bt_on_off");
}
- if (supported_features & 4) // Alarm - Button - Night
+ else id(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
{
- id(disp1).send_command_printf("bt_night_pic.pic=%i", (state == "armed_night") ? 43 : 42);
- id(disp1).set_component_background_color("bt_night_text", (state == "armed_night") ? 19818 : 52857);
- id(disp1).set_component_background_color("bt_night_icon", (state == "armed_night") ? 19818 : 52857);
- id(disp1).set_component_font_color("bt_night_text", (state == "armed_night") ? 65535 : 0);
- id(disp1).set_component_font_color("bt_night_icon", (state == "armed_night") ? 65535 : 0);
- if (state == "armed_night") id(disp1).hide_component("bt_night"); else id(disp1).show_component("bt_night");
+ id(disp1).set_component_text_printf("bt_play_pause", "%s", "\uE409"); // mdi:play
+ id(disp1).show_component("bt_play_pause");
}
- if (supported_features & 32) // Alarm - Button - Vacation
+ else if (supported_features & 1 and state == "playing" ) //PAUSE
{
- id(disp1).send_command_printf("bt_vacat_pic.pic=%i", (state == "armed_vacation") ? 43 : 42);
- id(disp1).set_component_background_color("bt_vacat_text", (state == "armed_vacation") ? 19818 : 52857);
- id(disp1).set_component_background_color("bt_vacat_icon", (state == "armed_vacation") ? 19818 : 52857);
- id(disp1).set_component_font_color("bt_vacat_text", (state == "armed_vacation") ? 65535 : 0);
- id(disp1).set_component_font_color("bt_vacat_icon", (state == "armed_vacation") ? 65535 : 0);
- if (state == "armed_vacation") id(disp1).hide_component("bt_vacat"); else id(disp1).show_component("bt_vacat");
+ id(disp1).set_component_text_printf("bt_play_pause", "%s", "\uE3E3"); // mdi:pause
+ id(disp1).show_component("bt_play_pause");
}
- if (supported_features & 16) // Alarm - Button - Custom bypass
+ else id(disp1).hide_component("bt_play_pause");
+
+ // bt_prev button - PREVIOUS_TRACK
+ if (supported_features & 16 and state != "off") id(disp1).show_component("bt_prev"); else id(disp1).hide_component("bt_prev");
+ // bt_next button - NEXT_TRACK
+ if (supported_features & 32 and state != "off") id(disp1).show_component("bt_next"); else id(disp1).hide_component("bt_next");
+
+ // Stop button - STOP
+ //if (supported_features & 4096 and (state == "playing" or state == "paused")) id(disp1).show_component("bt_stop"); else id(disp1).hide_component("bt_stop");
+
+ // mute/unmute button - VOLUME_MUTE
+ id(disp1).set_component_value("is_muted", (is_volume_muted) ? 1 : 0);
+ if (supported_features & 8 and is_volume_muted) // unmute
{
- id(disp1).send_command_printf("bt_bypass_pic.pic=%i", (state == "armed_bypass") ? 43 : 42);
- id(disp1).set_component_background_color("bt_bypass_text", (state == "armed_bypass") ? 19818 : 52857);
- id(disp1).set_component_background_color("bt_bypass_icon", (state == "armed_bypass") ? 19818 : 52857);
- id(disp1).set_component_font_color("bt_bypass_text", (state == "armed_bypass") ? 65535 : 0);
- id(disp1).set_component_font_color("bt_bypass_icon", (state == "armed_bypass") ? 65535 : 0);
- if (state == "armed_bypass") id(disp1).hide_component("bt_bypass"); else id(disp1).show_component("bt_bypass");
+ id(disp1).set_component_text_printf("bt_mute", "%s", "\uEE07"); // mdi:volume-variant-off
+ id(disp1).show_component("bt_mute");
}
- if ( true ) // Alarm - Button - Disarm
+ else if (supported_features & 8) // mute
{
- id(disp1).send_command_printf("bt_disarm_pic.pic=%i", (state == "disarmed") ? 43 : 42);
- id(disp1).set_component_background_color("bt_disarm_text", (state == "disarmed") ? 19818 : 52857);
- id(disp1).set_component_background_color("bt_disarm_icon", (state == "disarmed") ? 19818 : 52857);
- id(disp1).set_component_font_color("bt_disarm_text", (state == "disarmed") ? 65535 : 0);
- id(disp1).set_component_font_color("bt_disarm_icon", (state == "disarmed") ? 65535 : 0);
- if (state == "disarmed") id(disp1).hide_component("bt_disarm"); else id(disp1).show_component("bt_disarm");
+ id(disp1).set_component_text_printf("bt_mute", "%s", "\uE57E"); // mdi:volume-low
+ id(disp1).show_component("bt_mute");
}
- }
+ else id(disp1).hide_component("bt_mute");
- #### 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 (id(current_page).state == "media_player")
- {
- id(entity_id) = entity;
- id(disp1).set_component_text_printf("page_label", "%s", friendly_name.c_str());
- id(display_wrapped_text).execute("track", media_title.c_str(), id(display_mode) == 2 ? 16 : 27);
- id(display_wrapped_text).execute("artist", media_artist.c_str(), id(display_mode) == 2 ? 26 : 40);
+ // VOLUME_SET
+ if (supported_features & 4)
+ {
+ if (volume_level != id(last_volume_level))
+ {
+ id(last_volume_level) = volume_level;
+ id(disp1).set_component_text_printf("vol_text", "%i%%", volume_level);
+ id(disp1).set_component_value("vol_slider", volume_level);
+ }
+ id(disp1).show_component("vol_slider");
+ id(disp1).show_component("bt_vol_down");
+ id(disp1).show_component("bt_vol_up");
+ id(disp1).show_component("vol_text");
+ }
+ else
+ {
+ id(disp1).hide_component("vol_slider");
+ id(disp1).hide_component("bt_vol_down");
+ id(disp1).hide_component("bt_vol_up");
+ id(disp1).hide_component("vol_text");
+ }
- // on/off button
- if (supported_features & 128 and state == "off") //TURN_ON
- {
- id(set_component_color).execute("bt_on_off", { 65535 }, {} );
- id(disp1).show_component("bt_on_off");
- }
- else if (supported_features & 256 and state != "off") //TURN_OFF
- {
- id(set_component_color).execute("bt_on_off", { 10597 }, {} );
- id(disp1).show_component("bt_on_off");
- }
- else id(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
- {
- id(disp1).set_component_text_printf("bt_play_pause", "%s", "\uE409"); // mdi:play
- id(disp1).show_component("bt_play_pause");
- }
- else if (supported_features & 1 and state == "playing" ) //PAUSE
- {
- id(disp1).set_component_text_printf("bt_play_pause", "%s", "\uE3E3"); // mdi:pause
- id(disp1).show_component("bt_play_pause");
- }
- else id(disp1).hide_component("bt_play_pause");
-
- // bt_prev button - PREVIOUS_TRACK
- if (supported_features & 16 and state != "off") id(disp1).show_component("bt_prev"); else id(disp1).hide_component("bt_prev");
- // bt_next button - NEXT_TRACK
- if (supported_features & 32 and state != "off") id(disp1).show_component("bt_next"); else id(disp1).hide_component("bt_next");
-
- // Stop button - STOP
- //if (supported_features & 4096 and (state == "playing" or state == "paused")) id(disp1).show_component("bt_stop"); else id(disp1).hide_component("bt_stop");
-
- // mute/unmute button - VOLUME_MUTE
- id(disp1).set_component_value("is_muted", (is_volume_muted) ? 1 : 0);
- if (supported_features & 8 and is_volume_muted) // unmute
- {
- id(disp1).set_component_text_printf("bt_mute", "%s", "\uEE07"); // mdi:volume-variant-off
- id(disp1).show_component("bt_mute");
- }
- else if (supported_features & 8) // mute
- {
- id(disp1).set_component_text_printf("bt_mute", "%s", "\uE57E"); // mdi:volume-low
- id(disp1).show_component("bt_mute");
- }
- else id(disp1).hide_component("bt_mute");
-
- // VOLUME_SET
- if (supported_features & 4)
- {
- if (volume_level != id(last_volume_level))
- {
- id(last_volume_level) = volume_level;
- id(disp1).set_component_text_printf("vol_text", "%i%%", volume_level);
- id(disp1).set_component_value("vol_slider", volume_level);
- }
- id(disp1).show_component("vol_slider");
- id(disp1).show_component("bt_vol_down");
- id(disp1).show_component("bt_vol_up");
- id(disp1).show_component("vol_text");
- }
- else
- {
- id(disp1).hide_component("vol_slider");
- id(disp1).hide_component("bt_vol_down");
- id(disp1).hide_component("bt_vol_up");
- id(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;
- id(disp1).set_component_value("prg_current", int(round(min(media_position + media_position_delta, media_duration))));
- }
- id(disp1).set_component_value("prg_total", int(round(media_duration)));
- id(disp1).send_command_printf("prg_timer.en=%i", (state == "playing") ? 1 : 0);
- id(disp1).show_component("time_current");
- id(disp1).show_component("time_total");
- id(disp1).show_component("time_progress");
- }
- else
- {
- id(disp1).send_command_printf("prg_timer.en=0");
- id(disp1).hide_component("time_current");
- id(disp1).hide_component("time_total");
- id(disp1).hide_component("time_progress");
- }
- }
+ 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;
+ id(disp1).set_component_value("prg_current", int(round(min(media_position + media_position_delta, media_duration))));
+ }
+ id(disp1).set_component_value("prg_total", int(round(media_duration)));
+ id(disp1).send_command_printf("prg_timer.en=%i", (state == "playing") ? 1 : 0);
+ id(disp1).show_component("time_current");
+ id(disp1).show_component("time_total");
+ id(disp1).show_component("time_progress");
+ }
+ else
+ {
+ id(disp1).send_command_printf("prg_timer.en=0");
+ id(disp1).hide_component("time_current");
+ id(disp1).hide_component("time_total");
+ id(disp1).hide_component("time_progress");
+ }
+ }
##### START - GLOBALS CONFIGURATION #####
globals:
@@ -1044,40 +1015,6 @@ sensor:
- lambda: |-
id(timer_reset_all).execute(id(current_page).state.c_str());
- ##### Uptime Sensors #####
- - name: ${device_name} Uptime seconds
- id: uptime_sec
- platform: uptime
- internal: true
-
- - name: ${device_name} API uptime
- id: api_timestamp
- platform: template
- lambda: 'return id(time_provider).now().timestamp;'
- internal: false
- device_class: timestamp
- entity_category: diagnostic
- accuracy_decimals: 0
- update_interval: never
-
- - name: ${device_name} Device uptime
- id: device_timestamp
- platform: template
- lambda: 'return (id(time_provider).now().timestamp - id(uptime_sec).state);'
- internal: false
- device_class: timestamp
- entity_category: diagnostic
- accuracy_decimals: 0
- update_interval: never
-
- ##### WIFI Signal stregth
- - name: ${device_name} RSSI
- platform: wifi_signal
- update_interval: 60s
- on_value:
- - script.execute:
- id: refresh_wifi_icon
-
##### INTERNAL TEMPERATURE SENSOR, ADC VALUE #####
- id: ntc_source
platform: adc
@@ -1268,23 +1205,6 @@ text_sensor:
id(disp1).set_component_text_printf("bt_vol_up", "%s", "\uE75C"); //mdi:volume-plus
}
- ##### ESPhome version used to compile the app #####
- - name: ${device_name} ESPhome Version
- platform: version
- disabled_by_default: true
-
- - platform: wifi_info
- ip_address:
- name: ${device_name} IP
- disabled_by_default: true
- id: ip_address
- ssid:
- name: ${device_name} SSID
- disabled_by_default: true
- bssid:
- name: ${device_name} BSSID
- disabled_by_default: true
-
- name: ${device_name} Notification Label
platform: template
id: notification_label
@@ -1668,8 +1588,8 @@ number:
##### START - SELECT CONFIGURATION #####
select:
- - id: wakeup_page_name
- name: ${device_name} Wake-up page
+ - name: ${device_name} Wake-up page
+ id: wakeup_page_name
platform: template
options:
- home
@@ -1715,7 +1635,8 @@ display:
api.connected
- lambda: |-
ESP_LOGV("display.disp1.on_setup", "Publish IP address");
- id(disp1).set_component_text_printf("boot.ip_addr", "%s", id(ip_address).state.c_str());
+ auto ip = network::get_ip_address();
+ id(disp1).set_component_text_printf("boot.ip_addr", "%d.%d.%d.%d", ip[0], ip[1], ip[2], ip[3]);
ESP_LOGV("display.disp1.on_setup", "Report to Home Assistant");
auto ha_event = new esphome::api::CustomAPIDevice();
ha_event->fire_homeassistant_event("esphome.nspanel_ha_blueprint",
@@ -2334,17 +2255,6 @@ script:
int content_length_ = 0;
int tft_size_ = 0;
- auto power_cycle_display = []()
- {
- ESP_LOGD("script.upload_tft.power_cycle_display", "Turn off Nextion");
- id(screen_power).turn_off();
- delay(1500);
- ESP_LOGD("script.upload_tft.power_cycle_display", "Turn on Nextion");
- id(screen_power).turn_on();
- delay(5000);
- return true;
- };
-
auto send_nextion_command = [](const std::string &command) -> bool
{
ESP_LOGD("script.upload_tft.send_nextion_command", "Sending: %s", command.c_str());
@@ -2686,9 +2596,22 @@ script:
};
if (upload_tft(url, id(tf_uart).get_baud_rate())) id(restart_nspanel).press();
- power_cycle_display();
- if (upload_tft(url, (id(tf_uart).get_baud_rate() == 115200) ? 921600 : 115200 )) id(restart_nspanel).press();
- power_cycle_display();
+ ESP_LOGD("script.upload_tft", "Turn off Nextion");
+ id(screen_power).turn_off();
+ delay(1500);
+ ESP_LOGD("script.upload_tft", "Turn on Nextion");
+ id(screen_power).turn_on();
+ delay(1500);
+ unsigned int new_baud_rate;
+ if (id(tf_uart).get_baud_rate() == 115200) new_baud_rate = 921600; else new_baud_rate = 115200;
+ ESP_LOGD("script.upload_tft", "Trying again at %i bps", new_baud_rate);
+ if (upload_tft(url, new_baud_rate)) id(restart_nspanel).press();
+ ESP_LOGD("script.upload_tft", "Turn off Nextion");
+ id(screen_power).turn_off();
+ delay(1500);
+ ESP_LOGD("script.upload_tft", "Turn on Nextion");
+ id(screen_power).turn_on();
+ delay(1500);
ESP_LOGE("script.upload_tft", "TFT upload failed.");
ESP_LOGW("script.upload_tft", "Trying Nextion standard upload");
id(disp1)->set_tft_url(url.c_str());
diff --git a/nspanel_esphome_advanced.yaml b/nspanel_esphome_advanced.yaml
new file mode 100644
index 0000000..907668d
--- /dev/null
+++ b/nspanel_esphome_advanced.yaml
@@ -0,0 +1,97 @@
+#####################################################################################################
+##### NSPANEL ESPHOME created by Blackymas - https://github.com/Blackymas/NSPanel_HA_Blueprint #####
+##### ADVANCED CONFIG + FULL ESPHOME CODE! #####
+##### PLEASE only make changes if it is necessary and also the required knowledge is available. #####
+##### For normal use with the Blueprint, no changes are necessary. #####
+#####################################################################################################
+##### ATTENTION: This will add advanced elements to the core system and requires the core part. #####
+#####################################################################################################
+
+captive_portal:
+
+time:
+ - id: !extend time_provider
+ on_time_sync:
+ then:
+ - component.update: api_timestamp
+ - component.update: device_timestamp
+
+button:
+ ##### EXIT REPARSE TFT DISPLAY #####
+ - name: ${device_name} Exit reparse
+ platform: template
+ icon: mdi:file-sync
+ id: tft_reparse_off
+ entity_category: config
+ on_press:
+ - logger.log: "Button pressed: Exit reparse"
+ - uart.write:
+ id: tf_uart
+ data: "DRAKJHSUYDGBNCJHGJKSHBDN"
+ - uart.write:
+ id: tf_uart
+ data: [0xFF, 0xFF, 0xFF]
+
+api:
+ services:
+ ##### 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;'
+
+sensor:
+ ##### Uptime Sensors #####
+ - name: ${device_name} Uptime seconds
+ id: uptime_sec
+ platform: uptime
+ internal: true
+
+ - name: ${device_name} API uptime
+ id: api_timestamp
+ platform: template
+ lambda: 'return id(time_provider).now().timestamp;'
+ internal: false
+ device_class: timestamp
+ entity_category: diagnostic
+ accuracy_decimals: 0
+ update_interval: never
+
+ - name: ${device_name} Device uptime
+ id: device_timestamp
+ platform: template
+ lambda: 'return (id(time_provider).now().timestamp - id(uptime_sec).state);'
+ internal: false
+ device_class: timestamp
+ entity_category: diagnostic
+ accuracy_decimals: 0
+ update_interval: never
+
+ ##### WIFI Signal stregth
+ - name: ${device_name} RSSI
+ platform: wifi_signal
+ update_interval: 60s
+ on_value:
+ - script.execute:
+ id: refresh_wifi_icon
+
+text_sensor:
+ ##### ESPhome version used to compile the app #####
+ - name: ${device_name} ESPhome Version
+ platform: version
+ disabled_by_default: true
+
+ - platform: wifi_info
+ ip_address:
+ name: ${device_name} IP
+ disabled_by_default: true
+ id: ip_address
+ ssid:
+ name: ${device_name} SSID
+ disabled_by_default: true
+ bssid:
+ name: ${device_name} BSSID
+ disabled_by_default: true