diff --git a/nspanel_blueprint.yaml b/nspanel_blueprint.yaml index eb63b42..5c1f855 100644 --- a/nspanel_blueprint.yaml +++ b/nspanel_blueprint.yaml @@ -6420,7 +6420,7 @@ action: service: '{{ nextion.command.text_printf }}' data: component: home.entity - message: '{{ climate }}' + message: '{{ "embedded_climate" if climate == thermostat_embedded else climate }}' continue_on_error: true ##### Weather Icon Home Page ##### @@ -7592,7 +7592,8 @@ action: sequence: &refresh_page_climate - &variables-climate_entity variables: - climate_entity: '{{ nspanel_event.entity if nspanel_event.entity is defined }}' + climate_entity_temp: '{{ nspanel_event.entity if nspanel_event.entity is defined }}' + climate_entity: '{{ thermostat_embedded if climate_entity_temp == "embedded_climate" else climate_entity_temp }}' settings_entity_domain: > {{ climate_entity.split(".")[0] @@ -7610,6 +7611,7 @@ action: component: page_label message: '{{ state_attr(climate_entity, "friendly_name") }}' continue_on_error: true + ##### Values ##### - &variables-climate_page variables: @@ -8406,7 +8408,7 @@ action: page_label: '{{ (button_context.name | replace("\\r", " ")) if button_context.name is string and button_context.name | length > 0 else state_attr(button_context.entity, "friendly_name") }}' page_icon: '{{ nextion.icon.domain[button_domain] }}' page_icon_color: -1 #No color set - entity: '{{ button_context.entity }}' + entity: '{{ "embedded_climate" if button_context.entity == thermostat_embedded else button_context.entity }}' back_page: '{{ page.home }}' continue_on_error: true - alias: Custom action - Left @@ -8467,7 +8469,7 @@ action: page_label: '{{ state_attr(climate, "friendly_name") }}' page_icon: '' page_icon_color: -1 #No color set - entity: '{{ climate }}' + entity: '{{ "embedded_climate" if climate == thermostat_embedded else climate }}' back_page: '{{ page.home }}' continue_on_error: true @@ -8635,7 +8637,7 @@ action: if is_number(last_click_button.icon_color_rgb) else ((last_click_button.icon_color_rgb[0] //(2**3)) *(2**11))+((last_click_button.icon_color_rgb[1] //(2**2)) *(2**5))+(last_click_button.icon_color_rgb[2] //(2**3)) }} - entity: '{{ last_click_button.entity }}' + entity: '{{ "embedded_climate" if last_click_button.entity == thermostat_embedded else last_click_button.entity }}' back_page: '{{ nspanel_event.page }}' continue_on_error: true else: # Short press diff --git a/nspanel_esphome.yaml b/nspanel_esphome.yaml index 78a363d..52b284f 100644 --- a/nspanel_esphome.yaml +++ b/nspanel_esphome.yaml @@ -268,9 +268,16 @@ api: entity: string back_page: string then: - - wait_until: - binary_sensor.is_on: nextion_init + #- wait_until: + # binary_sensor.is_on: nextion_init - lambda: |- + ESP_LOGV("api.service.open_entity_settings_page", "Starting"); + ESP_LOGV("api.service.open_entity_settings_page", "page: %s", page.c_str()); + ESP_LOGV("api.service.open_entity_settings_page", "page_label: %s", page_label.c_str()); + ESP_LOGV("api.service.open_entity_settings_page", "page_icon: %s", page_icon.c_str()); + ESP_LOGV("api.service.open_entity_settings_page", "page_icon_color: %i", page_icon_color); + ESP_LOGV("api.service.open_entity_settings_page", "entity: %s", entity.c_str()); + ESP_LOGV("api.service.open_entity_settings_page", "back_page: %s", back_page.c_str()); id(disp1).set_component_text_printf("home.entity", "%s", entity.c_str()); std::string cmd_page = std::string("page ") + page.c_str(); id(disp1).send_command_printf(cmd_page.c_str()); @@ -284,6 +291,7 @@ api: { id(disp1).set_component_font_color("icon_state", page_icon_color); } + ESP_LOGV("api.service.open_entity_settings_page", "Finished"); ##### Service to play a rtttl tones ##### # Example tones : https://codebender.cc/sketch:109888#RTTTL%20Songs.ino @@ -1006,6 +1014,7 @@ text_sensor: on_value: then: - lambda: |- + ESP_LOGV("text_sensor.nspanelevent", "Starting"); id(page_timer)->execute(int(id(page_timeout).state)); DynamicJsonDocument doc(1024); deserializeJson(doc, x); @@ -1013,6 +1022,10 @@ text_sensor: std::string component = doc["component"]; std::string value = doc["value"]; std::string entity = doc["entity"]; + ESP_LOGV("text_sensor.nspanelevent", "page: %s", page.c_str()); + ESP_LOGV("text_sensor.nspanelevent", "component: %s", component.c_str()); + ESP_LOGV("text_sensor.nspanelevent", "value: %s", value.c_str()); + ESP_LOGV("text_sensor.nspanelevent", "entity: %s", entity.c_str()); auto ha_event = new esphome::api::CustomAPIDevice(); ha_event->fire_homeassistant_event("esphome.nspanel_ha_blueprint", { @@ -1024,18 +1037,32 @@ text_sensor: }); if (component=="currentpage") { - ESP_LOGD("nspanelevent", "New page: %s", page.c_str()); + ESP_LOGV("text_sensor.nspanelevent", "New page: %s", page.c_str()); + ESP_LOGV("text_sensor.nspanelevent", "Trigger HA event"); ha_event->fire_homeassistant_event("esphome.nspanel_ha_blueprint", { {"type", "page_changed"}, {"page", page}, {"entity", entity} }); + ESP_LOGV("text_sensor.nspanelevent", "Call add-ons scripts for new page"); + id(addon_climate_set_climate).execute(page=="climate" and entity=="embedded_climate"); + ESP_LOGV("text_sensor.nspanelevent", "Publish current_page sensor"); id(current_page).publish_state(page); - if (page=="home") id(update_page_home).execute(); - else if (page=="screensaver") id(disp1).set_component_value("orign", id(wakeup_page_id)); + ESP_LOGV("text_sensor.nspanelevent", "Construct new page"); + if (page=="home") + { + ESP_LOGV("text_sensor.nspanelevent", "Construct home page"); + id(update_page_home).execute(); + } + else if (page=="screensaver") + { + ESP_LOGV("text_sensor.nspanelevent", "Construct screensaver page"); + id(disp1).set_component_value("orign", id(wakeup_page_id)); + } else if (page=="climate") { + ESP_LOGV("text_sensor.nspanelevent", "Construct climate page"); id(disp1).set_component_text_printf("climate.button01_icon", "%s", "\uEE8D"); //mdi:calendar-sync id(disp1).set_component_text_printf("climate.button02_icon", "%s", "\uE069"); //mdi:autorenew id(disp1).set_component_text_printf("climate.button03_icon", "%s", "\uE237"); //mdi:fire @@ -1043,10 +1070,11 @@ text_sensor: id(disp1).set_component_text_printf("climate.button05_icon", "%s", "\uE58D"); //mdi:water-percent id(disp1).set_component_text_printf("climate.button06_icon", "%s", "\uE20F"); //mdi:fan id(disp1).set_component_text_printf("climate.button07_icon", "%s", "\uE424"); //mdi:power - id(addon_climate_update_page_climate); + id(addon_climate_update_page_climate)->execute(); } else if (page=="fan") { + ESP_LOGV("text_sensor.nspanelevent", "Construct fan page"); id(disp1).set_component_text_printf("fan.button_on", "%s", "\uE20F"); //mdi:fan id(disp1).set_component_text_printf("fan.button_off", "%s", "\uE81C"); //mdi:fan-off id(disp1).set_component_text_printf("fan.button_up", "%s", "\uF46D"); //mdi:fan-chevron-up @@ -1054,6 +1082,7 @@ text_sensor: } else if (page=="keyb_num") { + ESP_LOGV("text_sensor.nspanelevent", "Construct keyb_num page"); id(disp1).set_component_text_printf("keyb_num.bview", "%s", "\uE207"); //mdi:eye id(disp1).set_component_text_printf("keyb_num.bclose", "%s", "\uE158"); //mdi:close-circle id(disp1).set_component_text_printf("keyb_num.bclear", "%s", "\uE641"); //mdi:eraser-variant @@ -1062,13 +1091,18 @@ text_sensor: } else if (page=="boot" and component=="timeout") { + ESP_LOGV("text_sensor.nspanelevent", "Trigger boot timeout event"); ha_event->fire_homeassistant_event("esphome.nspanel_ha_blueprint", { {"type", "boot"}, {"step", "timeout"}, {"value", value} }); - if (stof(value) >= 5) id(disp1).send_command_printf("page %i", id(wakeup_page_id)); + if (stof(value) >= 5) + { + ESP_LOGV("text_sensor.nspanelevent", "Jump to wakeup page: %i", id(wakeup_page_id)); + id(disp1).send_command_printf("page %i", id(wakeup_page_id)); + } } ##### NSPanel event - Execute actions from ESPHome - NO push to HA ##### @@ -1444,6 +1478,7 @@ script: climate_icon: string embedded_climate: bool then: + - lambda: ESP_LOGV("script.set_climate", "Starting"); - if: condition: - binary_sensor.is_on: nextion_init @@ -1488,6 +1523,7 @@ script: id(disp1).hide_component("increase_temp"); } id(disp1).set_component_value("embedded", (embedded_climate) ? 1 : 0); + - lambda: ESP_LOGV("script.set_climate", "Finished"); - id: refresh_colors ## Refresh colors of global components mode: restart @@ -1590,6 +1626,14 @@ script: - script.execute: refresh_relays - script.execute: refresh_wifi_icon - script.execute: addon_climate_update_page_home + # Show panel's temperature if API is out + - if: + condition: + - not: + api.connected: + then: + - lambda: id(disp1).set_component_text_printf("home.current_temp", "%.1f°", id(temp_nspanel).state); + - lambda: ESP_LOGV("script.update_page_home", "Finished"); - id: service_call_alarm_control_panel @@ -1790,6 +1834,7 @@ script: # Reserved for Add-on Climate - lambda: |- ESP_LOGV("script.addon_climate_set_climate", "Starting"); + ESP_LOGV("script.addon_climate_set_climate", "embedded_climate: %i", (embedded_climate) ? 1 : 0); ESP_LOGV("script.addon_climate_set_climate", "Finished"); - id: addon_climate_global_settings mode: restart diff --git a/nspanel_esphome_addon_climate_cool.yaml b/nspanel_esphome_addon_climate_cool.yaml index dc9bb10..0b27952 100644 --- a/nspanel_esphome_addon_climate_cool.yaml +++ b/nspanel_esphome_addon_climate_cool.yaml @@ -1,5 +1,5 @@ #################################################################################################### -##### NSPanel ESPHome Add-on for Climate control - Heat ##### +##### NSPanel ESPHome Add-on for Climate control - Cool ##### ##### Add-on for https://github.com/Blackymas/NSPanel_HA_Blueprint ##### #################################################################################################### @@ -7,7 +7,7 @@ substitutions: ### Local thermostat defaults ### # https://esphome.io/components/climate/thermostat.html temp_units: "°C" - heater_relay: "0" # Select 1 for "Relay 1", 2 for "Relay 2" or "0" to a dummy switch/disabled + cooler_relay: "0" # Select 1 for "Relay 1", 2 for "Relay 2" or "0" to a dummy switch/disabled min_off_time: "300" min_run_time: "300" min_idle_time: "30" @@ -21,17 +21,17 @@ climate: name: ${device_name} Thermostat id: thermostat_embedded sensor: temp_nspanel - min_heating_off_time: ${min_off_time}s - min_heating_run_time: ${min_run_time}s + min_cooling_off_time: ${min_off_time}s + min_cooling_run_time: ${min_run_time}s min_idle_time: ${min_idle_time}s visual: min_temperature: ${temp_min} ${temp_units} max_temperature: ${temp_max} ${temp_units} temperature_step: ${temp_step} ${temp_units} - heat_action: - - switch.turn_on: relay_${heater_relay} + cool_action: + - switch.turn_on: relay_${cooler_relay} idle_action: - - switch.turn_off: relay_${heater_relay} + - switch.turn_off: relay_${cooler_relay} default_preset: "Off" on_boot_restore_from: memory preset: @@ -63,15 +63,15 @@ script: - id: !extend addon_climate_update_page_home mode: restart then: + - lambda: ESP_LOGV("script.addon_climate_update_page_home", "Starting"); - if: condition: - binary_sensor.is_on: nextion_init then: - lambda: |- // Update home.entity variable + ESP_LOGV("script.addon_climate_update_page_home", "Update home.entity variable: %s", (id(is_embedded_thermostat)) ? "embedded_climate" : ""); id(disp1).set_component_text_printf("home.entity", (id(is_embedded_thermostat)) ? "embedded_climate" : ""); - //if (id(is_embedded_thermostat)) id(disp1).set_component_text_printf("home.entity", "embedded_climate"); - //else id(disp1).set_component_text_printf("home.entity", ""); - if: condition: @@ -79,6 +79,7 @@ script: then: - lambda: |- // Update chips + ESP_LOGV("script.addon_climate_update_page_home", "Update chips"); ESP_LOGV("script.refresh_chips_climate", "thermostat_embedded.action=%i", int(id(thermostat_embedded).action)); switch (int(id(thermostat_embedded).action)) // CLIMATE_ACTION_OFF = 0, CLIMATE_ACTION_COOLING = 2, CLIMATE_ACTION_HEATING = 3, CLIMATE_ACTION_IDLE = 4, CLIMATE_ACTION_DRYING = 5, CLIMATE_ACTION_FAN = 6 { @@ -136,6 +137,7 @@ script: id(disp1).set_component_font_color("home.icon_top_03", 1530); break; } + - lambda: ESP_LOGV("script.addon_climate_update_page_home", "Finished"); - id: !extend addon_climate_service_call then: @@ -158,6 +160,7 @@ script: then: - lambda: |- ESP_LOGV("script.addon_climate_set_climate", "Starting"); + ESP_LOGV("script.addon_climate_set_climate", "embedded_climate: %i", (embedded_climate) ? 1 : 0); id(is_addon_climate_visible) = embedded_climate; ESP_LOGV("script.addon_climate_set_climate", "Finished"); @@ -165,19 +168,24 @@ script: then: - lambda: |- ESP_LOGV("script.addon_climate_global_settings", "Starting"); + ESP_LOGV("script.addon_climate_global_settings", "embedded_climate: %i", (embedded_climate) ? 1 : 0); id(is_embedded_thermostat) = embedded_climate; ESP_LOGV("script.addon_climate_global_settings", "Finished"); - id: !extend addon_climate_update_page_climate then: - - lambda: ESP_LOGV("script.addon_climate_update_page_climate", "Starting"); + - lambda: |- + ESP_LOGV("script.addon_climate_update_page_climate", "Starting"); + ESP_LOGV("script.addon_climate_update_page_climate", "nextion_init: %i", (id(nextion_init)) ? 1 : 0); + ESP_LOGV("script.addon_climate_update_page_climate", "current_page: %s", id(current_page).state.c_str()); + ESP_LOGV("script.addon_climate_update_page_climate", "is_addon_climate_visible: %i", (id(is_addon_climate_visible)) ? 1 : 0); - if: condition: - binary_sensor.is_on: nextion_init - text_sensor.state: # Is climate page visible? id: current_page state: 'climate' - - lambda: !lambda return id(is_addon_climate_visible); + - lambda: !lambda return (id(is_addon_climate_visible)); then: # Embedded thermostat is visible # Update slider, current temperature & target temperature - script.execute: diff --git a/nspanel_esphome_addon_climate_heat.yaml b/nspanel_esphome_addon_climate_heat.yaml index dc9bb10..a302c2c 100644 --- a/nspanel_esphome_addon_climate_heat.yaml +++ b/nspanel_esphome_addon_climate_heat.yaml @@ -63,15 +63,15 @@ script: - id: !extend addon_climate_update_page_home mode: restart then: + - lambda: ESP_LOGV("script.addon_climate_update_page_home", "Starting"); - if: condition: - binary_sensor.is_on: nextion_init then: - lambda: |- // Update home.entity variable + ESP_LOGV("script.addon_climate_update_page_home", "Update home.entity variable: %s", (id(is_embedded_thermostat)) ? "embedded_climate" : ""); id(disp1).set_component_text_printf("home.entity", (id(is_embedded_thermostat)) ? "embedded_climate" : ""); - //if (id(is_embedded_thermostat)) id(disp1).set_component_text_printf("home.entity", "embedded_climate"); - //else id(disp1).set_component_text_printf("home.entity", ""); - if: condition: @@ -79,6 +79,7 @@ script: then: - lambda: |- // Update chips + ESP_LOGV("script.addon_climate_update_page_home", "Update chips"); ESP_LOGV("script.refresh_chips_climate", "thermostat_embedded.action=%i", int(id(thermostat_embedded).action)); switch (int(id(thermostat_embedded).action)) // CLIMATE_ACTION_OFF = 0, CLIMATE_ACTION_COOLING = 2, CLIMATE_ACTION_HEATING = 3, CLIMATE_ACTION_IDLE = 4, CLIMATE_ACTION_DRYING = 5, CLIMATE_ACTION_FAN = 6 { @@ -136,6 +137,7 @@ script: id(disp1).set_component_font_color("home.icon_top_03", 1530); break; } + - lambda: ESP_LOGV("script.addon_climate_update_page_home", "Finished"); - id: !extend addon_climate_service_call then: @@ -158,6 +160,7 @@ script: then: - lambda: |- ESP_LOGV("script.addon_climate_set_climate", "Starting"); + ESP_LOGV("script.addon_climate_set_climate", "embedded_climate: %i", (embedded_climate) ? 1 : 0); id(is_addon_climate_visible) = embedded_climate; ESP_LOGV("script.addon_climate_set_climate", "Finished"); @@ -165,19 +168,24 @@ script: then: - lambda: |- ESP_LOGV("script.addon_climate_global_settings", "Starting"); + ESP_LOGV("script.addon_climate_global_settings", "embedded_climate: %i", (embedded_climate) ? 1 : 0); id(is_embedded_thermostat) = embedded_climate; ESP_LOGV("script.addon_climate_global_settings", "Finished"); - id: !extend addon_climate_update_page_climate then: - - lambda: ESP_LOGV("script.addon_climate_update_page_climate", "Starting"); + - lambda: |- + ESP_LOGV("script.addon_climate_update_page_climate", "Starting"); + ESP_LOGV("script.addon_climate_update_page_climate", "nextion_init: %i", (id(nextion_init)) ? 1 : 0); + ESP_LOGV("script.addon_climate_update_page_climate", "current_page: %s", id(current_page).state.c_str()); + ESP_LOGV("script.addon_climate_update_page_climate", "is_addon_climate_visible: %i", (id(is_addon_climate_visible)) ? 1 : 0); - if: condition: - binary_sensor.is_on: nextion_init - text_sensor.state: # Is climate page visible? id: current_page state: 'climate' - - lambda: !lambda return id(is_addon_climate_visible); + - lambda: !lambda return (id(is_addon_climate_visible)); then: # Embedded thermostat is visible # Update slider, current temperature & target temperature - script.execute: