This commit is contained in:
Edward Firmo
2024-03-15 17:23:51 +01:00
parent afbeb7a816
commit 7ce40bc4b7

View File

@@ -274,7 +274,7 @@ api:
if (entity_id.domain != "invalid" or entity == "embedded_climate") {
detailed_entity->publish_state(entity);
if (entity_id.domain == "alarm_control_panel") entity_id.domain = "alarm";
disp1->goto_page(entity_id.domain.c_str());
goto_page->execute(entity_id.domain.c_str());
disp1->send_command_printf("back_page_id=%" PRIu8, get_page_id(back_page.c_str()));
if (entity_id.domain == "climate")
disp1->set_component_value("embedded", (entity == "embedded_climate") ? 1 : 0);
@@ -443,13 +443,13 @@ api:
disp1->set_component_font_color("home.time", id(home_time_color));
// Chips icon size
disp1->send_command_printf("home.chip_relay1.font=%" PRIi32, chip_font);
disp1->send_command_printf("home.chip_relay2.font=%" PRIi32, chip_font);
disp1->send_command_printf("home.chip_climate.font=%" PRIi32, chip_font);
disp1->set_component_font("home.chip_relay1", chip_font);
disp1->set_component_font("home.chip_relay2", chip_font);
disp1->set_component_font("home.chip_climate", chip_font);
for (int i = 1; i <= 7; ++i) {
disp1->send_command_printf("home.chip%02d.font=%" PRIi32, i, chip_font);
}
disp1->send_command_printf("home.wifi_icon.font=%" PRIi32, chip_font);
disp1->set_component_font("home.wifi_icon", chip_font);
id(home_chip_font_id) = chip_font;
// Custom buttons icon size
@@ -457,12 +457,12 @@ api:
for (int i = 1; i <= 7; ++i) {
disp1->send_command_printf("home.button%02d.font=%" PRIu8, i, id(home_custom_buttons_font_id));
}
disp1->send_command_printf("home.bt_notific.font=%" PRIu8, id(home_custom_buttons_font_id));
disp1->send_command_printf("home.bt_qrcode.font=%" PRIu8, id(home_custom_buttons_font_id));
disp1->send_command_printf("home.bt_entities.font=%" PRIu8, id(home_custom_buttons_font_id));
disp1->set_component_font("home.bt_notific", id(home_custom_buttons_font_id));
disp1->set_component_font("home.bt_qrcode", id(home_custom_buttons_font_id));
disp1->set_component_font("home.bt_entities", id(home_custom_buttons_font_id));
// Outdoor temperature font size
disp1->send_command_printf("home.outdoor_temp.font==%" PRIi32, outdoor_temp_font);
disp1->set_component_font("home.outdoor_temp", outdoor_temp_font);
// QRCode button
set_component_visibility->execute("home.bt_qrcode", qrcode);
@@ -568,7 +568,7 @@ api:
// 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->send_command_printf("bt_home_pic.pic=%i", (state == "armed_home") ? 43 : 42); // To do: Replace this when esphome/esphome#6378 is merged
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);
@@ -578,7 +578,7 @@ api:
}
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->send_command_printf("bt_away_pic.pic=%i", (state == "armed_away") ? 43 : 42); // To do: Replace this when esphome/esphome#6378 is merged
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);
@@ -587,7 +587,7 @@ api:
}
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->send_command_printf("bt_night_pic.pic=%i", (state == "armed_night") ? 43 : 42); // To do: Replace this when esphome/esphome#6378 is merged
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);
@@ -596,7 +596,7 @@ api:
}
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->send_command_printf("bt_vacat_pic.pic=%i", (state == "armed_vacation") ? 43 : 42); // To do: Replace this when esphome/esphome#6378 is merged
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);
@@ -605,7 +605,7 @@ api:
}
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->send_command_printf("bt_bypass_pic.pic=%i", (state == "armed_bypass") ? 43 : 42); // To do: Replace this when esphome/esphome#6378 is merged
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);
@@ -614,7 +614,7 @@ api:
}
if ( true ) // Alarm - Button - Disarm
{
disp1->send_command_printf("bt_disarm_pic.pic=%i", (state == "disarmed") ? 43 : 42);
disp1->send_command_printf("bt_disarm_pic.pic=%i", (state == "disarmed") ? 43 : 42); // To do: Replace this when esphome/esphome#6378 is merged
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);
@@ -645,16 +645,16 @@ api:
- lambda: if (current_page->state == "climate") detailed_entity->publish_state(entity);
- script.execute:
id: set_climate
current_temp: !lambda "return current_temp;"
supported_features: !lambda "return supported_features;"
target_temp: !lambda "return target_temp;"
target_temp_high: !lambda "return target_temp_high;"
target_temp_low: !lambda "return target_temp_low;"
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;"
current_temp: !lambda return current_temp;
supported_features: !lambda return supported_features;
target_temp: !lambda return target_temp;
target_temp_high: !lambda return target_temp_high;
target_temp_low: !lambda return target_temp_low;
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;
# Dynamically updates the media player page with current state and media information.
- service: page_media_player
@@ -776,7 +776,7 @@ api:
tone: string # The RTTTL string for the melody to be played. It should follow the RTTTL format, including the melody's name, default settings, and a sequence of notes.
then:
- rtttl.play:
rtttl: !lambda 'return tone;'
rtttl: !lambda return tone;
# Updates an entity to display specific values with dynamic icons, names, and color codes.
- service: value
@@ -817,9 +817,9 @@ api:
}
// Decide which font to use based on adjusted length
if (adjusted_length > 8.0 and adjusted_length <= 12.0) {
disp1->send_command_printf("%s.font=1", id.c_str());
disp1->set_component_font(id.c_str(), 1);
} else if (adjusted_length > 12.0) {
disp1->send_command_printf("%s.font=0", id.c_str());
disp1->set_component_font(id.c_str(), 0);
}
}
}
@@ -847,8 +847,11 @@ display:
- id: disp1
platform: nextion
uart_id: tf_uart
start_up_page: 8
on_setup:
- script.execute: setup_sequence
lambda: |-
nextion_init->publish_state(true);
goto_page->execute("boot");
on_page:
lambda: |-
@@ -980,12 +983,6 @@ globals:
restore_value: false
initial_value: 'false'
##### Is boot sequence completed? #####
- id: setup_sequence_completed
type: bool
restore_value: false
initial_value: 'false'
##### Media Player #####
###### Last volume level from Home Assistant ######
- id: last_volume_level
@@ -1239,7 +1236,7 @@ number:
then:
- lambda: |-
disp1->send_command_printf("brightness=%i", int(x));
disp1->send_command_printf("settings.brightslider.val=%i", int(x));
disp1->set_component_value("settings.brightslider", int(x));
if (current_page->state != "screensaver") {
set_brightness->execute(x);
timer_dim->execute(current_page->state.c_str(), int(timeout_dim->state));
@@ -1263,7 +1260,7 @@ number:
then:
- lambda: |-
disp1->send_command_printf("brightness_dim=%i", int(x));
disp1->send_command_printf("settings.dimslider.val=%i", int(x));
disp1->set_component_value("settings.dimslider", int(x));
if (current_page->state != "screensaver" and current_brightness->state <= x) {
set_brightness->execute(x);
timer_sleep->execute(current_page->state.c_str(), int(timeout_sleep->state));
@@ -1483,7 +1480,7 @@ sensor:
then:
- number.set:
id: display_brightness
value: !lambda 'return int(x);'
value: !lambda return int(x);
- lambda: |-
timer_reset_all->execute("settings");
@@ -1497,7 +1494,7 @@ sensor:
then:
- number.set:
id: display_dim_brightness
value: !lambda 'return int(x);'
value: !lambda return int(x);
- lambda: |-
timer_reset_all->execute("settings");
@@ -1640,11 +1637,10 @@ text_sensor:
internal: false
disabled_by_default: false
on_value:
then:
- lambda: |-
if (!id(is_uploading_tft)) {
page_changed->execute(x.c_str());
}
lambda: |-
if (!id(is_uploading_tft)) {
page_changed->execute(x.c_str());
}
- id: notification_label
name: Notification Label
@@ -1918,7 +1914,7 @@ script:
// Blueprint version
nspanel_ha_blueprint::copyStringToCharArray(id(version_blueprint), blueprint_version);
disp1->set_component_text("boot.bluep_version", blueprint_version.c_str());
if (current_page->state == "boot") page_boot->execute();
// if (current_page->state == "boot") page_boot->execute();
check_versions->execute();
// MUI strings
@@ -1949,8 +1945,7 @@ script:
id: current_page
state: boot
then:
- lambda: |-
ESP_LOGV("script.global_settings", "Boot page is visible");
- lambda: ESP_LOGV("script.global_settings", "Boot page is visible");
- wait_until:
condition:
- not:
@@ -1964,8 +1959,7 @@ script:
id: current_page
state: 'boot'
then:
- lambda: |-
ESP_LOGV("script.global_settings", "Boot page still visible");
- lambda: ESP_LOGV("script.global_settings", "Boot page still visible");
- if:
condition:
switch.is_on: notification_sound
@@ -1977,8 +1971,7 @@ script:
goto_page->execute(wakeup_page_name->state.c_str());
timer_reset_all->execute(wakeup_page_name->state.c_str());
- lambda: |-
ESP_LOGV("script.global_settings", "Finished");
- lambda: ESP_LOGV("script.global_settings", "Finished");
- id: goto_page
mode: restart
@@ -2068,17 +2061,94 @@ script:
- id: page_boot
mode: restart
then:
- logger.log: Page boot called
- lambda: |-
set_brightness->execute(100);
disp1->set_component_text_printf("boot.esph_version", "${version}"); // ESPHome version
if (current_page->state == "boot") {
ESP_LOGW("DEBUG", "Page boot is visible");
#ifdef ARDUINO
disp1->set_component_text_printf("framework", "Arduino");
disp1->set_component_text("framework", "Arduino");
#elif defined(USE_ESP_IDF)
disp1->set_component_text_printf("framework", "ESP-IDF");
disp1->set_component_text("framework", "ESP-IDF");
#endif
disp1->send_command_printf("tm_esphome.en=0");
disp1->send_command_printf("tm_esphome.en=%i", (isnan(display_charset->state) or isnan(display_mode->state) or version_tft->state.empty()) ? 1 : 0);
}
- logger.log: Wait for Wi-Fi
- wait_until:
condition:
- lambda: return (wifi_component->is_connected());
timeout: 10s
- if:
condition:
- lambda: return (wifi_component->is_connected());
then: # Wi-Fi connected
- lambda: |-
if (current_page->state == "boot") {
disp1->set_component_text("ip_addr", network::get_ip_address().str().c_str()); // To do: get_ip_addresses()[0]
set_brightness->execute(100);
}
- wait_until:
condition:
- lambda: return (api_server->is_connected());
timeout: 10s
- if:
condition:
- lambda: return (api_server->is_connected());
then: # API connected
- lambda: |-
esphome::api::CustomAPIDevice ha_event;
ha_event.fire_homeassistant_event("esphome.nspanel_ha_blueprint",
{
{"device_name", device_name->state.c_str()},
{"type", "boot"},
{"step", "start"}
});
- wait_until:
condition:
- lambda: return (wifi_component->is_connected() and api_server->is_connected() and blueprint_status->state > 99);
timeout: 2s
- lambda: |-
set_brightness->execute(display_brightness->state);
disp1->send_command_printf("brightness=%i", int(display_brightness->state));
disp1->set_component_value("settings.brightslider", int(display_brightness->state));
disp1->send_command_printf("brightness_dim=%i", int(display_dim_brightness->state));
disp1->set_component_value("settings.dimslider", int(display_dim_brightness->state));
disp1->send_command_printf("brightness_sleep=%i", int(display_sleep_brightness->state));
nextion_init->publish_state(disp1->is_setup());
if (api_server->is_connected() and disp1->is_setup()) {
esphome::api::CustomAPIDevice ha_event;
ha_event.fire_homeassistant_event("esphome.nspanel_ha_blueprint",
{
{"device_name", device_name->state.c_str()},
{"type", "boot"},
{"step", "nextion_init"}
});
}
// Chips icon size
for (int i = 1; i <= 7; ++i) {
disp1->send_command_printf("home.chip%02d.font=%i", i, id(home_chip_font_id));
}
// Custom buttons icon size
for (int i = 1; i <= 7; ++i) {
disp1->send_command_printf("home.button%02d.font=%i", i, id(home_custom_buttons_font_id));
}
disp1->set_component_font("home.bt_notific", id(home_custom_buttons_font_id));
disp1->set_component_font("home.bt_qrcode", id(home_custom_buttons_font_id));
disp1->set_component_font("home.bt_entities", id(home_custom_buttons_font_id));
disp1->set_component_font("home.wifi_icon", id(home_chip_font_id));
disp1->set_component_font_color("home.chip_relay1", id(home_relay1_icon_color));
disp1->set_component_font_color("home.chip_relay2", id(home_relay2_icon_color));
timer_reset_all->execute("boot");
- wait_until:
condition:
- not:
- text_sensor.state: # Is boot page visible?
id: current_page
state: boot
timeout: 10s
- lambda: |-
if (current_page->state == "boot") goto_page->execute(wakeup_page_name->state.c_str());
- id: page_buttonpage
mode: restart
@@ -2116,8 +2186,10 @@ script:
page: string
then:
- lambda: |-
// Report new page to logs
ESP_LOGD("script.page_changed", "New page: %s", page.c_str());
// Go to boot page if not initiated
if (not nextion_init->state) goto_page->execute("boot");
if (blueprint_status->state <= 99) goto_page->execute("boot");
// Reset globals
if (page != "alarm" &&
page != "climate" &&
@@ -2136,8 +2208,6 @@ script:
id(last_media_position) = 0;
}
// Report new page to logs
ESP_LOGD("script.page_changed", "New page: %s", page.c_str());
if (!detailed_entity->state.empty())
ESP_LOGD("script.page_changed", "Entity shown: %s", detailed_entity->state.c_str());
@@ -2284,7 +2354,7 @@ script:
if (current_page->state == "screensaver" and !id(is_uploading_tft)) {
disp1->send_command_printf("back_page_id=%" PRIu8, get_page_id(wakeup_page_name->state.c_str()));
if (id(screensaver_display_time)) {
disp1->send_command_printf("screensaver.text.font=%i", id(screensaver_display_time_font));
disp1->set_component_font("screensaver.text", id(screensaver_display_time_font));
disp1->set_component_font_color("screensaver.text", id(screensaver_display_time_color));
set_component_visibility->execute("screensaver.text", true);
refresh_datetime->execute();
@@ -2509,14 +2579,14 @@ script:
then:
- if:
condition:
- lambda: !lambda return (tf_uart->get_baud_rate() != baud_rate);
- lambda: return (tf_uart->get_baud_rate() != baud_rate);
then:
- lambda: |-
ESP_LOGD("script.set_baud_rate", "Baud rate changing from %" PRIu32 " to %" PRIu32 " bps", tf_uart->get_baud_rate(), baud_rate);
ESP_LOGD("script.set_baud_rate", "Flush UART");
- wait_until:
condition:
- lambda: !lambda return (tf_uart->available() < 1);
- lambda: return (tf_uart->available() < 1);
timeout: 5s
- lambda: |-
ESP_LOGD("script.set_baud_rate", "Sending instruction '%s=%" PRIu32 "' to Nextion", definitive ? "bauds" : "baud", baud_rate);
@@ -2524,7 +2594,7 @@ script:
ESP_LOGD("script.set_baud_rate", "Flush UART");
- wait_until:
condition:
- lambda: !lambda return (tf_uart->available() < 1);
- lambda: return (tf_uart->available() < 1);
timeout: 5s
- lambda: |-
ESP_LOGD("script.set_baud_rate", "Set ESPHome new baud rate to %" PRIu32 " bps", baud_rate);
@@ -2639,108 +2709,6 @@ script:
nspanel_ha_blueprint::NextionComponent component = nspanel_ha_blueprint::extractNextionComponent(component_id, current_page->state);
if (component.is_current_page) disp1->send_command_printf("vis %s,%i", component.component_id.c_str(), show ? 1 : 0);
- id: setup_sequence
mode: restart
then:
- logger.log: Starting Nextion setup sequence
- lambda: display_charset->update();
- wait_until:
condition:
- lambda: !lambda return (not isnan(display_charset->state));
timeout: 5s
- lambda: display_mode->update();
- wait_until:
condition:
- lambda: !lambda return (not isnan(display_mode->state));
timeout: 5s
- if:
condition:
- lambda: !lambda return (not isnan(display_mode->state));
then: # Project's TFT detected
- lambda: |-
goto_page->execute("boot");
version_tft->update();
- wait_until:
condition:
- lambda: !lambda return (not version_tft->state.empty());
timeout: 5s
- wait_until:
condition:
- lambda: !lambda return (wifi_component->is_connected());
timeout: 10s
- if:
condition:
- lambda: !lambda return (wifi_component->is_connected());
then: # Wi-Fi connected
- lambda: |-
if (current_page->state == "boot") {
disp1->set_component_text("boot.ip_addr", network::get_ip_address().str().c_str()); // To do: get_ip_addresses()[0]
set_brightness->execute(100);
}
- wait_until:
condition:
- lambda: !lambda return (api_server->is_connected());
timeout: 10s
- if:
condition:
- lambda: !lambda return (api_server->is_connected());
then: # API connected
- lambda: |-
esphome::api::CustomAPIDevice ha_event;
ha_event.fire_homeassistant_event("esphome.nspanel_ha_blueprint",
{
{"device_name", device_name->state.c_str()},
{"type", "boot"},
{"step", "start"}
});
- wait_until:
condition:
- lambda: !lambda return id(setup_sequence_completed);
timeout: 1s
- lambda: |-
set_brightness->execute(display_brightness->state);
disp1->send_command_printf("brightness=%i", int(display_brightness->state));
disp1->send_command_printf("settings.brightslider.val=%i", int(display_brightness->state));
disp1->send_command_printf("brightness_dim=%i", int(display_dim_brightness->state));
disp1->send_command_printf("settings.dimslider.val=%i", int(display_dim_brightness->state));
disp1->send_command_printf("brightness_sleep=%i", int(display_sleep_brightness->state));
nextion_init->publish_state(disp1->is_setup());
if (api_server->is_connected() and disp1->is_setup()) {
esphome::api::CustomAPIDevice ha_event;
ha_event.fire_homeassistant_event("esphome.nspanel_ha_blueprint",
{
{"device_name", device_name->state.c_str()},
{"type", "boot"},
{"step", "nextion_init"}
});
}
// Chips icon size
for (int i = 1; i <= 7; ++i) {
disp1->send_command_printf("home.chip%02d.font=%i", i, id(home_chip_font_id));
}
// Custom buttons icon size
for (int i = 1; i <= 7; ++i) {
disp1->send_command_printf("home.button%02d.font=%i", i, id(home_custom_buttons_font_id));
}
disp1->send_command_printf("home.bt_notific.font=%i", id(home_custom_buttons_font_id));
disp1->send_command_printf("home.bt_qrcode.font=%i", id(home_custom_buttons_font_id));
disp1->send_command_printf("home.bt_entities.font=%i", id(home_custom_buttons_font_id));
disp1->send_command_printf("home.wifi_icon.font=%i", id(home_chip_font_id));
disp1->set_component_font_color("home.chip_relay1", id(home_relay1_icon_color));
disp1->set_component_font_color("home.chip_relay2", id(home_relay2_icon_color));
timer_reset_all->execute("boot");
id(setup_sequence_completed) = true;
- wait_until:
condition:
- not:
- text_sensor.state: # Is boot page visible?
id: current_page
state: boot
timeout: 10s
- lambda: |-
if (current_page->state == "boot") goto_page->execute(wakeup_page_name->state.c_str());
- logger.log: Nextion setup sequence finished
- id: stop_all
mode: restart
then:
@@ -2793,7 +2761,6 @@ script:
set_baud_rate->stop();
set_brightness->stop();
set_climate->stop();
setup_sequence->stop();
timer_dim->stop();
timer_page->stop();
timer_reset_all->stop();
@@ -2860,7 +2827,7 @@ script:
}
- if:
condition:
- lambda: !lambda return (timeout >= 1);
- lambda: return (timeout >= 1);
then:
- delay: !lambda return (timeout *1000);
- lambda: |-
@@ -2880,8 +2847,7 @@ script:
ESP_LOGV("script.timer_sleep", "Reset timer: %is", timeout);
- if:
condition:
- lambda: |-
return (timeout >= 1 and current_page->state != "screensaver" and current_page->state != "boot");
- lambda: return (timeout >= 1 and current_page->state != "screensaver" and current_page->state != "boot");
then:
- delay: !lambda return (timeout *1000);
- lambda: |-