Reduce number of calls to Nextion - Relay and buttons bars
Helps with #1949
This commit is contained in:
@@ -119,9 +119,6 @@ ota:
|
||||
##### Adds custom library for NSPanel HA Blueprint project
|
||||
nspanel_ha_blueprint:
|
||||
|
||||
##### JSON - Used to parse json and for Upload TFT #####
|
||||
json:
|
||||
|
||||
##### LOGGER #####
|
||||
logger:
|
||||
id: logger_std
|
||||
@@ -154,9 +151,10 @@ time:
|
||||
on_time:
|
||||
- seconds: 0
|
||||
then:
|
||||
- script.execute: refresh_datetime
|
||||
- script.execute: refresh_relays
|
||||
- script.execute: refresh_hardware_buttons_bars
|
||||
- lambda:
|
||||
refresh_datetime->execute();
|
||||
refresh_relays->execute(3);
|
||||
refresh_hardware_buttons_bars->execute(3);
|
||||
|
||||
on_time_sync:
|
||||
then:
|
||||
@@ -289,7 +287,7 @@ api:
|
||||
if (button_mask & 2) // Checks if the second least significant bit is set (right button)
|
||||
update_bitwise_setting(id(buttons_settings), state, ButtonSettings::ButtonRight_State);
|
||||
// Refreshes the indication bars on the display
|
||||
refresh_hardware_buttons_bars->execute();
|
||||
refresh_hardware_buttons_bars->execute(button_mask);
|
||||
|
||||
# Icon Service
|
||||
- service: icon
|
||||
@@ -400,7 +398,8 @@ api:
|
||||
button_bar_color_off[2]));
|
||||
|
||||
// Refresh relays display
|
||||
refresh_relays->execute();
|
||||
refresh_relays->execute(3);
|
||||
refresh_hardware_buttons_bars->execute(3);
|
||||
}
|
||||
blueprint_status->publish_state(int(blueprint_status->raw_state) | (1 << 4));
|
||||
# Sets up the "Home" page in ESPHome with customized settings and UI elements as defined in the project blueprint.
|
||||
@@ -1583,10 +1582,14 @@ switch:
|
||||
restore_mode: RESTORE_DEFAULT_OFF
|
||||
on_turn_on:
|
||||
then:
|
||||
- script.execute: refresh_relays
|
||||
- lambda:
|
||||
refresh_relays->execute(1);
|
||||
refresh_hardware_buttons_bars->execute(1);
|
||||
on_turn_off:
|
||||
then:
|
||||
- script.execute: refresh_relays
|
||||
- lambda:
|
||||
refresh_relays->execute(1);
|
||||
refresh_hardware_buttons_bars->execute(1);
|
||||
##### PHYSICAL SWITCH 2 ######
|
||||
- name: Relay 2
|
||||
platform: gpio
|
||||
@@ -1596,10 +1599,14 @@ switch:
|
||||
restore_mode: RESTORE_DEFAULT_OFF
|
||||
on_turn_on:
|
||||
then:
|
||||
- script.execute: refresh_relays
|
||||
- lambda:
|
||||
refresh_relays->execute(2);
|
||||
refresh_hardware_buttons_bars->execute(2);
|
||||
on_turn_off:
|
||||
then:
|
||||
- script.execute: refresh_relays
|
||||
- lambda:
|
||||
refresh_relays->execute(2);
|
||||
refresh_hardware_buttons_bars->execute(2);
|
||||
|
||||
##### DISPLAY ALWAYS ON #####
|
||||
- name: Nextion display - Power
|
||||
@@ -1733,7 +1740,7 @@ text_sensor:
|
||||
const cJSON* title = cJSON_GetObjectItemCaseSensitive(json, "mui");
|
||||
if (json_cmp_string(code_format, "number") and (json_cmp_string(key, "disarm") or json_cmp_string(code_arm_req, "1"))) {
|
||||
goto_page->execute("keyb_num");
|
||||
disp1->set_component_value("keyb_num.page_id", 23); //Calling from Alarm page
|
||||
disp1->set_component_value("keyb_num.page_id", get_page_id("alarm")); //Calling from Alarm page
|
||||
disp1->set_component_text("keyb_num.domain", page->valuestring);
|
||||
disp1->set_component_text("keyb_num.key", key->valuestring);
|
||||
disp1->set_component_text("keyb_num.value", value->valuestring);
|
||||
@@ -1762,7 +1769,7 @@ text_sensor:
|
||||
if (json_cmp_string(key, "volume_mute"))
|
||||
ha_call_service->execute("media_player.volume_mute", "is_volume_muted", value->valuestring, detailed_entity->state.c_str());
|
||||
else if (json_cmp_string(key, "volume_set"))
|
||||
ha_call_service->execute("media_player.volume_set", "volume_level", json_percentage_to_float_string(value).c_str()), detailed_entity->state.c_str());
|
||||
ha_call_service->execute("media_player.volume_set", "volume_level", json_percentage_to_float_string(value).c_str(), detailed_entity->state.c_str());
|
||||
else if ((key != NULL and key->valuestring != NULL and key->valuestring[0] != '\0'))
|
||||
ha_call_service->execute((std::string("media_player.") + key->valuestring), "", "", detailed_entity->state.c_str());
|
||||
}
|
||||
@@ -2199,7 +2206,7 @@ script:
|
||||
ESP_LOGD("script.page_changed", "Entity shown: %s", detailed_entity->state.c_str());
|
||||
|
||||
// Update buttons bars on screen
|
||||
refresh_hardware_buttons_bars->execute();
|
||||
refresh_hardware_buttons_bars->execute(3);
|
||||
|
||||
// Reset timers
|
||||
if (current_page->state != "screensaver") timer_reset_all->execute();
|
||||
@@ -2245,7 +2252,7 @@ script:
|
||||
else if (current_page->state == "weather04") page_weather04->execute();
|
||||
else if (current_page->state == "weather05") page_weather05->execute();
|
||||
- delay: 1s
|
||||
- script.execute: refresh_hardware_buttons_bars
|
||||
- lambda: refresh_hardware_buttons_bars->execute(3);
|
||||
|
||||
- id: page_climate
|
||||
mode: restart
|
||||
@@ -2308,8 +2315,9 @@ script:
|
||||
- id: page_home
|
||||
mode: restart
|
||||
then:
|
||||
- script.execute: refresh_relays
|
||||
- script.execute: refresh_wifi_icon
|
||||
- lambda:
|
||||
refresh_relays->execute(3);
|
||||
refresh_wifi_icon->execute();
|
||||
|
||||
- id: page_keyb_num
|
||||
mode: restart
|
||||
@@ -2428,6 +2436,8 @@ script:
|
||||
|
||||
- id: refresh_hardware_buttons_bars
|
||||
mode: restart
|
||||
parameters:
|
||||
button_mask: uint8_t
|
||||
then:
|
||||
- lambda: |-
|
||||
#if ESPHOME_LOG_LEVEL > ESPHOME_LOG_LEVEL_DEBUG
|
||||
@@ -2435,11 +2445,12 @@ script:
|
||||
ESP_LOGV("script.refresh_hardware_buttons_bars", "Page id: %i", get_page_id(current_page->state.c_str()));
|
||||
ESP_LOGV("script.refresh_hardware_buttons_bars", "buttons_bars_pages: %i", id(buttons_bars_pages));
|
||||
ESP_LOGV("script.refresh_hardware_buttons_bars", "relay_settings: %i", id(relay_settings));
|
||||
ESP_LOGV("script.refresh_hardware_buttons_bars", "button_mask: %i", button_mask);
|
||||
#endif
|
||||
if (!id(is_uploading_tft) and ((id(buttons_bars_pages) & (1 << get_page_id(current_page->state.c_str()))) != 0)) {
|
||||
switch (int(display_mode->state)) {
|
||||
case 1: // EU model
|
||||
if (id(buttons_settings) & ButtonSettings::ButtonLeft_Enabled) { // Left button
|
||||
if (button_mask & 1 and id(buttons_settings) & ButtonSettings::ButtonLeft_Enabled) { // Left button
|
||||
disp1->fill_area(48, 307, 118, 3,
|
||||
(((id(relay_settings) & RelaySettings::Relay1_Local) and relay_1->state) or (id(buttons_settings) & ButtonSettings::ButtonLeft_State)) ?
|
||||
id(buttons_color_on) : id(buttons_color_off));
|
||||
@@ -2447,7 +2458,7 @@ script:
|
||||
(((id(relay_settings) & RelaySettings::Relay1_Local) and relay_1->state) or (id(buttons_settings) & ButtonSettings::ButtonLeft_State)) ?
|
||||
id(buttons_color_on) : id(buttons_color_off));
|
||||
}
|
||||
if (id(buttons_settings) & ButtonSettings::ButtonRight_Enabled) { // Right button
|
||||
if (button_mask & 2 and id(buttons_settings) & ButtonSettings::ButtonRight_Enabled) { // Right button
|
||||
disp1->fill_area(289, 307, 118, 3,
|
||||
(((id(relay_settings) & RelaySettings::Relay2_Local) and relay_2->state) or (id(buttons_settings) & ButtonSettings::ButtonRight_State)) ?
|
||||
id(buttons_color_on) : id(buttons_color_off));
|
||||
@@ -2457,7 +2468,7 @@ script:
|
||||
}
|
||||
break;
|
||||
case 2: // US Portrait
|
||||
if (id(buttons_settings) & ButtonSettings::ButtonLeft_Enabled) { // Left button
|
||||
if (button_mask & 1 and id(buttons_settings) & ButtonSettings::ButtonLeft_Enabled) { // Left button
|
||||
disp1->fill_area(17, 466, 118, 3,
|
||||
(((id(relay_settings) & RelaySettings::Relay1_Local) and relay_1->state) or (id(buttons_settings) & ButtonSettings::ButtonLeft_State)) ?
|
||||
id(buttons_color_on) : id(buttons_color_off));
|
||||
@@ -2465,7 +2476,7 @@ script:
|
||||
(((id(relay_settings) & RelaySettings::Relay1_Local) and relay_1->state) or (id(buttons_settings) & ButtonSettings::ButtonLeft_State)) ?
|
||||
id(buttons_color_on) : id(buttons_color_off));
|
||||
}
|
||||
if (id(buttons_settings) & ButtonSettings::ButtonRight_Enabled) { // Right button
|
||||
if (button_mask & 2 and id(buttons_settings) & ButtonSettings::ButtonRight_Enabled) { // Right button
|
||||
disp1->fill_area(184, 466, 118, 3,
|
||||
(((id(relay_settings) & RelaySettings::Relay2_Local) and relay_2->state) or (id(buttons_settings) & ButtonSettings::ButtonRight_State)) ?
|
||||
id(buttons_color_on) : id(buttons_color_off));
|
||||
@@ -2475,7 +2486,7 @@ script:
|
||||
}
|
||||
break;
|
||||
case 3: // US Landscape
|
||||
if (id(buttons_settings) & ButtonSettings::ButtonLeft_Enabled) { // Left button
|
||||
if (button_mask & 1 and id(buttons_settings) & ButtonSettings::ButtonLeft_Enabled) { // Left button
|
||||
disp1->fill_area(467, 174, 3, 118,
|
||||
(((id(relay_settings) & RelaySettings::Relay1_Local) and relay_1->state) or (id(buttons_settings) & ButtonSettings::ButtonLeft_State)) ?
|
||||
id(buttons_color_on) : id(buttons_color_off));
|
||||
@@ -2483,7 +2494,7 @@ script:
|
||||
(((id(relay_settings) & RelaySettings::Relay1_Local) and relay_1->state) or (id(buttons_settings) & ButtonSettings::ButtonLeft_State)) ?
|
||||
id(buttons_color_on) : id(buttons_color_off));
|
||||
}
|
||||
if (id(buttons_settings) & ButtonSettings::ButtonRight_Enabled) { // Right button
|
||||
if (button_mask & 2 and id(buttons_settings) & ButtonSettings::ButtonRight_Enabled) { // Right button
|
||||
disp1->fill_area(467, 28, 3, 118,
|
||||
(((id(relay_settings) & RelaySettings::Relay2_Local) and relay_2->state) or (id(buttons_settings) & ButtonSettings::ButtonRight_State)) ?
|
||||
id(buttons_color_on) : id(buttons_color_off));
|
||||
@@ -2497,18 +2508,19 @@ script:
|
||||
|
||||
- id: refresh_relays
|
||||
mode: restart
|
||||
parameters:
|
||||
relay_mask: uint8_t
|
||||
then:
|
||||
- lambda: |-
|
||||
// Chips - Relays
|
||||
disp1->set_component_text("home.chip_relay1", (relay_1->state) ? id(home_relay1_icon) : "\uFFFF");
|
||||
disp1->set_component_text("home.chip_relay2", (relay_2->state) ? id(home_relay2_icon) : "\uFFFF");
|
||||
refresh_hardware_buttons_bars->execute();
|
||||
if (!id(is_uploading_tft) and relay_mask & 1) disp1->set_component_text("home.chip_relay1", (relay_1->state) ? id(home_relay1_icon) : "\uFFFF");
|
||||
if (!id(is_uploading_tft) and relay_mask & 2) disp1->set_component_text("home.chip_relay2", (relay_2->state) ? id(home_relay2_icon) : "\uFFFF");
|
||||
|
||||
- id: refresh_wifi_icon
|
||||
mode: restart
|
||||
then:
|
||||
- lambda: |-
|
||||
if (nextion_init->state) {
|
||||
if (!id(is_uploading_tft) and nextion_init->state) {
|
||||
disp1->send_command_printf("api=%i", (wifi_component->is_connected() and api_server->is_connected() and blueprint_status->state > 99) ? 1 : 0);
|
||||
// Update Wi-Fi icon color
|
||||
disp1->set_component_font_color("home.wifi_icon", (blueprint_status->state > 99) ? (wifi_rssi->state > -70 ? 33808 : 64992) : 63488);
|
||||
|
||||
Reference in New Issue
Block a user