@@ -82,20 +82,31 @@ script:
|
|||||||
- id: !extend change_climate_state
|
- id: !extend change_climate_state
|
||||||
then:
|
then:
|
||||||
- lambda: |-
|
- lambda: |-
|
||||||
|
auto FahrenheitToCelsius = [](float fahrenheit) -> float {
|
||||||
|
return (fahrenheit - 32.0) * 5.0 / 9.0;
|
||||||
|
};
|
||||||
|
|
||||||
if (embedded) {
|
if (embedded) {
|
||||||
static const char *const TAG = "addon_climate_base.script.change_climate_state";
|
static const char *const TAG = "addon_climate_base.script.change_climate_state";
|
||||||
id(is_addon_climate_visible) = true;
|
id(is_addon_climate_visible) = true;
|
||||||
disp1->set_component_value("climate.embedded", 1);
|
disp1->set_component_value("climate.embedded", 1);
|
||||||
auto call = thermostat_embedded->make_call();
|
auto call = thermostat_embedded->make_call();
|
||||||
|
float temperature;
|
||||||
if (key == "temperature") {
|
if (key == "temperature") {
|
||||||
ESP_LOGD(TAG, "set_target_temperature(%f)", (stof(value) / 10));
|
temperature = stof(value) / 10;
|
||||||
call.set_target_temperature(stof(value) / 10);
|
if (id(temp_unit_fahrenheit)) temperature = FahrenheitToCelsius(temperature);
|
||||||
|
ESP_LOGD(TAG, "set_target_temperature(%f)", temperature);
|
||||||
|
call.set_target_temperature(temperature);
|
||||||
} else if (key == "target_temp_high") {
|
} else if (key == "target_temp_high") {
|
||||||
ESP_LOGD(TAG, "set_target_temperature_high(%f)", (stof(value) / 10));
|
temperature = stof(value) / 10;
|
||||||
call.set_target_temperature_high(stof(value) / 10);
|
if (id(temp_unit_fahrenheit)) temperature = FahrenheitToCelsius(temperature);
|
||||||
|
ESP_LOGD(TAG, "set_target_temperature_high(%f)", temperature);
|
||||||
|
call.set_target_temperature_high(temperature);
|
||||||
} else if (key == "target_temp_low") {
|
} else if (key == "target_temp_low") {
|
||||||
ESP_LOGD(TAG, "set_target_temperature_low(%f)", (stof(value) / 10));
|
temperature = stof(value) / 10;
|
||||||
call.set_target_temperature_low(stof(value) / 10);
|
if (id(temp_unit_fahrenheit)) temperature = FahrenheitToCelsius(temperature);
|
||||||
|
ESP_LOGD(TAG, "set_target_temperature_low(%f)", temperature);
|
||||||
|
call.set_target_temperature_low(temperature);
|
||||||
} else if (key == "hvac_mode") {
|
} else if (key == "hvac_mode") {
|
||||||
ESP_LOGD(TAG, "hvac_mode(%s)", value.c_str());
|
ESP_LOGD(TAG, "hvac_mode(%s)", value.c_str());
|
||||||
call.set_mode(value);
|
call.set_mode(value);
|
||||||
@@ -122,28 +133,48 @@ script:
|
|||||||
- id: !extend page_climate
|
- id: !extend page_climate
|
||||||
then:
|
then:
|
||||||
- lambda: |-
|
- lambda: |-
|
||||||
|
auto CelsiusToFahrenheit = [](float celsius) -> float {
|
||||||
|
return (celsius * 9 / 5) + 32;
|
||||||
|
};
|
||||||
|
|
||||||
id(is_addon_climate_visible) = (current_page->state == "climate" and detailed_entity->state == "embedded_climate");
|
id(is_addon_climate_visible) = (current_page->state == "climate" and detailed_entity->state == "embedded_climate");
|
||||||
if (id(is_addon_climate_visible)) {
|
if (id(is_addon_climate_visible)) {
|
||||||
static const char *const TAG = "addon_climate_base.script.page_climate";
|
static const char *const TAG = "addon_climate_base.script.page_climate";
|
||||||
ESP_LOGV(TAG, "Climate page constructor:");
|
ESP_LOGV(TAG, "Climate page constructor:");
|
||||||
ESP_LOGV(TAG, " Add-on mode: %s", (${addon_climate_dual}) ? "Dual" : ((${addon_climate_heat}) ? "Heat" : ((${addon_climate_cool}) ? "Cool" : "Unknown")));
|
ESP_LOGV(TAG, " Add-on mode: %s", (${addon_climate_dual}) ? "Dual" : ((${addon_climate_heat}) ? "Heat" : ((${addon_climate_cool}) ? "Cool" : "Unknown")));
|
||||||
|
ESP_LOGV(TAG, " Temp. units: %s", id(temp_unit_fahrenheit) ? "Fahrenheit" : "Celsius");
|
||||||
disp1->set_component_text_printf("page_label", id(addon_climate_friendly_name).c_str());
|
disp1->set_component_text_printf("page_label", id(addon_climate_friendly_name).c_str());
|
||||||
float temp_step = ${temp_step};
|
ClimateTraits traits = thermostat_embedded->get_traits();
|
||||||
float temp_offset = ${temp_min};
|
float temp_step = traits.get_visual_target_temperature_step();
|
||||||
float temp_max = ${temp_max};
|
float temp_offset = traits.get_visual_min_temperature();
|
||||||
|
float temp_max = traits.get_visual_max_temperature();
|
||||||
|
float temp_target = thermostat_embedded->target_temperature;
|
||||||
|
float temp_target_high = thermostat_embedded->target_temperature_high;
|
||||||
|
float temp_target_low = thermostat_embedded->target_temperature_low;
|
||||||
|
float temp_current = thermostat_embedded->current_temperature;
|
||||||
|
if (id(temp_unit_fahrenheit)) {
|
||||||
|
//temp_step = CelsiusToFahrenheit(temp_step);
|
||||||
|
temp_step = temp_step * 1.8;
|
||||||
|
temp_offset = CelsiusToFahrenheit(temp_offset);
|
||||||
|
temp_max = CelsiusToFahrenheit(temp_max);
|
||||||
|
temp_target = CelsiusToFahrenheit(temp_target);
|
||||||
|
temp_target_high = CelsiusToFahrenheit(temp_target_high);
|
||||||
|
temp_target_low = CelsiusToFahrenheit(temp_target_low);
|
||||||
|
temp_current = CelsiusToFahrenheit(temp_current);
|
||||||
|
}
|
||||||
float total_steps = (temp_max-temp_offset)/temp_step;
|
float total_steps = (temp_max-temp_offset)/temp_step;
|
||||||
set_climate->execute
|
set_climate->execute
|
||||||
(
|
(
|
||||||
thermostat_embedded->current_temperature, // current_temp
|
temp_current, // current_temp
|
||||||
0, // supported_features
|
0, // supported_features
|
||||||
((${addon_climate_dual}) ? -999 : thermostat_embedded->target_temperature), // target_temp
|
((${addon_climate_dual}) ? -999 : temp_target), // target_temp
|
||||||
((${addon_climate_dual}) ? thermostat_embedded->target_temperature_high : -999), // target_temp_high
|
((${addon_climate_dual}) ? temp_target_high : -999), // target_temp_high
|
||||||
((${addon_climate_dual}) ? thermostat_embedded->target_temperature_low : -999), // target_temp_low
|
((${addon_climate_dual}) ? temp_target_low : -999), // target_temp_low
|
||||||
int(round(${temp_step}*10)), // temp_step
|
int(round(temp_step*10)), // temp_step
|
||||||
int(round(total_steps)), // total_steps
|
int(round(total_steps)), // total_steps
|
||||||
int(round(${temp_min}*10)), // temp_offset
|
int(round(temp_offset*10)), // temp_offset
|
||||||
"", // climate_icon
|
"", // climate_icon
|
||||||
true // embedded_climate
|
true // embedded_climate
|
||||||
);
|
);
|
||||||
|
|
||||||
// Update target temp icon
|
// Update target temp icon
|
||||||
|
|||||||
Reference in New Issue
Block a user