Embedded climate (#917)

* Performance improvements

The main focus here was to reduce the number of calls between Home Assistant and ESPHome, moving logic as much as possible to TFT and ESPHome.
- Service calls moved to ESPHome (in preparation for Alarm Control Panel)
- Page change informed via event call instead of `nspanel_event` sensor (which still in use by other calls, but might be possible to remove in the future)

* Draft embedded climate

This adds an initial version of an embedded climate/thermostat (heating only for now) with support for local control even with Wi-Fi out.

Solves #646
Solves #263

* Update ReleaseNotes.md

* Fix climate slider

Fix for climate slider opening in an incorrect position and sending only the integer part of the new target temperature

* Moving home page to ESPHome

In progress...

* Fix translations - Dutch

* Embedded chip 3

Home page - Chip 3 will be controlled locally when embedded climate is enable.

* Fixed buttons bar

Fixed buttons bar managed on ESPHome when embedded climate is visible.
This commit is contained in:
Edward Firmo
2023-07-08 09:34:09 +02:00
committed by GitHub
parent 64659f3794
commit f25ca0934c
13 changed files with 2933 additions and 2381 deletions

View File

@@ -8,6 +8,7 @@
##### ADVANCED CONFIGURATION - activate only when you know what you do ##############################
substitutions:
verbose_log: "false"
baud_rate: "115200" # requires 115200 if tft is installed but can be changed to 9600 if tft upload fails and nextion switches to 9600
# ## usage of secrets-file ## -> comment in ###### Change ME ######
# device_name: "nspanel-name" # Wird im Blueprint benötigt!
@@ -27,6 +28,20 @@ substitutions:
time_source: "homeassistant" # Either "homeassistant" or "sntp" are supported
### Local thermostat defaults ###
# https://esphome.io/components/climate/thermostat.html
embedded_thermostat_disabled: "true"
embedded_thermostat_temp_units: "°C"
embedded_thermostat_heater_relay: "1" # Select 1 for "Relay 1" or 2 for "Relay 2"
embedded_thermostat_min_heating_off_time: "300"
embedded_thermostat_min_heating_run_time: "300"
embedded_thermostat_min_idle_time: "30"
# https://esphome.io/components/climate/index.html#base-climate-configuration
embedded_thermostat_visual_min_temperature: "5"
embedded_thermostat_visual_max_temperature: "25"
embedded_thermostat_visual_temperature_step: "0.5"
###### USE THIS ONLY FOR YOUR FIRST TFT UPLOAD
###### AND IF EXIT-REPARSE BUTTON FAILS
###### ONCE IT WORKED, REMOVE THESE LINES
@@ -64,7 +79,7 @@ wifi:
##### ESPHOME CONFIGURATION #####
esphome:
name: ${device_name}
min_version: 2022.10.2
min_version: 2023.5.0
##### TYPE OF ESP BOARD #####
esp32:
@@ -128,39 +143,13 @@ time:
on_time:
- seconds: 0
then:
- wait_until:
binary_sensor.is_on: nextion_init
- &refresh_datetime
lambda: |-
std::string time_format_str = id(mui_time_format);
if (time_format_str.find("%p") != std::string::npos)
{
std::string meridiem_text = id(time_provider).now().strftime("%p");
id(disp1).set_component_text_printf("home.meridiem", "%s", meridiem_text.c_str());
}
else { id(disp1).set_component_text_printf("home.meridiem", " "); }
if (time_format_str.find("%-H") != std::string::npos) { time_format_str = time_format_str.replace(time_format_str.find("%-H"), sizeof("%-H")-1, to_string((int)(id(time_provider).now().hour))); }
if (time_format_str.find("%-I") != std::string::npos)
{
if (id(time_provider).now().hour>12)
{
time_format_str = time_format_str.replace(time_format_str.find("%-I"), sizeof("%-I")-1, to_string((int)(id(time_provider).now().hour-12)));
}
else if (id(time_provider).now().hour==0)
{
time_format_str = time_format_str.replace(time_format_str.find("%-I"), sizeof("%-I")-1, "12");
}
else
{
time_format_str = time_format_str.replace(time_format_str.find("%-I"), sizeof("%-I")-1, to_string((int)(id(time_provider).now().hour)));
}
}
std::string time_text = id(time_provider).now().strftime(time_format_str);
id(disp1).set_component_text_printf("home.time", "%s", time_text.c_str());
- script.execute:
id: refresh_datetime
on_time_sync:
then:
- logger.log: "Synchronized system clock"
- *refresh_datetime
- script.execute:
id: refresh_datetime
##### START - BUTTON CONFIGURATION #####
button:
@@ -200,6 +189,7 @@ button:
##### START - API CONFIGURATION #####
api:
id: api_server
##### advanced config - activate to use api_password #####
# password: ${api_password}
services:
@@ -384,39 +374,32 @@ api:
target_temp: float
temp_step: int
total_steps: int
slider_val: int
temp_offset: int
climate_icon: string
embedded_climate: bool
then:
- wait_until:
binary_sensor.is_on: nextion_init
- lambda: |-
id(disp1).send_command_printf("climateslider.maxval=%i", total_steps);
id(disp1).set_component_value("temp_offset", temp_offset);
id(disp1).set_component_value("temp_step", temp_step);
id(disp1).set_component_text_printf("current_temp", "%.1f°", current_temp);
id(disp1).show_component("current_temp");
id(disp1).show_component("current_icon");
if (target_temp > -999)
if (${verbose_log})
{
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());
id(disp1).show_component("target_icon");
id(disp1).show_component("target_temp");
id(disp1).show_component("climateslider");
id(disp1).show_component("decrease_temp");
id(disp1).show_component("increase_temp");
}
else
{
id(disp1).hide_component("target_icon");
id(disp1).hide_component("target_temp");
id(disp1).hide_component("climateslider");
id(disp1).hide_component("decrease_temp");
id(disp1).hide_component("increase_temp");
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);
}
- script.execute:
id: set_climate
current_temp: !lambda "return current_temp;"
target_temp: !lambda "return target_temp;"
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;"
#### Service to set the buttons ####
- service: set_button
variables:
@@ -510,25 +493,63 @@ api:
id(disp1).send_command_printf("%s", entxcen.c_str());
}
##### Service for localization of global vars #####
- service: set_localization
##### Service for transferring global settings from the blueprint to ESPHome #####
- service: global_settings
variables:
relay1_local_control: bool
relay1_icon: string
relay1_icon_color: int
relay2_local_control: bool
relay2_icon: string
relay2_icon_color: int
date_color: int
time_format: string
time_color: int
embedded_climate: bool
wakeup_page: int
then:
## Logs
- lambda: |-
ESP_LOGD("set_localization", "time_format: %s", time_format.c_str());
id(mui_time_format) = time_format;
- *refresh_datetime
if (${verbose_log})
{
ESP_LOGD("global_settings", "relay1_local_control: %i", (relay1_local_control) ? 1 : 0);
ESP_LOGD("global_settings", "relay2_local_control: %i", (relay2_local_control) ? 1 : 0);
ESP_LOGD("global_settings", "date_color: %i", date_color);
ESP_LOGD("global_settings", "time_format: %s", time_format.c_str());
ESP_LOGD("global_settings", "time_color: %i", time_color);
ESP_LOGD("global_settings", "embedded_climate: %i", (embedded_climate and not (${embedded_thermostat_disabled})) ? 1 : 0);
}
##### Service for setting relays as locally controlled #####
- service: set_relay_local
variables:
relay1: bool
relay2: bool
then:
## Relays
- lambda: |-
id(relay1_local).publish_state(relay1);
id(relay2_local).publish_state(relay2);
id(relay1_local).publish_state(relay1_local_control);
id(relay2_local).publish_state(relay2_local_control);
id(home_relay1_icon) = relay1_icon.c_str();
id(home_relay2_icon) = relay2_icon.c_str();
id(home_relay1_icon_color) = relay1_icon_color;
id(home_relay2_icon_color) = relay2_icon_color;
## Localization
- lambda: id(mui_time_format) = time_format;
## Date/Time colors
- lambda: |-
id(home_date_color) = date_color;
id(home_time_color) = time_color;
## Embedded thermostat
- lambda: id(is_embedded_thermostat) = (embedded_climate and not (${embedded_thermostat_disabled}));
## Wakeup page
- lambda: id(wakeup_page_id) = wakeup_page;
## Refresh colors of global components
- script.execute:
id: refresh_colors
## Update home page
- script.execute:
id: update_page_home
##### START - GLOBALS CONFIGURATION #####
globals:
@@ -556,11 +577,59 @@ globals:
# type: std::string
# restore_value: no
# initial_value: '"%A, %d.%m"'
- id: home_date_color
type: int
restore_value: true
initial_value: '65535'
- id: mui_time_format
type: std::string
restore_value: no
initial_value: '"%H:%M"'
- id: home_time_color
type: int
restore_value: true
initial_value: '65535'
##### Is embedded thermostat set as main climate entity? #####
- id: is_embedded_thermostat
type: bool
restore_value: true
initial_value: 'false'
##### Is embedded thermostat visible on climate page? #####
- id: is_embedded_thermostat_visible
type: bool
restore_value: false
initial_value: 'false'
##### Relay icons #####
- id: home_relay1_icon
type: std::string
restore_value: false
initial_value: ''
- id: home_relay1_icon_color
type: int
restore_value: true
initial_value: '65535'
- id: home_relay2_icon
type: std::string
restore_value: false
initial_value: ''
- id: home_relay2_icon_color
type: int
restore_value: true
initial_value: '65535'
##### Wakeup page ID #####
- id: wakeup_page_id
type: int
restore_value: true
initial_value: '0'
##### START - BINARY SENSOR CONFIGURATION #####
binary_sensor:
@@ -583,15 +652,8 @@ binary_sensor:
api.connected:
then:
- switch.toggle: relay_1
- if:
condition:
switch.is_on: relay_1
then:
- lambda: id(disp1).send_command_printf("home.left_bt_pic.pic=78");
- lambda: id(disp1).send_command_printf("home.icon_top_01","\U0000E3A5");
else:
- lambda: id(disp1).send_command_printf("home.left_bt_pic.pic=77");
- lambda: id(disp1).send_command_printf("home.icon_top_01","\U0000FFFF");
- script.execute:
id: refresh_relays
##### RIGHT BUTTON BELOW DISPLAY TO TOGGLE RELAY #####
- name: ${device_name} Right Button
@@ -612,15 +674,8 @@ binary_sensor:
api.connected:
then:
- switch.toggle: relay_2
- if:
condition:
switch.is_on: relay_2
then:
- lambda: id(disp1).send_command_printf("home.right_bt_pic.pic=78");
- lambda: id(disp1).send_command_printf("home.icon_top_02","\U0000E3A8");
else:
- lambda: id(disp1).send_command_printf("home.right_bt_pic.pic=77");
- lambda: id(disp1).send_command_printf("home.icon_top_02","\U0000FFFF");
- script.execute:
id: refresh_relays
##### Restart NSPanel Button - Setting Page #####
- name: ${device_name} Restart
@@ -663,28 +718,11 @@ binary_sensor:
##### API connection status
- platform: status
name: ${device_name} Status
id: api_status
on_state:
then:
- &update_wifi_icon
if:
condition:
wifi.connected:
then:
- if:
condition:
api.connected:
then:
- lambda: id(disp1).set_component_value("home.api",1);
- lambda: id(disp1).set_component_text_printf("home.wifi_icon", "%s", "\U0000E5A8");
- lambda: id(disp1).set_component_font_color("home.wifi_icon", 33808);
else:
- lambda: id(disp1).set_component_value("home.api",0);
- lambda: id(disp1).set_component_text_printf("home.wifi_icon", "%s", "\U0000F256");
- lambda: id(disp1).set_component_font_color("home.wifi_icon", 63488);
else:
- lambda: id(disp1).set_component_value("home.api",0);
- lambda: id(disp1).set_component_text_printf("home.wifi_icon", "%s", "\U0000E5A9");
- lambda: id(disp1).set_component_font_color("home.wifi_icon", 63488);
- script.execute:
id: refresh_wifi_icon
##### START - SENSOR CONFIGURATION #####
sensor:
@@ -699,7 +737,8 @@ sensor:
platform: wifi_signal
update_interval: 60s
on_value:
- *update_wifi_icon
- script.execute:
id: refresh_wifi_icon
##### INTERNAL TEMPERATURE SENSOR, ADC VALUE #####
- id: ntc_source
@@ -768,6 +807,13 @@ sensor:
##### START - TEXT SENSOR CONFIGURATION #####
text_sensor:
##### Current page name #####
- name: ${device_name} current page
platform: template
id: current_page
internal: false
disabled_by_default: true
##### ESPhome version used to compile the app #####
- platform: version
name: ${device_name} ESPhome Version
@@ -809,6 +855,141 @@ text_sensor:
then:
- lambda: |-
id(page_timer)->execute(int(id(page_timeout).state));
DynamicJsonDocument doc(1024);
deserializeJson(doc, x);
std::string page = doc["page"];
std::string component = doc["component"];
std::string value = doc["value"];
std::string entity = doc["entity"];
if (component=="currentpage")
{
ESP_LOGD("nspanelevent", "New page: %s", page.c_str());
auto ha_event = new esphome::api::CustomAPIDevice();
ha_event->fire_homeassistant_event("esphome.nspanel_pagechange",
{
{"page", page},
{"entity", entity}
});
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));
else if (page=="climate" and id(is_embedded_thermostat_visible)) id(update_page_climate);
}
else if (page=="boot" and component=="timeout" and stof(value) >= 5) id(disp1).send_command_printf("page %i", id(wakeup_page_id));
##### NSPanel event - Execute actions from ESPHome - NO push to HA #####
- name: ${device_name} NSPanel local event
platform: nextion
nextion_id: disp1
id: disp1_local_event
component_name: localevent
internal: True
filters:
- lambda: |-
x = x.c_str();
x.shrink_to_fit();
return x;
on_value:
then:
- lambda: |-
id(page_timer)->execute(int(id(page_timeout).state));
DynamicJsonDocument doc(1024);
deserializeJson(doc, x);
std::string domain = doc["domain"];
std::string key = doc["key"];
std::string value = doc["value"];
std::string entity = doc["entity"];
int embedded = doc["embedded"];
if (${verbose_log})
{
ESP_LOGD("text_sensor.localevent", "domain=%s", domain.c_str());
ESP_LOGD("text_sensor.localevent", "key=%s", key.c_str());
ESP_LOGD("text_sensor.localevent", "value=%s", value.c_str());
ESP_LOGD("text_sensor.localevent", "entity=%s", entity.c_str());
ESP_LOGD("text_sensor.localevent", "embedded=%i", embedded);
}
id(is_embedded_thermostat_visible) = (domain == "climate" and embedded == 1);
if (id(is_embedded_thermostat_visible) and (not ${embedded_thermostat_disabled}))
{
if (${verbose_log}) ESP_LOGD("text_sensor.localevent", "Embedded thermostat is visible");
auto call = id(thermostat_embedded).make_call();
if (key == "set_temperature")
{
if (${verbose_log}) ESP_LOGD("text_sensor.localevent", "set_temperature=%f", stof(value) / 10);
call.set_target_temperature(stof(value) / 10);
}
else if (key == "hvac_mode")
{
if (${verbose_log}) ESP_LOGD("text_sensor.localevent", "set_mode=%s", value);
call.set_mode(value);
}
call.perform();
}
else if (entity != "" and not entity.empty() and entity != "embedded_climate")
{
HomeassistantServiceResponse resp;
HomeassistantServiceMap resp_kv;
if (domain == "climate")
{
if (${verbose_log}) ESP_LOGD("text_sensor.localevent", "HA controlled climate");
if (key == "set_temperature")
{
resp.service = "climate.set_temperature";
resp_kv.key = "temperature";
resp_kv.value = to_string(stof(value) / 10);
if (${verbose_log})
{
ESP_LOGD("text_sensor.localevent", "resp.service=%s", resp.service.c_str());
ESP_LOGD("text_sensor.localevent", "resp_kv.key=%s", resp_kv.key.c_str());
ESP_LOGD("text_sensor.localevent", "resp_kv.value=%s", resp_kv.value.c_str());
}
resp.data.push_back(resp_kv);
}
else if (key == "hvac_mode")
{
resp.service = "climate.set_hvac_mode";
resp_kv.key = "hvac_mode";
resp_kv.value = value;
resp.data.push_back(resp_kv);
}
}
else if (domain == "cover")
{
if (key == "position")
{
resp.service = "cover.set_cover_position";
resp_kv.key = key;
resp_kv.value = value;
resp.data.push_back(resp_kv);
}
else resp.service = std::string("cover.") + key.c_str();
}
else if (domain == "fan")
{
if (key == "stop")
{
resp.service = "fan.turn_off";
}
else
{
resp.service = "fan.turn_on";
resp_kv.key = key;
resp_kv.value = value;
resp.data.push_back(resp_kv);
}
}
else if (domain == "light")
{
resp.service = "light.turn_on";
resp_kv.key = key;
resp_kv.value = value;
resp.data.push_back(resp_kv);
}
resp_kv.key = "entity_id";
resp_kv.value = entity;
resp.data.push_back(resp_kv);
id(api_server).send_homeassistant_service_call(resp);
}
##### touchevent sensor, Reset the page timeout #####
- id: disp1_touchevent
@@ -1058,7 +1239,13 @@ display:
- binary_sensor.template.publish:
id: nextion_init
state: true
- logger.log: "Nextion start - Prepare home page"
- script.execute:
id: refresh_colors
- lambda: id(home_relay1_icon) = "\uE3A5";
- lambda: id(home_relay1_icon) = "\uE3A8";
- logger.log: "Nextion start - Done!"
#on_page: # Couldn't make this trigger to work, so used text_sensor nspanelevent and localevent instead
### Script for page_timer
script:
@@ -1067,15 +1254,417 @@ script:
parameters:
delay: int
then:
- lambda: ESP_LOGD("nspanel", "start page-timer delay %i", int(id(page_timeout).state));
- lambda: if (${verbose_log}) ESP_LOGD("script.page_timer", "start page-timer delay %i", int(id(page_timeout).state));
- delay: !lambda return delay *1000;
- lambda: |-
DynamicJsonDocument doc(1024);
deserializeJson(doc, id(disp1_nspanel_event).state);
std::string page = doc["page"];
if (page == "home" or page == "screensaver" or page == "boot" or int(id(page_timeout).state) == 0) {
ESP_LOGD("nspanel", "no page-jump");
} else {
ESP_LOGD("nspanel", "timer->home");
id(disp1).send_command_printf("page 0");
}
if (page == "home" or page == "screensaver" or page == "boot" or int(id(page_timeout).state) == 0)
{
if (${verbose_log}) ESP_LOGD("script.page_timer", "no page-jump");
}
else
{
if (${verbose_log}) ESP_LOGD("script.page_timer", "timer->home");
id(disp1).send_command_printf("page 0");
}
- id: set_climate
mode: restart
parameters:
current_temp: float
target_temp: float
temp_step: int
total_steps: int
temp_offset: int
climate_icon: string
embedded_climate: bool
then:
- if:
condition:
- binary_sensor.is_on: nextion_init
- text_sensor.state: # Is climate page visible?
id: current_page
state: 'climate'
then:
- lambda: |-
if (${verbose_log})
{
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(is_embedded_thermostat_visible) = embedded_climate;
id(disp1).send_command_printf("climateslider.maxval=%i", total_steps);
id(disp1).set_component_value("temp_offset", temp_offset);
id(disp1).set_component_value("temp_step", temp_step);
id(disp1).set_component_text_printf("current_temp", "%.1f°", current_temp);
id(disp1).show_component("current_temp");
id(disp1).show_component("current_icon");
if (target_temp > -999)
{
float slider_val = round(((10*target_temp) - temp_offset) / temp_step);
if (${verbose_log}) 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());
id(disp1).show_component("target_icon");
id(disp1).show_component("target_temp");
id(disp1).show_component("climateslider");
id(disp1).show_component("decrease_temp");
id(disp1).show_component("increase_temp");
}
else
{
id(disp1).hide_component("target_icon");
id(disp1).hide_component("target_temp");
id(disp1).hide_component("climateslider");
id(disp1).hide_component("decrease_temp");
id(disp1).hide_component("increase_temp");
}
id(disp1).set_component_value("embedded", (embedded_climate) ? 1 : 0);
- id: refresh_colors ## Refresh colors of global components
mode: restart
then:
- if:
condition:
- binary_sensor.is_on: nextion_init
#- text_sensor.state: # Is home page visible?
# id: current_page
# state: 'home'
then:
- lambda: |-
id(disp1).set_component_font_color("home.date", id(home_date_color));
id(disp1).set_component_font_color("home.time", id(home_time_color));
id(disp1).set_component_font_color("home.icon_top_01", id(home_relay1_icon_color));
id(disp1).set_component_font_color("home.icon_top_02", id(home_relay2_icon_color));
- id: refresh_datetime
mode: restart
then:
- if:
condition:
- binary_sensor.is_on: nextion_init
#- text_sensor.state: # Is home page visible?
# id: current_page
# state: 'home'
then:
- lambda: |-
std::string time_format_str = id(mui_time_format);
if (time_format_str.find("%p") != std::string::npos)
{
std::string meridiem_text = id(time_provider).now().strftime("%p");
id(disp1).set_component_text_printf("home.meridiem", "%s", meridiem_text.c_str());
}
else { id(disp1).set_component_text_printf("home.meridiem", " "); }
if (time_format_str.find("%-H") != std::string::npos) { time_format_str = time_format_str.replace(time_format_str.find("%-H"), sizeof("%-H")-1, to_string((int)(id(time_provider).now().hour))); }
if (time_format_str.find("%-I") != std::string::npos)
{
if (id(time_provider).now().hour>12)
{
time_format_str = time_format_str.replace(time_format_str.find("%-I"), sizeof("%-I")-1, to_string((int)(id(time_provider).now().hour-12)));
}
else if (id(time_provider).now().hour==0)
{
time_format_str = time_format_str.replace(time_format_str.find("%-I"), sizeof("%-I")-1, "12");
}
else
{
time_format_str = time_format_str.replace(time_format_str.find("%-I"), sizeof("%-I")-1, to_string((int)(id(time_provider).now().hour)));
}
}
std::string time_text = id(time_provider).now().strftime(time_format_str);
id(disp1).set_component_text_printf("home.time", "%s", time_text.c_str());
- id: refresh_relays
mode: restart
then:
- if:
condition:
- binary_sensor.is_on: nextion_init
#- text_sensor.state: # Is home page visible?
# id: current_page
# state: 'home'
then:
- lambda: |-
// Chips - Relays
if (id(relay_1).state) id(disp1).set_component_text_printf("home.icon_top_01", "%s", id(home_relay1_icon).c_str());
else id(disp1).set_component_text_printf("home.icon_top_01", "\uFFFF");
if (id(relay_2).state) id(disp1).set_component_text_printf("home.icon_top_02", "%s", id(home_relay2_icon).c_str());
else id(disp1).set_component_text_printf("home.icon_top_02", "\uFFFF");
// Hardware buttons - Fallback mode
if (id(relay_1).state or (id(relay1_fallback).state and not id(api_status).state)) id(disp1).send_command_printf("home.left_bt_pic.pic=%i", (id(relay_1).state) ? 78 : 77);
if (id(relay_2).state or (id(relay2_fallback).state and not id(api_status).state)) id(disp1).send_command_printf("home.right_bt_pic.pic=%i", (id(relay_2).state) ? 78 : 77);
- id: refresh_chips_climate
mode: restart
then:
- if:
condition:
- binary_sensor.is_on: nextion_init
- lambda: !lambda 'return (not ${embedded_thermostat_disabled});'
- lambda: !lambda 'return id(is_embedded_thermostat);'
then:
- lambda: |-
if (${verbose_log}) ESP_LOGD("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
{
case 0: //CLIMATE_ACTION_OFF
if (${verbose_log}) ESP_LOGD("script.refresh_chips_climate", "thermostat_embedded.mode=%i", int(id(thermostat_embedded).mode));
switch (int(id(thermostat_embedded).mode)) // CLIMATE_MODE_OFF = 0, CLIMATE_MODE_HEAT_COOL = 1, CLIMATE_MODE_COOL = 2, CLIMATE_MODE_HEAT = 3, CLIMATE_MODE_FAN_ONLY = 4, CLIMATE_MODE_DRY = 5, CLIMATE_MODE_AUTO = 6
{
case 0: //CLIMATE_MODE_OFF
id(disp1).set_component_text_printf("home.icon_top_03", "%s", "\uFFFF"); // (E424) Don't show icon when off
id(disp1).set_component_font_color("home.icon_top_03", 35921);
break;
case 1: //CLIMATE_MODE_HEAT_COOL
id(disp1).set_component_text_printf("home.icon_top_03", "%s", "\uE069");
id(disp1).set_component_font_color("home.icon_top_03", 35921);
break;
case 2: //CLIMATE_MODE_COOL
id(disp1).set_component_text_printf("home.icon_top_03", "%s", "\uE716");
id(disp1).set_component_font_color("home.icon_top_03", 35921);
break;
case 3: //CLIMATE_MODE_HEAT
id(disp1).set_component_text_printf("home.icon_top_03", "%s", "\uE237");
id(disp1).set_component_font_color("home.icon_top_03", 35921);
break;
case 4: //CLIMATE_MODE_FAN_ONLY
id(disp1).set_component_text_printf("home.icon_top_03", "%s", "\uE20F");
id(disp1).set_component_font_color("home.icon_top_03", 35921);
break;
case 5: //CLIMATE_MODE_DRY
id(disp1).set_component_text_printf("home.icon_top_03", "%s", "\uE58D");
id(disp1).set_component_font_color("home.icon_top_03", 35921);
break;
case 6: //CLIMATE_MODE_AUTO
id(disp1).set_component_text_printf("home.icon_top_03", "%s", "\uEE8D");
id(disp1).set_component_font_color("home.icon_top_03", 35921);
break;
}
case 2: //CLIMATE_ACTION_COOLING
id(disp1).set_component_text_printf("home.icon_top_03", "%s", "\uE716");
id(disp1).set_component_font_color("home.icon_top_03", 1055);
break;
case 3: //CLIMATE_ACTION_HEATING
id(disp1).set_component_text_printf("home.icon_top_03", "%s", "\uE237");
id(disp1).set_component_font_color("home.icon_top_03", 64164);
break;
case 4: //CLIMATE_ACTION_IDLE
id(disp1).set_component_text_printf("home.icon_top_03", "%s", "\uE50E"); // mdi:thermometer
id(disp1).set_component_font_color("home.icon_top_03", 35921);
break;
case 5: //CLIMATE_ACTION_DRYING
id(disp1).set_component_text_printf("home.icon_top_03", "%s", "\uE58D");
id(disp1).set_component_font_color("home.icon_top_03", 64704);
break;
case 6: //CLIMATE_ACTION_FAN
id(disp1).set_component_text_printf("home.icon_top_03", "%s", "\uE20F");
id(disp1).set_component_font_color("home.icon_top_03", 1530);
break;
}
- id: refresh_wifi_icon
mode: restart
then:
- if:
condition:
- binary_sensor.is_on: nextion_init
#- text_sensor.state: # Is home page visible?
# id: current_page
# state: 'home'
then:
# Update Wi-Fi icon
- if:
condition:
wifi.connected:
then:
- if:
condition:
api.connected:
then:
- lambda: id(disp1).set_component_value("home.api",1);
- lambda: id(disp1).set_component_text_printf("home.wifi_icon", "%s", "\uE5A8");
- lambda: id(disp1).set_component_font_color("home.wifi_icon", 33808);
else:
- lambda: id(disp1).set_component_value("home.api",0);
- lambda: id(disp1).set_component_text_printf("home.wifi_icon", "%s", "\uF256");
- lambda: id(disp1).set_component_font_color("home.wifi_icon", 63488);
else:
- lambda: id(disp1).set_component_value("home.api",0);
- lambda: id(disp1).set_component_text_printf("home.wifi_icon", "%s", "\uE5A9");
- lambda: id(disp1).set_component_font_color("home.wifi_icon", 63488);
- id: update_page_home
mode: restart
then:
- script.execute:
id: refresh_datetime
- script.execute:
id: refresh_relays
- script.execute:
id: refresh_wifi_icon
- script.execute:
id: refresh_chips_climate
- if:
condition:
- binary_sensor.is_on: nextion_init
- text_sensor.state: # Is home page visible?
id: current_page
state: 'home'
then:
- lambda: |-
// Update home.entity variable
if (id(is_embedded_thermostat) and not (${embedded_thermostat_disabled})) id(disp1).set_component_text_printf("home.entity", "embedded_climate");
else id(disp1).set_component_text_printf("home.entity", "");
- id: update_page_climate
mode: restart
then:
- 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_embedded_thermostat_visible);
- lambda: !lambda 'return (not ${embedded_thermostat_disabled});'
then: # Embedded thermostat is visible
# Update slider, current temperature & target temperature
- script.execute:
id: set_climate
current_temp: !lambda "return id(thermostat_embedded).current_temperature;"
target_temp: !lambda "return id(thermostat_embedded).target_temperature;"
temp_step: !lambda "return int(round(${embedded_thermostat_visual_temperature_step}*10));"
total_steps: !lambda |-
float temp_step = ${embedded_thermostat_visual_temperature_step};
float temp_offset = ${embedded_thermostat_visual_min_temperature};
float temp_max = ${embedded_thermostat_visual_max_temperature};
float total_steps = (temp_max-temp_offset)/temp_step;
return int(round(total_steps));
slider_val: !lambda |-
float temp_step = ${embedded_thermostat_visual_temperature_step};
float temp_offset = ${embedded_thermostat_visual_min_temperature};
return int(round((10*id(thermostat_embedded).target_temperature-temp_offset)/temp_step));
temp_offset: !lambda "return int(round(${embedded_thermostat_visual_min_temperature}*10));"
climate_icon: ""
embedded_climate: True
# Update target temp icon
- lambda: |-
if (${verbose_log}) ESP_LOGD("script.update_page_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
{
case 0: //CLIMATE_ACTION_OFF
if (${verbose_log}) ESP_LOGD("script.update_page_climate", "thermostat_embedded.mode=%i", int(id(thermostat_embedded).mode));
switch (int(id(thermostat_embedded).mode)) // CLIMATE_MODE_OFF = 0, CLIMATE_MODE_HEAT_COOL = 1, CLIMATE_MODE_COOL = 2, CLIMATE_MODE_HEAT = 3, CLIMATE_MODE_FAN_ONLY = 4, CLIMATE_MODE_DRY = 5, CLIMATE_MODE_AUTO = 6
{
case 0: //CLIMATE_MODE_OFF
id(disp1).set_component_text_printf("climate.target_icon", "%s", "\uFFFF"); // (E424) Don't show icon when off
id(disp1).set_component_font_color("climate.target_icon", 35921);
break;
case 1: //CLIMATE_MODE_HEAT_COOL
id(disp1).set_component_text_printf("climate.target_icon", "%s", "\uE069");
id(disp1).set_component_font_color("climate.target_icon", 35921);
break;
case 2: //CLIMATE_MODE_COOL
id(disp1).set_component_text_printf("climate.target_icon", "%s", "\uE716");
id(disp1).set_component_font_color("climate.target_icon", 1055);
break;
case 3: //CLIMATE_MODE_HEAT
id(disp1).set_component_text_printf("climate.target_icon", "%s", "\uE237");
id(disp1).set_component_font_color("climate.target_icon", 64164);
break;
case 4: //CLIMATE_MODE_FAN_ONLY
id(disp1).set_component_text_printf("climate.target_icon", "%s", "\uE20F");
id(disp1).set_component_font_color("climate.target_icon", 35921);
break;
case 5: //CLIMATE_MODE_DRY
id(disp1).set_component_text_printf("climate.target_icon", "%s", "\uE58D");
id(disp1).set_component_font_color("climate.target_icon", 64704);
break;
case 6: //CLIMATE_MODE_AUTO
id(disp1).set_component_text_printf("climate.target_icon", "%s", "\uEE8D");
id(disp1).set_component_font_color("climate.target_icon", 35921);
break;
}
case 2: //CLIMATE_ACTION_COOLING
id(disp1).set_component_text_printf("climate.target_icon", "%s", "\uE716");
id(disp1).set_component_font_color("climate.target_icon", 1055);
break;
case 3: //CLIMATE_ACTION_HEATING
id(disp1).set_component_text_printf("climate.target_icon", "%s", "\uE237");
id(disp1).set_component_font_color("climate.target_icon", 64164);
break;
case 4: //CLIMATE_ACTION_IDLE
id(disp1).set_component_text_printf("climate.target_icon", "%s", "\uE50E"); // mdi:thermometer
id(disp1).set_component_font_color("climate.target_icon", 35921);
break;
case 5: //CLIMATE_ACTION_DRYING
id(disp1).set_component_text_printf("climate.target_icon", "%s", "\uE58D");
id(disp1).set_component_font_color("climate.target_icon", 64704);
break;
case 6: //CLIMATE_ACTION_FAN
id(disp1).set_component_text_printf("climate.target_icon", "%s", "\uE20F");
id(disp1).set_component_font_color("climate.target_icon", 1530);
break;
}
# Update buttons bar
- lambda: |-
if (${verbose_log}) ESP_LOGD("script.update_page_climate", "Updating buttons bar");
// Hide not supported hotspots
id(disp1).hide_component("climate.button01");
id(disp1).hide_component("climate.button02");
id(disp1).show_component("climate.button03"); //Heat
id(disp1).hide_component("climate.button04");
id(disp1).hide_component("climate.button05");
id(disp1).hide_component("climate.button06");
id(disp1).show_component("climate.button07"); //Off
// Set buttons colors
id(disp1).set_component_font_color("climate.button01_icon", 10597);
id(disp1).set_component_font_color("climate.button02_icon", 10597);
id(disp1).set_component_font_color("climate.button03_icon", (id(thermostat_embedded).mode==climate::CLIMATE_MODE_HEAT) ? 64164 : 48631);
id(disp1).set_component_font_color("climate.button04_icon", 10597);
id(disp1).set_component_font_color("climate.button05_icon", 10597);
id(disp1).set_component_font_color("climate.button06_icon", 10597);
id(disp1).set_component_font_color("climate.button07_icon", (id(thermostat_embedded).mode==climate::CLIMATE_MODE_OFF) ? 35921 : 48631);
climate:
- platform: thermostat
name: ${device_name} Thermostat
id: thermostat_embedded
sensor: temp_nspanel
min_heating_off_time: ${embedded_thermostat_min_heating_off_time}s
min_heating_run_time: ${embedded_thermostat_min_heating_run_time}s
min_idle_time: ${embedded_thermostat_min_idle_time}s
visual:
min_temperature: ${embedded_thermostat_visual_min_temperature} ${embedded_thermostat_temp_units}
max_temperature: ${embedded_thermostat_visual_max_temperature} ${embedded_thermostat_temp_units}
temperature_step: ${embedded_thermostat_visual_temperature_step} ${embedded_thermostat_temp_units}
# target_temperature: 0.5 #!lambda "return ${embedded_thermostat_visual_target_temperature_step};"
# current_temperature: 0.1 #!lambda "return ${embedded_thermostat_visual_current_temperature_step};"
heat_action:
- switch.turn_on: relay_${embedded_thermostat_heater_relay}
idle_action:
- switch.turn_off: relay_${embedded_thermostat_heater_relay}
default_preset: "Off"
on_boot_restore_from: memory
preset:
- name: "Off"
default_target_temperature_low: ${embedded_thermostat_visual_min_temperature} ${embedded_thermostat_temp_units}
mode: "off"
- name: Home
default_target_temperature_low: 21 ${embedded_thermostat_temp_units}
internal: ${embedded_thermostat_disabled}
on_state:
- logger.log: Climate state changed - Start
- script.execute:
id: update_page_climate
- logger.log: Climate state changed - End