Fix empty page climate

This commit is contained in:
Edward Firmo
2023-09-15 09:46:27 +02:00
parent c2d94ce183
commit 76a9520557
11 changed files with 126 additions and 202 deletions

View File

@@ -253,13 +253,13 @@ api:
back_page: string
then:
- 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, %i, %i", page_icon_color[0], page_icon_color[1], page_icon_color[2] );
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());
ESP_LOGD("api.service.open_entity_settings_page", "Starting");
ESP_LOGD("api.service.open_entity_settings_page", "page: %s", page.c_str());
ESP_LOGD("api.service.open_entity_settings_page", "page_label: %s", page_label.c_str());
ESP_LOGD("api.service.open_entity_settings_page", "page_icon: %s", page_icon.c_str());
ESP_LOGD("api.service.open_entity_settings_page", "page_icon_color: %i, %i, %i", page_icon_color[0], page_icon_color[1], page_icon_color[2] );
ESP_LOGD("api.service.open_entity_settings_page", "entity: %s", entity.c_str());
ESP_LOGD("api.service.open_entity_settings_page", "back_page: %s", back_page.c_str());
id(entity_id) = entity;
std::string cmd_page = std::string("page ") + page.c_str();
id(disp1).send_command_printf(cmd_page.c_str());
@@ -276,7 +276,7 @@ api:
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("api.service.open_entity_settings_page", "Finished");
ESP_LOGD("api.service.open_entity_settings_page", "Finished");
##### Service to play a rtttl tones #####
# Example tones : https://codebender.cc/sketch:109888#RTTTL%20Songs.ino
@@ -309,15 +309,17 @@ api:
temp_offset: int
climate_icon: string
embedded_climate: bool
entity: string
then:
- lambda: |-
ESP_LOGV("api.service.set_climate", "climateslider.maxval=%i", total_steps);
ESP_LOGV("api.service.set_climate", "temp_offset=%f", temp_offset);
ESP_LOGV("api.service.set_climate", "temp_step=%f", temp_step);
ESP_LOGV("api.service.set_climate", "current_temp=%f", current_temp);
ESP_LOGV("api.service.set_climate", "target_temp=%f", target_temp);
ESP_LOGV("api.service.set_climate", "target_icon=%s", climate_icon.c_str());
ESP_LOGV("api.service.set_climate", "embedded=%i", (embedded_climate) ? 1 : 0);
ESP_LOGD("api.service.set_climate", "climateslider.maxval=%i", total_steps);
ESP_LOGD("api.service.set_climate", "temp_offset=%f", temp_offset);
ESP_LOGD("api.service.set_climate", "temp_step=%f", temp_step);
ESP_LOGD("api.service.set_climate", "current_temp=%f", current_temp);
ESP_LOGD("api.service.set_climate", "target_temp=%f", target_temp);
ESP_LOGD("api.service.set_climate", "target_icon=%s", climate_icon.c_str());
ESP_LOGD("api.service.set_climate", "embedded=%i", (embedded_climate) ? 1 : 0);
if (id(current_page).state == "climate") id(entity_id) = entity;
- script.execute:
id: set_climate
@@ -881,7 +883,7 @@ globals:
- id: embedded_indoor_temp
type: bool
restore_value: true
initial_value: 'true'
initial_value: 'false'
- id: temp_unit_fahrenheit
type: bool
restore_value: true
@@ -1076,15 +1078,6 @@ sensor:
- lambda: |-
id(timer_reset_all)->execute();
##### Send current brightness info to Home Assistant
- name: ${device_name} Brightness
id: brightness
platform: nextion
variable_name: dim
#update_interval: 1s
internal: false
precision: 0
##### Uptime Sensors #####
- name: ${device_name} Uptime seconds
id: uptime_sec
@@ -1177,11 +1170,19 @@ sensor:
text_sensor:
##### Current page name #####
- name: ${device_name} current page
platform: template
- name: ${device_name} Current page
id: current_page
platform: template
#platform: nextion
#nextion_id: disp1
#component_name: currentpage
internal: false
disabled_by_default: false
#filters:
# - lambda: |-
# x = x.c_str();
# x.shrink_to_fit();
# return x;
on_value:
then:
- lambda: |-
@@ -1229,17 +1230,17 @@ text_sensor:
on_value:
then:
- lambda: |-
ESP_LOGV("text_sensor.nspanelevent", "Starting");
ESP_LOGD("text_sensor.nspanelevent", "Starting");
DynamicJsonDocument doc(1024);
deserializeJson(doc, x);
std::string page = doc["page"];
std::string component = doc["component"];
std::string value = doc["value"];
std::string entity = id(entity_id); //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());
ESP_LOGD("text_sensor.nspanelevent", "page: %s", page.c_str());
ESP_LOGD("text_sensor.nspanelevent", "component: %s", component.c_str());
ESP_LOGD("text_sensor.nspanelevent", "value: %s", value.c_str());
ESP_LOGD("text_sensor.nspanelevent", "entity: %s", entity.c_str());
auto ha_event = new esphome::api::CustomAPIDevice();
ha_event->fire_homeassistant_event("esphome.nspanel_ha_blueprint",
{
@@ -1251,8 +1252,8 @@ text_sensor:
});
if (component=="currentpage")
{
ESP_LOGV("text_sensor.nspanelevent", "New page: %s", page.c_str());
ESP_LOGV("text_sensor.nspanelevent", "Trigger HA event");
ESP_LOGD("text_sensor.nspanelevent", "New page: %s", page.c_str());
ESP_LOGD("text_sensor.nspanelevent", "Trigger HA event");
id(timer_page)->execute();
ha_event->fire_homeassistant_event("esphome.nspanel_ha_blueprint",
{
@@ -1260,7 +1261,7 @@ text_sensor:
{"page", page},
{"entity", entity}
});
ESP_LOGV("text_sensor.nspanelevent", "Call add-ons scripts for new page");
ESP_LOGD("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);
@@ -1360,45 +1361,50 @@ text_sensor:
on_value:
then:
- lambda: |-
ESP_LOGV("text_sensor.localevent", "Starting");
ESP_LOGD("text_sensor.localevent", "Starting");
DynamicJsonDocument doc(1024);
deserializeJson(doc, x);
std::string page = doc["page"];
ESP_LOGV("text_sensor.localevent", "page: %s", page.c_str());
ESP_LOGD("text_sensor.localevent", "page: %s", page.c_str());
std::string event = doc["event"];
ESP_LOGV("text_sensor.localevent", "event: %s", event.c_str());
ESP_LOGD("text_sensor.localevent", "event: %s", event.c_str());
std::string component = doc["component"];
ESP_LOGV("text_sensor.localevent", "component: %s", component.c_str());
ESP_LOGD("text_sensor.localevent", "component: %s", component.c_str());
std::string key = doc["key"];
ESP_LOGV("text_sensor.localevent", "key: %s", key.c_str());
ESP_LOGD("text_sensor.localevent", "key: %s", key.c_str());
std::string value = doc["value"];
ESP_LOGV("text_sensor.localevent", "value: %s", value.c_str());
ESP_LOGD("text_sensor.localevent", "value: %s", value.c_str());
std::string entity = id(entity_id); //doc["entity"];
ESP_LOGV("text_sensor.localevent", "entity: %s", entity.c_str());
ESP_LOGD("text_sensor.localevent", "entity: %s", entity.c_str());
int embedded = doc["embedded"];
ESP_LOGV("text_sensor.localevent", "embedded: %i", embedded);
ESP_LOGD("text_sensor.localevent", "embedded: %i", embedded);
std::string service = "";
// send event to Home Assistant
auto ha_event = new esphome::api::CustomAPIDevice();
if (event=="pagechanged")
{
ESP_LOGV("text_sensor.localevent", "New page: %s", page.c_str());
ESP_LOGD("text_sensor.localevent", "New page: %s", page.c_str());
id(timer_page)->execute();
ESP_LOGV("text_sensor.localevent", "Trigger HA event");
ESP_LOGD("text_sensor.localevent", "Trigger HA event");
ha_event->fire_homeassistant_event("esphome.nspanel_ha_blueprint",
{
{"type", "page_changed"},
{"page", page},
{"entity", entity}
});
ESP_LOGV("text_sensor.localevent", "Call add-ons scripts for new page");
ESP_LOGD("text_sensor.localevent", "Call add-ons scripts for new page");
id(addon_climate_set_climate).execute(page=="climate" and id(entity_id) == "embedded_climate");
ESP_LOGV("text_sensor.localevent", "Publish current_page sensor");
ESP_LOGD("text_sensor.localevent", "Publish current_page sensor");
id(current_page).publish_state(page);
ESP_LOGV("text_sensor.localevent", "Construct new page");
ESP_LOGD("text_sensor.localevent", "Construct new page");
}
else if (event=="short_click" or event=="long_click") id(ha_button)->execute(page.c_str(), component.c_str(), event.c_str());
else if (event=="click")
{
if (page == "home" and component == "climate") id(entity_id) = (id(is_embedded_thermostat)) ? "embedded_climate" : "";
id(disp1).goto_page("climate");
}
else if (page == "light" or page == "climate" or page == "notification")// Generic event
{
ha_event->fire_homeassistant_event("esphome.nspanel_ha_blueprint",
@@ -1822,7 +1828,7 @@ script:
ESP_LOGD("script.timer_page", "Fallback to page Home");
id(disp1).goto_page("home");
}
- id: timer_dim # Handle the brightness dimming after a timeout DEBUG
- id: timer_dim # Handle the brightness dimming after a timeout
mode: restart
then:
- lambda: |-
@@ -1848,7 +1854,7 @@ script:
id(disp1).send_command_printf("dim=%i", id(display_dim_brightness_global));
id(is_dim_brightness) = true;
}
- id: timer_sleep # Handle the sleep (go to screensaver page) after a timeout DEBUG
- id: timer_sleep # Handle the sleep (go to screensaver page) after a timeout
mode: restart
then:
- lambda: |-
@@ -1886,13 +1892,13 @@ script:
state: 'climate'
then:
- lambda: |-
ESP_LOGV("script.set_climate", "climateslider.maxval=%i", total_steps);
ESP_LOGV("script.set_climate", "temp_offset=%i", temp_offset);
ESP_LOGV("script.set_climate", "temp_step=%i", temp_step);
ESP_LOGV("script.set_climate", "current_temp=%f", current_temp);
ESP_LOGV("script.set_climate", "target_temp=%f", target_temp);
ESP_LOGV("script.set_climate", "target_icon=%s", climate_icon.c_str());
ESP_LOGV("script.set_climate", "embedded=%i", (embedded_climate) ? 1 : 0);
ESP_LOGD("script.set_climate", "climateslider.maxval=%i", total_steps);
ESP_LOGD("script.set_climate", "temp_offset=%i", temp_offset);
ESP_LOGD("script.set_climate", "temp_step=%i", temp_step);
ESP_LOGD("script.set_climate", "current_temp=%f", current_temp);
ESP_LOGD("script.set_climate", "target_temp=%f", target_temp);
ESP_LOGD("script.set_climate", "target_icon=%s", climate_icon.c_str());
ESP_LOGD("script.set_climate", "embedded=%i", (embedded_climate) ? 1 : 0);
id(addon_climate_set_climate).execute(embedded_climate);
id(disp1).send_command_printf("climateslider.maxval=%i", total_steps);
id(disp1).set_component_value("temp_offset", temp_offset);
@@ -1903,7 +1909,7 @@ script:
if (target_temp > -999)
{
float slider_val = round(((10*target_temp) - temp_offset) / temp_step);
ESP_LOGV("script.set_climate", "climateslider=%f", slider_val);
ESP_LOGD("script.set_climate", "climateslider=%f", slider_val);
id(disp1).set_component_value("climateslider", slider_val);
id(disp1).set_component_text_printf("target_temp", "%.1f°", target_temp);
id(disp1).set_component_text_printf("target_icon", "%s", climate_icon.c_str());
@@ -1922,7 +1928,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");
- lambda: ESP_LOGD("script.set_climate", "Finished");
- id: refresh_datetime
mode: restart
@@ -2358,7 +2364,11 @@ script:
- id: check_versions
mode: restart
then:
- delay: 60s
- wait_until:
condition:
- lambda: !lambda 'return (id(version_tft) == "${version}");'
- lambda: !lambda 'return (id(version_blueprint) == "${version}");'
timeout: 60s
- lambda: |-
ESP_LOGD("script.check_versions", "ESPHome version: ${version}");
ESP_LOGD("script.check_versions", "TFT version: %s", id(version_tft).c_str());