HW button bar in all pages
Partially solves #1835 Partially solves #1517 Solves #1507
This commit is contained in:
@@ -105,6 +105,16 @@ globals:
|
||||
nspanel_ha_blueprint_upload_tft:
|
||||
|
||||
script:
|
||||
- id: nextion_status
|
||||
mode: restart
|
||||
then:
|
||||
- lambda: |-
|
||||
static const char *const TAG = "script.nextion_status";
|
||||
ESP_LOGD(TAG, "Nextion status:");
|
||||
ESP_LOGD(TAG, " Is detected: %s", YESNO(disp1->is_detected()));
|
||||
ESP_LOGD(TAG, " Is setup: %s", YESNO(disp1->is_setup()));
|
||||
ESP_LOGD(TAG, " Queue size: %d", disp1->queue_size());
|
||||
|
||||
- id: nextion_upload
|
||||
mode: single
|
||||
parameters:
|
||||
@@ -166,6 +176,11 @@ script:
|
||||
App.feed_wdt();
|
||||
}
|
||||
|
||||
- id: !extend stop_all
|
||||
then:
|
||||
- lambda: |-
|
||||
nextion_status->stop();
|
||||
|
||||
- id: upload_tft
|
||||
mode: single
|
||||
parameters:
|
||||
|
||||
@@ -24,8 +24,8 @@ substitutions:
|
||||
##### External components #####
|
||||
external_components:
|
||||
- source:
|
||||
#type: local
|
||||
#path: packages/Blackymas/components
|
||||
# type: local
|
||||
# path: packages/Blackymas/components
|
||||
type: git
|
||||
url: https://github.com/Blackymas/NSPanel_HA_Blueprint
|
||||
ref: dev # To do: Change it for releasing
|
||||
@@ -157,7 +157,6 @@ time:
|
||||
- seconds: 0
|
||||
then:
|
||||
- script.execute: refresh_datetime
|
||||
- seconds: 30
|
||||
|
||||
on_time_sync:
|
||||
then:
|
||||
@@ -370,9 +369,25 @@ api:
|
||||
disp1->set_component_font_color("home.chip_relay2", id(home_relay2_icon_color));
|
||||
}
|
||||
|
||||
// Refresh display
|
||||
// Refresh relays display
|
||||
refresh_relays->execute();
|
||||
|
||||
// Buttons bars settings
|
||||
update_bitwise_setting(id(buttons_settings), button_left, ButtonSettings::ButtonLeft_Enabled);
|
||||
update_bitwise_setting(id(buttons_settings), button_right, ButtonSettings::ButtonRight_Enabled);
|
||||
|
||||
if (button_bar_color_on.size() == 3)
|
||||
id(buttons_color_on) = ColorUtil::color_to_565(esphome::Color(button_bar_color_on[0],
|
||||
button_bar_color_on[1],
|
||||
button_bar_color_on[2]));
|
||||
if (button_bar_color_off.size() == 3)
|
||||
id(buttons_color_off) = ColorUtil::color_to_565(esphome::Color(button_bar_color_off[0],
|
||||
button_bar_color_off[1],
|
||||
button_bar_color_off[2]));
|
||||
|
||||
// Refresh buttons bars display
|
||||
refresh_hardware_buttons_bars->execute();
|
||||
|
||||
// Embedded thermostat
|
||||
id(is_embedded_thermostat) = embedded_climate;
|
||||
|
||||
@@ -404,26 +419,7 @@ api:
|
||||
then:
|
||||
- lambda: |-
|
||||
if (not id(is_uploading_tft)) {
|
||||
static const char *const TAG = "service.page_home";
|
||||
ESP_LOGV(TAG, "date_color: %i", date_color.size());
|
||||
ESP_LOGV(TAG, "time_format: %s", time_format.c_str());
|
||||
ESP_LOGV(TAG, "time_color: %i", time_color.size());
|
||||
ESP_LOGV(TAG, "meridiem: %i", meridiem.size());
|
||||
ESP_LOGV(TAG, "chip_font: %" PRIi32, chip_font);
|
||||
ESP_LOGV(TAG, "custom_buttons_font: %" PRIi32, custom_buttons_font);
|
||||
ESP_LOGV(TAG, "notification_icon: %s", notification_icon.c_str());
|
||||
ESP_LOGV(TAG, "notification_icon_color_normal: %i", notification_icon_color_normal.size());
|
||||
ESP_LOGV(TAG, "notification_icon_color_unread: %i", notification_icon_color_unread.size());
|
||||
ESP_LOGV(TAG, "qrcode: %s", YESNO(qrcode));
|
||||
ESP_LOGV(TAG, "qrcode_icon: %s", qrcode_icon.c_str());
|
||||
ESP_LOGV(TAG, "qrcode_icon_color: %i", qrcode_icon_color.size());
|
||||
ESP_LOGV(TAG, "entities_pages: %s", YESNO(entities_pages));
|
||||
ESP_LOGV(TAG, "entities_pages_icon: %s", entities_pages_icon.c_str());
|
||||
ESP_LOGV(TAG, "entities_pages_icon_color: %i", entities_pages_icon_color.size());
|
||||
ESP_LOGV(TAG, "outdoor_temp_font: %i", outdoor_temp_font);
|
||||
|
||||
// Localization
|
||||
ESP_LOGV(TAG, "Load localization");
|
||||
id(mui_time_format) = time_format;
|
||||
if (meridiem.size() == 2) {
|
||||
id(mui_meridiem)[0] = meridiem[0];
|
||||
@@ -431,14 +427,12 @@ api:
|
||||
}
|
||||
|
||||
// Date/Time colors
|
||||
ESP_LOGV(TAG, "Load date/time colors");
|
||||
id(home_date_color) = esphome::display::ColorUtil::color_to_565(esphome::Color(date_color[0], date_color[1], date_color[2]));
|
||||
id(home_time_color) = esphome::display::ColorUtil::color_to_565(esphome::Color(time_color[0], time_color[1], time_color[2]));
|
||||
disp1->set_component_font_color("home.date", id(home_date_color));
|
||||
disp1->set_component_font_color("home.time", id(home_time_color));
|
||||
|
||||
// Chips icon size
|
||||
ESP_LOGV(TAG, "Chips 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);
|
||||
@@ -449,7 +443,6 @@ api:
|
||||
id(home_chip_font_id) = chip_font;
|
||||
|
||||
// Custom buttons icon size
|
||||
ESP_LOGV(TAG, "Custom buttons sizes");
|
||||
id(home_custom_buttons_font_id) = custom_buttons_font;
|
||||
for (int i = 1; i <= 7; ++i) {
|
||||
disp1->send_command_printf("home.button%02d.font=%" PRIu8, i, id(home_custom_buttons_font_id));
|
||||
@@ -459,11 +452,9 @@ api:
|
||||
disp1->send_command_printf("home.bt_entities.font=%" PRIu8, id(home_custom_buttons_font_id));
|
||||
|
||||
// Outdoor temperature font size
|
||||
ESP_LOGV(TAG, "Outdoor temperature font size");
|
||||
disp1->send_command_printf("home.outdoor_temp.font==%" PRIi32, outdoor_temp_font);
|
||||
|
||||
// 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());
|
||||
id(home_notify_icon_color_normal) = esphome::display::ColorUtil::color_to_565(esphome::Color(notification_icon_color_normal[0],
|
||||
@@ -475,13 +466,11 @@ api:
|
||||
disp1->set_component_font_color("home.bt_notific", notification_unread->state ? id(home_notify_icon_color_unread) : id(home_notify_icon_color_normal));
|
||||
|
||||
// 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());
|
||||
disp1->set_component_font_color("home.bt_qrcode", esphome::display::ColorUtil::color_to_565(esphome::Color(qrcode_icon_color[0], qrcode_icon_color[1], qrcode_icon_color[2])));
|
||||
|
||||
// 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());
|
||||
disp1->set_component_font_color("home.bt_entities", esphome::display::ColorUtil::color_to_565(esphome::Color(entities_pages_icon_color[0],
|
||||
@@ -843,14 +832,7 @@ display:
|
||||
- script.execute: setup_sequence
|
||||
on_page:
|
||||
lambda: |-
|
||||
static const char *const TAG = "display.disp1.on_page";
|
||||
if (id(is_uploading_tft)) {
|
||||
ESP_LOGD(TAG, "Page changed ignored as a TFT upload is in progress");
|
||||
} else if (x > page_names.size()) {
|
||||
ESP_LOGW(TAG, "Invalid page index: %i", int(x));
|
||||
} else {
|
||||
ESP_LOGD(TAG, "Nextion page changed");
|
||||
ESP_LOGD(TAG, "New page: %s (%i)" , page_names[x], x);
|
||||
if (not id(is_uploading_tft)) {
|
||||
page_id->update();
|
||||
if (current_page->state != page_names[x] or x == 9) {
|
||||
current_page->publish_state(page_names[x]);
|
||||
@@ -859,11 +841,6 @@ display:
|
||||
}
|
||||
on_touch:
|
||||
lambda: |-
|
||||
static const char *const TAG = "display.disp1.on_touch";
|
||||
ESP_LOGV(TAG, "Nextion touch event detected!");
|
||||
ESP_LOGV(TAG, "Page: %s", page_names[page_id]);
|
||||
ESP_LOGV(TAG, "Component Id: %i", component_id);
|
||||
ESP_LOGV(TAG, "Event type: %s", touch_event ? "Press" : "Release");
|
||||
timer_reset_all->execute(page_names[page_id]);
|
||||
|
||||
##### START - GLOBALS CONFIGURATION #####
|
||||
@@ -1373,8 +1350,6 @@ select:
|
||||
icon: mdi:page-next-outline
|
||||
on_value:
|
||||
- lambda: |-
|
||||
static const char *const TAG = "select.wakeup_page_name";
|
||||
ESP_LOGD(TAG, "New wake-up page selected: %s", x.c_str());
|
||||
page_screensaver->execute();
|
||||
|
||||
##### START - SENSOR CONFIGURATION #####
|
||||
@@ -1404,8 +1379,6 @@ sensor:
|
||||
on_value:
|
||||
then:
|
||||
- lambda: |-
|
||||
static const char *const TAG = "sensor.blueprint_status";
|
||||
ESP_LOGD(TAG, "Blueprint progress: %i%%", int(round(x)));
|
||||
// Update api value on Nextion
|
||||
disp1->send_command_printf("api=%i", (x > 99) ? 1 : 0);
|
||||
|
||||
@@ -1481,11 +1454,6 @@ sensor:
|
||||
icon: mdi:brightness-percent
|
||||
internal: false
|
||||
disabled_by_default: false
|
||||
on_value:
|
||||
then:
|
||||
- lambda: |-
|
||||
static const char *const TAG = "sensor.current_brightness";
|
||||
ESP_LOGD(TAG, "Current brightness: %i%%", int(x));
|
||||
|
||||
###### Page Id - Current #####
|
||||
- id: page_id
|
||||
@@ -1499,13 +1467,7 @@ sensor:
|
||||
on_value:
|
||||
then:
|
||||
- lambda: |-
|
||||
static const char *const TAG = "sensor.page_id";
|
||||
ESP_LOGD(TAG, "New page Id: %i", int(x));
|
||||
if (id(is_uploading_tft)) {
|
||||
ESP_LOGD(TAG, "Skipping actions as a TFT upload is in progress");
|
||||
} else if (x > page_names.size()) {
|
||||
ESP_LOGW(TAG, "Invalid page index: %i", int(x));
|
||||
} else if (current_page->state != page_names[x]) {
|
||||
if (not id(is_uploading_tft) and current_page->state != page_names[x]) {
|
||||
current_page->publish_state(page_names[x]);
|
||||
page_changed->execute(page_names[x]);
|
||||
}
|
||||
@@ -1670,8 +1632,6 @@ text_sensor:
|
||||
on_value:
|
||||
then:
|
||||
- lambda: |-
|
||||
static const char *const TAG = "text_sensor.disp1_nspanel_event";
|
||||
ESP_LOGW(TAG, "Starting");
|
||||
DynamicJsonDocument doc(1024);
|
||||
deserializeJson(doc, x);
|
||||
std::string page = doc["page"];
|
||||
@@ -1679,10 +1639,6 @@ text_sensor:
|
||||
if (not (component == "currentpage" and (page == "screensaver" or page == "home"))) timer_reset_all->execute(page.c_str());
|
||||
std::string value = doc["value"];
|
||||
std::string entity = detailed_entity->state.c_str(); // doc["entity"];
|
||||
ESP_LOGW(TAG, "page: %s", page.c_str());
|
||||
ESP_LOGW(TAG, "component: %s", component.c_str());
|
||||
ESP_LOGW(TAG, "value: %s", value.c_str());
|
||||
ESP_LOGW(TAG, "entity: %s", entity.c_str());
|
||||
auto ha_event = new esphome::api::CustomAPIDevice();
|
||||
ha_event->fire_homeassistant_event("esphome.nspanel_ha_blueprint",
|
||||
{
|
||||
@@ -1708,7 +1664,6 @@ text_sensor:
|
||||
on_value:
|
||||
then:
|
||||
- lambda: |-
|
||||
static const char *const TAG = "text_sensor.localevent";
|
||||
DynamicJsonDocument doc(1024);
|
||||
deserializeJson(doc, x);
|
||||
std::string page = doc["page"];
|
||||
@@ -1795,8 +1750,6 @@ text_sensor:
|
||||
update_interval: never
|
||||
on_value:
|
||||
- lambda: |-
|
||||
static const char *const TAG = "text_sensor.version_tft";
|
||||
ESP_LOGD(TAG, "TFT version: %s", x.c_str());
|
||||
if (current_page->state == "boot") {
|
||||
page_boot->execute();
|
||||
timer_reset_all->execute("boot");
|
||||
@@ -1831,23 +1784,25 @@ script:
|
||||
return (compare_versions("${version}", version_tft->state.c_str()) and compare_versions("${version}", id(version_blueprint)));
|
||||
timeout: 60s
|
||||
- lambda: |-
|
||||
if (id(is_uploading_tft)) check_versions->stop();
|
||||
static const char *const TAG = "script.check_versions";
|
||||
ESP_LOGD(TAG, "Versions:");
|
||||
ESP_LOGD(TAG, " ESPHome: ${version}");
|
||||
ESP_LOGD(TAG, " TFT: %s", version_tft->state.c_str());
|
||||
if (not compare_versions("${version}", version_tft->state.c_str())) ESP_LOGE(TAG, "TFT version mismatch!");
|
||||
ESP_LOGD(TAG, " Blueprint: %s", id(version_blueprint));
|
||||
if (not compare_versions("${version}", id(version_blueprint))) ESP_LOGE(TAG, "Blueprint version mismatch!");
|
||||
if (not id(is_uploading_tft)) {
|
||||
ESP_LOGD("script.check_versions", "Versions:");
|
||||
ESP_LOGD("script.check_versions", " ESPHome: ${version}");
|
||||
ESP_LOGD("script.check_versions", " TFT: %s", version_tft->state.c_str());
|
||||
if (not compare_versions("${version}", version_tft->state.c_str()))
|
||||
ESP_LOGE("script.check_versions", "TFT version mismatch!");
|
||||
ESP_LOGD("script.check_versions", " Blueprint: %s", id(version_blueprint));
|
||||
if (not compare_versions("${version}", id(version_blueprint)))
|
||||
ESP_LOGE("script.check_versions", "Blueprint version mismatch!");
|
||||
|
||||
auto ha_event = new esphome::api::CustomAPIDevice();
|
||||
ha_event->fire_homeassistant_event("esphome.nspanel_ha_blueprint",
|
||||
{
|
||||
{"type", "version"},
|
||||
{"tft", version_tft->state.c_str()},
|
||||
{"esphome", "${version}"},
|
||||
{"blueprint", id(version_blueprint)}
|
||||
});
|
||||
auto ha_event = new esphome::api::CustomAPIDevice();
|
||||
ha_event->fire_homeassistant_event("esphome.nspanel_ha_blueprint",
|
||||
{
|
||||
{"type", "version"},
|
||||
{"tft", version_tft->state.c_str()},
|
||||
{"esphome", "${version}"},
|
||||
{"blueprint", id(version_blueprint)}
|
||||
});
|
||||
}
|
||||
|
||||
- id: display_embedded_temp
|
||||
mode: restart
|
||||
@@ -1909,9 +1864,7 @@ script:
|
||||
then:
|
||||
- lambda: |-
|
||||
if (id(is_uploading_tft)) global_settings->stop();
|
||||
static const char *const TAG = "script.global_settings";
|
||||
// Blueprint version
|
||||
ESP_LOGV(TAG, "Check Blueprint version");
|
||||
nspanel_ha_blueprint::copyStringToCharArray(id(version_blueprint), blueprint_version);
|
||||
disp1->set_component_text_printf("boot.bluep_version", "%s", blueprint_version.c_str());
|
||||
if (current_page->state == "boot") page_boot->execute();
|
||||
@@ -1922,7 +1875,6 @@ script:
|
||||
id(mui_unavailable_global) = mui_unavailable;
|
||||
|
||||
// Screen saver page (sleep)
|
||||
ESP_LOGV(TAG, "Setup screensaver page");
|
||||
id(screensaver_display_time) = screensaver_time;
|
||||
id(screensaver_display_time_font) = screensaver_time_font;
|
||||
id(screensaver_display_time_color) = esphome::display::ColorUtil::color_to_565(esphome::Color(screensaver_time_color[0], screensaver_time_color[1], screensaver_time_color[2]));
|
||||
@@ -1933,10 +1885,8 @@ script:
|
||||
|
||||
if (current_page->state != "boot") {
|
||||
// Update current page
|
||||
ESP_LOGV(TAG, "Update current page");
|
||||
page_changed->execute(current_page->state.c_str());
|
||||
}
|
||||
ESP_LOGV(TAG, "Current page: %s", current_page->state.c_str());
|
||||
disp1->set_component_text_printf("boot.bluep_version", "%s", blueprint_version.c_str());
|
||||
|
||||
- if:
|
||||
@@ -2013,16 +1963,8 @@ script:
|
||||
entity: string
|
||||
then:
|
||||
- lambda: |-
|
||||
if (id(is_uploading_tft)) ha_call_service->stop();
|
||||
static const char *const TAG = "script.ha_call_service";
|
||||
ESP_LOGV(TAG, "Calling Home Assisant service");
|
||||
ESP_LOGV(TAG, " Type: service_call");
|
||||
ESP_LOGV(TAG, " Service: %s", service.c_str());
|
||||
ESP_LOGV(TAG, " Entity: %s", entity.c_str());
|
||||
ESP_LOGV(TAG, " Key: %s", key.c_str());
|
||||
ESP_LOGV(TAG, " Value: %s", value.c_str());
|
||||
if (service != "" and not service.empty())
|
||||
{
|
||||
if (not id(is_uploading_tft)) {
|
||||
if (service != "" and not service.empty()) {
|
||||
auto ha_event = new esphome::api::CustomAPIDevice();
|
||||
ha_event->fire_homeassistant_event("esphome.nspanel_ha_blueprint",
|
||||
{
|
||||
@@ -2033,17 +1975,7 @@ script:
|
||||
{"value", value}
|
||||
});
|
||||
}
|
||||
ESP_LOGV(TAG, "Finished");
|
||||
|
||||
- id: nextion_status
|
||||
mode: restart
|
||||
then:
|
||||
- lambda: |-
|
||||
static const char *const TAG = "script.nextion_status";
|
||||
ESP_LOGD(TAG, "Nextion status:");
|
||||
ESP_LOGD(TAG, " Is detected: %s", YESNO(disp1->is_detected()));
|
||||
ESP_LOGD(TAG, " Is setup: %s", YESNO(disp1->is_setup()));
|
||||
ESP_LOGD(TAG, " Queue size: %d", disp1->queue_size());
|
||||
}
|
||||
|
||||
- id: notification_clear
|
||||
mode: restart
|
||||
@@ -2065,8 +1997,7 @@ script:
|
||||
mode: restart
|
||||
then:
|
||||
- lambda: |-
|
||||
static const char *const TAG = "script.page_blank";
|
||||
ESP_LOGV(TAG, "Construct blank page");
|
||||
ESP_LOGV("script.page_blank", "Construct blank page");
|
||||
disp1->set_component_text_printf("esp_version", "ESP: ${version}"); // ESPHome version
|
||||
#ifdef ARDUINO
|
||||
disp1->set_component_text_printf("framework", "Arduino");
|
||||
@@ -2079,8 +2010,6 @@ script:
|
||||
mode: restart
|
||||
then:
|
||||
- lambda: |-
|
||||
static const char *const TAG = "script.page_boot";
|
||||
ESP_LOGV(TAG, "Construct boot page");
|
||||
set_brightness->execute(100);
|
||||
disp1->set_component_text_printf("boot.esph_version", "${version}"); // ESPHome version
|
||||
if (current_page->state == "boot") {
|
||||
@@ -2128,8 +2057,6 @@ script:
|
||||
page: string
|
||||
then:
|
||||
- lambda: |-
|
||||
static const char *const TAG = "script.page_changed";
|
||||
|
||||
// Go to boot page if not initiated
|
||||
if (not nextion_init->state) goto_page->execute("boot");
|
||||
// Reset globals
|
||||
@@ -2151,14 +2078,17 @@ script:
|
||||
}
|
||||
|
||||
// Report new page to logs
|
||||
ESP_LOGD(TAG, "New page: %s", page.c_str());
|
||||
if (!detailed_entity->state.empty()) ESP_LOGD(TAG, "Entity shown: %s", detailed_entity->state.c_str());
|
||||
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());
|
||||
|
||||
// Update buttons bars on screen
|
||||
refresh_hardware_buttons_bars->execute();
|
||||
|
||||
// Reset timers
|
||||
timer_reset_all->execute(page.c_str());
|
||||
|
||||
// Report new page to Home Assistant
|
||||
ESP_LOGV(TAG, "Trigger HA event");
|
||||
auto ha_event = new esphome::api::CustomAPIDevice();
|
||||
ha_event->fire_homeassistant_event("esphome.nspanel_ha_blueprint",
|
||||
{
|
||||
@@ -2278,8 +2208,6 @@ script:
|
||||
mode: restart
|
||||
then:
|
||||
- lambda: |-
|
||||
static const char *const TAG = "script.page_notification";
|
||||
ESP_LOGV(TAG, "Updating notification page");
|
||||
disp1->set_component_text_printf("notification.notifi_label", "%s", notification_label->state.c_str());
|
||||
display_wrapped_text->execute("notification.notifi_text01", notification_text->state.c_str(), display_mode->state == 2 ? 23 : 32);
|
||||
|
||||
@@ -2292,8 +2220,6 @@ script:
|
||||
then:
|
||||
- lambda: |-
|
||||
if (current_page->state == "screensaver" and not id(is_uploading_tft)) {
|
||||
static const char *const TAG = "script.page_screensaver";
|
||||
ESP_LOGV(TAG, "Updating screensaver page");
|
||||
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));
|
||||
@@ -2310,8 +2236,6 @@ script:
|
||||
mode: restart
|
||||
then:
|
||||
- lambda: |-
|
||||
static const char *const TAG = "script.page_settings";
|
||||
ESP_LOGV(TAG, "Construct settings page");
|
||||
//disp1->set_component_text_printf("bt_sleep", "%s", (id(sleep_mode).state) ? "\uEA19" : "\uEA18"); //mdi:toggle-switch-outline or mdi:toggle-switch-off-outline
|
||||
set_component_visibility->execute("page_settings.lbl_sleep", false);
|
||||
set_component_visibility->execute("page_settings.bt_sleep", false);
|
||||
@@ -2356,8 +2280,6 @@ script:
|
||||
mode: restart
|
||||
then:
|
||||
- lambda: |-
|
||||
static const char *const TAG = "script.refresh_datetime";
|
||||
ESP_LOGV(TAG, "Updating time display");
|
||||
std::string time_format_str = id(mui_time_format);
|
||||
if (time_format_str.find("%-H") != std::string::npos) {
|
||||
time_format_str = time_format_str.replace(time_format_str.find("%-H"), sizeof("%-H")-1,
|
||||
@@ -2376,40 +2298,51 @@ script:
|
||||
}
|
||||
std::string meridiem_text = (id(time_provider).now().hour<12) ? id(mui_meridiem)[0] : id(mui_meridiem)[1];
|
||||
if (current_page->state == "screensaver" and id(screensaver_display_time)) {
|
||||
ESP_LOGV(TAG, "Updating time on screensaver page");
|
||||
std::string time_format_str_sleep = time_format_str;
|
||||
if (time_format_str_sleep.find("%p") != std::string::npos)
|
||||
time_format_str_sleep.replace(time_format_str_sleep.find("%p"), sizeof("%p")-1, meridiem_text.c_str());
|
||||
disp1->set_component_text_printf("text", "%s", id(time_provider).now().strftime(time_format_str_sleep).c_str());
|
||||
}
|
||||
ESP_LOGV(TAG, "Updating home page meridiem");
|
||||
disp1->set_component_text_printf("home.meridiem", "%s", (time_format_str.find("%p") != std::string::npos) ? meridiem_text.c_str() : " ");
|
||||
ESP_LOGV(TAG, "Updating home page time");
|
||||
disp1->set_component_text_printf("home.time", "%s", id(time_provider).now().strftime(time_format_str).c_str());
|
||||
refresh_hardware_buttons_bars->execute();
|
||||
|
||||
- id: refresh_hardware_buttons_bars
|
||||
mode: restart
|
||||
then:
|
||||
- lambda: |-
|
||||
if (not id(is_uploading_tft)) {
|
||||
if (display_mode->state == 3) { // US Landscape model
|
||||
if (id(buttons_settings) & nspanel_ha_blueprint::ButtonSettings::ButtonLeft_Enabled) { // Left button
|
||||
disp1->fill_area(467, 174, 3, 118, (id(buttons_settings) & nspanel_ha_blueprint::ButtonSettings::ButtonLeft_State) ? id(buttons_color_on) : id(buttons_color_off));
|
||||
disp1->fill_area(468, 173, 1, 120, (id(buttons_settings) & nspanel_ha_blueprint::ButtonSettings::ButtonLeft_State) ? id(buttons_color_on) : id(buttons_color_off));
|
||||
}
|
||||
if (id(buttons_settings) & nspanel_ha_blueprint::ButtonSettings::ButtonRight_Enabled) { // Right button
|
||||
disp1->fill_area(467, 28, 3, 118, (id(buttons_settings) & nspanel_ha_blueprint::ButtonSettings::ButtonRight_State) ? id(buttons_color_on) : id(buttons_color_off));
|
||||
disp1->fill_area(468, 27, 1, 120, (id(buttons_settings) & nspanel_ha_blueprint::ButtonSettings::ButtonRight_State) ? id(buttons_color_on) : id(buttons_color_off));
|
||||
}
|
||||
} else { // US Portrait and EU models
|
||||
if (id(buttons_settings) & nspanel_ha_blueprint::ButtonSettings::ButtonLeft_Enabled) { // Left button
|
||||
disp1->fill_area(48, 307, 118, 3, (id(buttons_settings) & nspanel_ha_blueprint::ButtonSettings::ButtonLeft_State) ? id(buttons_color_on) : id(buttons_color_off));
|
||||
disp1->fill_area(47, 308, 120, 1, (id(buttons_settings) & nspanel_ha_blueprint::ButtonSettings::ButtonLeft_State) ? id(buttons_color_on) : id(buttons_color_off));
|
||||
}
|
||||
if (id(buttons_settings) & nspanel_ha_blueprint::ButtonSettings::ButtonRight_Enabled) { // Right button
|
||||
disp1->fill_area(289, 307, 118, 3, (id(buttons_settings) & nspanel_ha_blueprint::ButtonSettings::ButtonRight_State) ? id(buttons_color_on) : id(buttons_color_off));
|
||||
disp1->fill_area(288, 308, 120, 1, (id(buttons_settings) & nspanel_ha_blueprint::ButtonSettings::ButtonRight_State) ? id(buttons_color_on) : id(buttons_color_off));
|
||||
}
|
||||
switch (int(display_mode->state)) {
|
||||
case 1: // EU model
|
||||
if (id(buttons_settings) & nspanel_ha_blueprint::ButtonSettings::ButtonLeft_Enabled) { // Left button
|
||||
disp1->fill_area(48, 307, 118, 3, (id(buttons_settings) & nspanel_ha_blueprint::ButtonSettings::ButtonLeft_State) ? id(buttons_color_on) : id(buttons_color_off));
|
||||
disp1->fill_area(47, 308, 120, 1, (id(buttons_settings) & nspanel_ha_blueprint::ButtonSettings::ButtonLeft_State) ? id(buttons_color_on) : id(buttons_color_off));
|
||||
}
|
||||
if (id(buttons_settings) & nspanel_ha_blueprint::ButtonSettings::ButtonRight_Enabled) { // Right button
|
||||
disp1->fill_area(289, 307, 118, 3, (id(buttons_settings) & nspanel_ha_blueprint::ButtonSettings::ButtonRight_State) ? id(buttons_color_on) : id(buttons_color_off));
|
||||
disp1->fill_area(288, 308, 120, 1, (id(buttons_settings) & nspanel_ha_blueprint::ButtonSettings::ButtonRight_State) ? id(buttons_color_on) : id(buttons_color_off));
|
||||
}
|
||||
break;
|
||||
case 2: // US Portrait
|
||||
if (id(buttons_settings) & nspanel_ha_blueprint::ButtonSettings::ButtonLeft_Enabled) { // Left button
|
||||
disp1->fill_area(17, 466, 118, 3, (id(buttons_settings) & nspanel_ha_blueprint::ButtonSettings::ButtonLeft_State) ? id(buttons_color_on) : id(buttons_color_off));
|
||||
disp1->fill_area(16, 467, 120, 1, (id(buttons_settings) & nspanel_ha_blueprint::ButtonSettings::ButtonLeft_State) ? id(buttons_color_on) : id(buttons_color_off));
|
||||
}
|
||||
if (id(buttons_settings) & nspanel_ha_blueprint::ButtonSettings::ButtonRight_Enabled) { // Right button
|
||||
disp1->fill_area(184, 466, 118, 3, (id(buttons_settings) & nspanel_ha_blueprint::ButtonSettings::ButtonRight_State) ? id(buttons_color_on) : id(buttons_color_off));
|
||||
disp1->fill_area(183, 467, 120, 1, (id(buttons_settings) & nspanel_ha_blueprint::ButtonSettings::ButtonRight_State) ? id(buttons_color_on) : id(buttons_color_off));
|
||||
}
|
||||
break;
|
||||
case 3: // US Landscape
|
||||
if (id(buttons_settings) & nspanel_ha_blueprint::ButtonSettings::ButtonLeft_Enabled) { // Left button
|
||||
disp1->fill_area(467, 174, 3, 118, (id(buttons_settings) & nspanel_ha_blueprint::ButtonSettings::ButtonLeft_State) ? id(buttons_color_on) : id(buttons_color_off));
|
||||
disp1->fill_area(468, 173, 1, 120, (id(buttons_settings) & nspanel_ha_blueprint::ButtonSettings::ButtonLeft_State) ? id(buttons_color_on) : id(buttons_color_off));
|
||||
}
|
||||
if (id(buttons_settings) & nspanel_ha_blueprint::ButtonSettings::ButtonRight_Enabled) { // Right button
|
||||
disp1->fill_area(467, 28, 3, 118, (id(buttons_settings) & nspanel_ha_blueprint::ButtonSettings::ButtonRight_State) ? id(buttons_color_on) : id(buttons_color_off));
|
||||
disp1->fill_area(468, 27, 1, 120, (id(buttons_settings) & nspanel_ha_blueprint::ButtonSettings::ButtonRight_State) ? id(buttons_color_on) : id(buttons_color_off));
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2420,9 +2353,7 @@ script:
|
||||
condition:
|
||||
- lambda: !lambda return id(setup_sequence_completed);
|
||||
- lambda: |-
|
||||
static const char *const TAG = "script.refresh_notification";
|
||||
bool is_notification = ((not notification_text->state.empty()) or (not notification_label->state.empty()));
|
||||
ESP_LOGV(TAG, "Notification: %s", YESNO(is_notification));
|
||||
disp1->send_command_printf("is_notification=%i", is_notification ? 1 : 0);
|
||||
set_component_visibility->execute("home.bt_notific", is_notification);
|
||||
- wait_until:
|
||||
@@ -2512,28 +2443,25 @@ script:
|
||||
- lambda: !lambda return (tf_uart->get_baud_rate() != baud_rate);
|
||||
then:
|
||||
- lambda: |-
|
||||
static const char *const TAG = "script.set_baud_rate";
|
||||
ESP_LOGD(TAG, "Baud rate changing from %" PRIu32 " to %" PRIu32 " bps", tf_uart->get_baud_rate(), baud_rate);
|
||||
ESP_LOGD(TAG, "Flush UART");
|
||||
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);
|
||||
timeout: 5s
|
||||
- lambda: |-
|
||||
static const char *const TAG = "script.set_baud_rate";
|
||||
ESP_LOGD(TAG, "Sending instruction '%s=%" PRIu32 "' to Nextion", definitive ? "bauds" : "baud", baud_rate);
|
||||
ESP_LOGD("script.set_baud_rate", "Sending instruction '%s=%" PRIu32 "' to Nextion", definitive ? "bauds" : "baud", baud_rate);
|
||||
disp1->send_command_printf("%s=%" PRIu32, definitive ? "bauds" : "baud", baud_rate);
|
||||
ESP_LOGD(TAG, "Flush UART");
|
||||
ESP_LOGD("script.set_baud_rate", "Flush UART");
|
||||
- wait_until:
|
||||
condition:
|
||||
- lambda: !lambda return (tf_uart->available() < 1);
|
||||
timeout: 5s
|
||||
- lambda: |-
|
||||
static const char *const TAG = "script.set_baud_rate";
|
||||
ESP_LOGD(TAG, "Set ESPHome new baud rate to %" PRIu32 " bps", baud_rate);
|
||||
ESP_LOGD("script.set_baud_rate", "Set ESPHome new baud rate to %" PRIu32 " bps", baud_rate);
|
||||
tf_uart->set_baud_rate(baud_rate);
|
||||
tf_uart->load_settings();
|
||||
ESP_LOGD(TAG, "Current baud rate: %" PRIu32 " bps", tf_uart->get_baud_rate());
|
||||
ESP_LOGD("script.set_baud_rate", "Current baud rate: %" PRIu32 " bps", tf_uart->get_baud_rate());
|
||||
|
||||
- id: set_brightness
|
||||
mode: restart
|
||||
@@ -2541,8 +2469,6 @@ script:
|
||||
brightness: float
|
||||
then:
|
||||
- lambda: |-
|
||||
static const char *const TAG = "script.set_brightness";
|
||||
ESP_LOGD(TAG, "brightness: %.0f%%", brightness);
|
||||
if (brightness == display_brightness->state and current_page->state != "boot" and current_page->state != "screensaver")
|
||||
disp1->send_command_printf("wakeup_timer.en=1");
|
||||
else
|
||||
@@ -2567,20 +2493,7 @@ script:
|
||||
then:
|
||||
- lambda: |-
|
||||
if (id(is_uploading_tft)) set_climate->stop();
|
||||
static const char *const TAG = "script.set_climate";
|
||||
ESP_LOGD(TAG, "Starting");
|
||||
ESP_LOGD(TAG, " current_temp: %f", current_temp);
|
||||
ESP_LOGD(TAG, " supported_features: %i", supported_features);
|
||||
ESP_LOGD(TAG, " target_temp: %f", target_temp);
|
||||
ESP_LOGD(TAG, " target_temp_high: %f", target_temp_high);
|
||||
ESP_LOGD(TAG, " target_temp_low: %f", target_temp_low);
|
||||
ESP_LOGD(TAG, " temp_step: %d", temp_step);
|
||||
ESP_LOGD(TAG, " total_steps: %d", total_steps);
|
||||
ESP_LOGD(TAG, " temp_offset: %i", temp_offset);
|
||||
ESP_LOGD(TAG, " climate_icon: %s", climate_icon.c_str());
|
||||
ESP_LOGD(TAG, " embedded_climate: %s", YESNO(embedded_climate));
|
||||
if (current_page->state == "climate") {
|
||||
ESP_LOGD(TAG, "Page climate is visible");
|
||||
disp1->send_command_printf("climateslider.maxval=%i", total_steps);
|
||||
disp1->send_command_printf("slider_high.maxval=%i", total_steps);
|
||||
disp1->send_command_printf("slider_low.maxval=%i", total_steps);
|
||||
@@ -2636,7 +2549,6 @@ script:
|
||||
}
|
||||
disp1->set_component_value("embedded", (embedded_climate) ? 1 : 0);
|
||||
}
|
||||
ESP_LOGD(TAG, "Finished");
|
||||
|
||||
- id: set_component_visibility
|
||||
mode: queued
|
||||
@@ -2657,26 +2569,17 @@ script:
|
||||
mode: restart
|
||||
then:
|
||||
- lambda: |-
|
||||
static const char *const TAG = "script.setup_sequence";
|
||||
ESP_LOGD(TAG, "Starting Nextion setup sequence");
|
||||
ESP_LOGD(TAG, "Fetching Page Id");
|
||||
page_id->update();
|
||||
- wait_until:
|
||||
condition:
|
||||
- lambda: !lambda return (not isnan(page_id->state));
|
||||
timeout: 15s
|
||||
- lambda: |-
|
||||
static const char *const TAG = "script.setup_sequence";
|
||||
ESP_LOGD(TAG, "Fetching charset");
|
||||
display_charset->update();
|
||||
- lambda: display_charset->update();
|
||||
- wait_until:
|
||||
condition:
|
||||
- lambda: !lambda return (not isnan(display_charset->state));
|
||||
timeout: 5s
|
||||
- lambda: |-
|
||||
static const char *const TAG = "script.setup_sequence";
|
||||
ESP_LOGD(TAG, "Fetching display mode");
|
||||
display_mode->update();
|
||||
- lambda: display_mode->update();
|
||||
- wait_until:
|
||||
condition:
|
||||
- lambda: !lambda return (not isnan(display_mode->state));
|
||||
@@ -2686,18 +2589,12 @@ script:
|
||||
- lambda: !lambda return (not isnan(display_mode->state));
|
||||
then: # Project's TFT detected
|
||||
- lambda: |-
|
||||
static const char *const TAG = "script.setup_sequence";
|
||||
ESP_LOGD(TAG, "Goto page Boot");
|
||||
goto_page->execute("boot");
|
||||
ESP_LOGD(TAG, "Fetching TFT version");
|
||||
version_tft->update();
|
||||
- wait_until:
|
||||
condition:
|
||||
- lambda: !lambda return (not version_tft->state.empty());
|
||||
timeout: 5s
|
||||
- lambda: |-
|
||||
static const char *const TAG = "script.setup_sequence";
|
||||
ESP_LOGD(TAG, "Wait for Wi-Fi");
|
||||
- wait_until:
|
||||
condition:
|
||||
- lambda: !lambda return (wifi_component->is_connected());
|
||||
@@ -2707,13 +2604,10 @@ script:
|
||||
- lambda: !lambda return (wifi_component->is_connected());
|
||||
then: # Wi-Fi connected
|
||||
- lambda: |-
|
||||
static const char *const TAG = "script.setup_sequence";
|
||||
if (current_page->state == "boot") {
|
||||
ESP_LOGD(TAG, "Publish IP address on screen");
|
||||
disp1->set_component_text_printf("boot.ip_addr", "%s", network::get_ip_address().str().c_str());
|
||||
set_brightness->execute(100);
|
||||
}
|
||||
ESP_LOGD(TAG, "Wait for API");
|
||||
- wait_until:
|
||||
condition:
|
||||
- lambda: !lambda return (api_server->is_connected());
|
||||
@@ -2723,41 +2617,23 @@ script:
|
||||
- lambda: !lambda return (api_server->is_connected());
|
||||
then: # API connected
|
||||
- lambda: |-
|
||||
static const char *const TAG = "script.setup_sequence";
|
||||
ESP_LOGD(TAG, "Publish IP address on screen");
|
||||
ESP_LOGD(TAG, "Report setup to Home Assistant");
|
||||
auto ha_event = new esphome::api::CustomAPIDevice();
|
||||
ha_event->fire_homeassistant_event("esphome.nspanel_ha_blueprint",
|
||||
{
|
||||
{"type", "boot"},
|
||||
{"step", "start"}
|
||||
});
|
||||
else: # API not connected
|
||||
- lambda: |-
|
||||
static const char *const TAG = "script.setup_sequence";
|
||||
ESP_LOGE(TAG, "API not available");
|
||||
else: # Wi-Fi not connected
|
||||
- lambda: |-
|
||||
static const char *const TAG = "script.setup_sequence";
|
||||
ESP_LOGE(TAG, "Wi-Fi not available");
|
||||
- lambda: |-
|
||||
static const char *const TAG = "script.setup_sequence";
|
||||
ESP_LOGE(TAG, "Wi-Fi not available");
|
||||
- wait_until:
|
||||
condition:
|
||||
- lambda: !lambda return id(setup_sequence_completed);
|
||||
timeout: 1s
|
||||
- lambda: |-
|
||||
static const char *const TAG = "script.setup_sequence";
|
||||
ESP_LOGD(TAG, "Set dimming values");
|
||||
set_brightness->execute(display_brightness->state);
|
||||
ESP_LOGD(TAG, "Set page Settings");
|
||||
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));
|
||||
ESP_LOGD(TAG, "Report to Home Assistant");
|
||||
nextion_init->publish_state(disp1->is_setup());
|
||||
if (api_server->is_connected() and disp1->is_setup()) {
|
||||
auto ha_event = new esphome::api::CustomAPIDevice();
|
||||
@@ -2768,12 +2644,10 @@ script:
|
||||
});
|
||||
}
|
||||
// Chips icon size
|
||||
ESP_LOGV(TAG, "Adjusting icon's sizes");
|
||||
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
|
||||
ESP_LOGV(TAG, "Adjusting custom buttons sizes");
|
||||
for (int i = 1; i <= 7; ++i) {
|
||||
disp1->send_command_printf("home.button%02d.font=%i", i, id(home_custom_buttons_font_id));
|
||||
}
|
||||
@@ -2781,13 +2655,11 @@ script:
|
||||
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));
|
||||
ESP_LOGV(TAG, "Restoring relay's icon colors");
|
||||
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");
|
||||
notification_clear->execute();
|
||||
id(setup_sequence_completed) = true;
|
||||
ESP_LOGD(TAG, "Wait for leaving boot page");
|
||||
- wait_until:
|
||||
condition:
|
||||
- not:
|
||||
@@ -2797,21 +2669,12 @@ script:
|
||||
timeout: 10s
|
||||
- lambda: |-
|
||||
if (current_page->state == "boot") goto_page->execute(wakeup_page_name->state.c_str());
|
||||
else: # Unknown TFT
|
||||
- lambda: |-
|
||||
static const char *const TAG = "script.setup_sequence";
|
||||
ESP_LOGE(TAG, "No compatible TFT detected");
|
||||
ESP_LOGE(TAG, "Display mode: %f", display_mode->state);
|
||||
- lambda: |-
|
||||
static const char *const TAG = "script.setup_sequence";
|
||||
ESP_LOGD(TAG, "Nextion setup sequence finished!");
|
||||
- logger.log: "Nextion setup sequence finished!"
|
||||
|
||||
- id: stop_all
|
||||
mode: restart
|
||||
then:
|
||||
- lambda: |-
|
||||
static const char *const TAG = "script.stop_all";
|
||||
ESP_LOGD(TAG, "Stopping scripts...");
|
||||
change_climate_state->stop();
|
||||
check_versions->stop();
|
||||
display_embedded_temp->stop();
|
||||
@@ -2819,7 +2682,6 @@ script:
|
||||
global_settings->stop();
|
||||
ha_button->stop();
|
||||
ha_call_service->stop();
|
||||
nextion_status->stop();
|
||||
notification_clear->stop();
|
||||
page_alarm->stop();
|
||||
page_blank->stop();
|
||||
@@ -2867,7 +2729,6 @@ script:
|
||||
timer_sleep->stop();
|
||||
update_alarm_icon->stop();
|
||||
update_climate_icon->stop();
|
||||
ESP_LOGD(TAG, "Finished");
|
||||
|
||||
###### Timers ######
|
||||
- id: timer_reset_all # Global timer reset - Triggered with a touch on the screen
|
||||
|
||||
Reference in New Issue
Block a user