-
-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathnspanel_esphome_addon_climate_base.yaml
More file actions
462 lines (414 loc) · 23.4 KB
/
nspanel_esphome_addon_climate_base.yaml
File metadata and controls
462 lines (414 loc) · 23.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
#####################################################################################################
##### NSPanel Easy - https://github.com/edwardtfn/NSPanel-Easy #####
#####################################################################################################
##### ESPHome Add-on for Climate control - Shared - This will be called by heat/cool #####
##### PLEASE only make changes if it is necessary and also the required knowledge is available. #####
##### For normal use with the Blueprint, no changes are necessary. #####
#####################################################################################################
##### ATTENTION: This will add climate elements to the core system and requires the core part. #####
#####################################################################################################
---
substitutions:
##############################
## Change only in your ##
## local yaml substitutions ##
##############################
### Local thermostat defaults ###
# https://esphome.io/components/climate/thermostat.html
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"
# https://esphome.io/components/climate/index.html#base-climate-configuration
temp_min: ${45 if TEMP_UNIT_IS_FAHRENHEIT else 7}
temp_max: ${95 if TEMP_UNIT_IS_FAHRENHEIT else 35}
target_low: ${64 if TEMP_UNIT_IS_FAHRENHEIT else 18}
target_high: ${75 if TEMP_UNIT_IS_FAHRENHEIT else 24}
cool_deadband: ${1 if TEMP_UNIT_IS_FAHRENHEIT else 0.5} # Temperature delta before engaging cooling
cool_overrun: ${1 if TEMP_UNIT_IS_FAHRENHEIT else 0.5} # Temperature delta before disengaging cooling
heat_deadband: ${1 if TEMP_UNIT_IS_FAHRENHEIT else 0.5} # Temperature delta before engaging heat
heat_overrun: ${1 if TEMP_UNIT_IS_FAHRENHEIT else 0.5} # Temperature delta before disengaging heat
climate_chip_visibility_default: "0" # CLIMATE_CHIP_ACTIVE_ONLY
TAG_ADDON_CLIMATE: nspanel.addon.climate
esphome:
platformio_options:
build_flags:
- -D NSPANEL_EASY_ADDON_CLIMATE_BASE
climate:
- platform: thermostat
name: Thermostat
id: thermostat_embedded
sensor: temp_nspanel
min_idle_time: ${min_idle_time}s
visual:
min_temperature: ${temp_min} ${temp_units}
max_temperature: ${temp_max} ${temp_units}
temperature_step:
target_temperature: ${1 if TEMP_UNIT_IS_FAHRENHEIT else 0.5} ${temp_units}
current_temperature: ${1 if TEMP_UNIT_IS_FAHRENHEIT else 0.1} ${temp_units}
default_preset: "Off"
on_boot_restore_from: memory
startup_delay: true
internal: false
on_state:
then:
- lambda: |-
ESP_LOGV("${TAG_ADDON_CLIMATE}", "Climate have a new state");
if (!is_device_ready_for_tasks()) {
ESP_LOGW("${TAG_ADDON_CLIMATE}", "Device not ready to work with the new state");
return;
}
if (current_page_id == get_page_id("climate") and detailed_entity->state == "embedded_climate") {
ESP_LOGV("${TAG_ADDON_CLIMATE}", "Update page 'climate'");
page_climate->execute();
}
ESP_LOGV("${TAG_ADDON_CLIMATE}", "Update page 'home'");
page_home->execute();
globals:
- id: climate_chip_visibility
type: uint8_t
restore_value: true
initial_value: '${climate_chip_visibility_default}'
switch:
##### PHYSICAL SWITCH 0 (Dummy) - Used when relay is not set #####
- name: Relay 0 (dummy)
platform: template
id: relay_0
lambda: !lambda return false;
internal: true
optimistic: true
script:
- id: !extend action_component_text
then:
- lambda: |-
if (page != "mem") return;
if (component == "addon_climate_friendly_name") {
ESP_LOGV("${TAG_ADDON_CLIMATE}", "Set addon_climate_friendly_name:");
ESP_LOGV("${TAG_ADDON_CLIMATE}", " from: %s", addon_climate_friendly_name.c_str());
ESP_LOGV("${TAG_ADDON_CLIMATE}", " to: %s", txt.c_str());
addon_climate_friendly_name = txt;
return;
}
- id: !extend action_component_val
then:
- lambda: |-
if (page != "mem") return;
if (component == "climate_chip_visibility") {
const bool valid = (val >= static_cast<int>(nspanel_easy::CLIMATE_CHIP_ACTIVE_ONLY) &&
val <= static_cast<int>(nspanel_easy::CLIMATE_CHIP_NEVER));
id(climate_chip_visibility) = valid
? static_cast<uint8_t>(val)
: static_cast<uint8_t>(nspanel_easy::CLIMATE_CHIP_ACTIVE_ONLY);
if (!valid) {
ESP_LOGW("${TAG_ADDON_CLIMATE}", "Invalid climate_chip_visibility: %d. Falling back to ACTIVE_ONLY", val);
}
ESP_LOGD("${TAG_ADDON_CLIMATE}", "climate_chip_visibility set to %" PRIu8, id(climate_chip_visibility));
}
- id: !extend change_climate_state
then:
- lambda: |-
ESP_LOGV("${TAG_ADDON_CLIMATE}", "Add-on climate code starting");
if (!embedded) {
ESP_LOGV("${TAG_ADDON_CLIMATE}", "Not showing the embedded climate");
return;
}
auto call = thermostat_embedded->make_call();
float temperature;
ESP_LOGV("${TAG_ADDON_CLIMATE}", "Inform display that is showing embedded climate");
disp1->set_component_value("climate.embedded", 1);
if (key == "hvac_mode") {
ESP_LOGV("${TAG_ADDON_CLIMATE}", "Set 'hvac_mode' to '%s'", value.c_str());
call.set_mode(value);
} else {
temperature = stof(value) / 10;
if (key == "temperature") {
ESP_LOGV("${TAG_ADDON_CLIMATE}", "Set target temperature to %f${temp_units}", temperature);
#if NSPANEL_EASY_HW_TEMPERATURE_IS_FAHRENHEIT
call.set_target_temperature(roundf(fahrenheit_to_celsius(temperature) * 1000.0f) / 1000.0f);
#else // Celsius
call.set_target_temperature(temperature);
#endif // NSPANEL_EASY_HW_TEMPERATURE_IS_FAHRENHEIT
} else if (key == "target_temp_high") {
ESP_LOGV("${TAG_ADDON_CLIMATE}", "Set target temperature high to %f${temp_units}", temperature);
#if NSPANEL_EASY_HW_TEMPERATURE_IS_FAHRENHEIT
call.set_target_temperature_high(roundf(fahrenheit_to_celsius(temperature) * 1000.0f) / 1000.0f);
#else // Celsius
call.set_target_temperature_high(temperature);
#endif // NSPANEL_EASY_HW_TEMPERATURE_IS_FAHRENHEIT
} else if (key == "target_temp_low") {
ESP_LOGV("${TAG_ADDON_CLIMATE}", "Set target temperature low to %f${temp_units}", temperature);
#if NSPANEL_EASY_HW_TEMPERATURE_IS_FAHRENHEIT
call.set_target_temperature_low(roundf(fahrenheit_to_celsius(temperature) * 1000.0f) / 1000.0f);
#else // Celsius
call.set_target_temperature_low(temperature);
#endif // NSPANEL_EASY_HW_TEMPERATURE_IS_FAHRENHEIT
}
}
ESP_LOGV("${TAG_ADDON_CLIMATE}", "Perform action");
call.perform();
ESP_LOGV("${TAG_ADDON_CLIMATE}", "Action done");
- id: !extend dump_config
then:
- lambda: |-
// Check if more than one or none of the climate options are defined
#if defined(NSPANEL_EASY_ADDON_CLIMATE_COOL) && defined(NSPANEL_EASY_ADDON_CLIMATE_HEAT)
#error "Invalid settings for add-on Climate. More than one option selected: Cool + Heat."
#elif defined(NSPANEL_EASY_ADDON_CLIMATE_COOL) && defined(NSPANEL_EASY_ADDON_CLIMATE_DUAL)
#error "Invalid settings for add-on Climate. More than one option selected: Cool + Dual."
#elif defined(NSPANEL_EASY_ADDON_CLIMATE_HEAT) && defined(NSPANEL_EASY_ADDON_CLIMATE_DUAL)
#error "Invalid settings for add-on Climate. More than one option selected: Heat + Dual."
#elif !defined(NSPANEL_EASY_ADDON_CLIMATE_COOL) && !defined(NSPANEL_EASY_ADDON_CLIMATE_HEAT) && !defined(NSPANEL_EASY_ADDON_CLIMATE_DUAL)
#error "Invalid settings for add-on Climate. No option selected between Cool, Heat or Dual."
#endif
#ifndef NSPANEL_EASY_PAGE_CLIMATE
#error "'nspanel_esphome_page_climate.yaml' is required."
#endif
const uint cooler_relay = ${cooler_relay};
const uint heater_relay = ${heater_relay};
ESP_LOGCONFIG("${TAG_ADDON_CLIMATE}", "Add-on climate:");
#ifdef NSPANEL_EASY_ADDON_CLIMATE_COOL
ESP_LOGCONFIG("${TAG_ADDON_CLIMATE}", " Cool: Enabled");
ESP_LOGCONFIG("${TAG_ADDON_CLIMATE}", " Relay: %u", cooler_relay);
ESP_LOGE_IF("${TAG_ADDON_CLIMATE}", (cooler_relay != 1 and cooler_relay != 2), " Relay: %u", cooler_relay);
#endif // NSPANEL_EASY_ADDON_CLIMATE_COOL
#ifdef NSPANEL_EASY_ADDON_CLIMATE_HEAT
ESP_LOGCONFIG("${TAG_ADDON_CLIMATE}", " Heat: Enabled");
ESP_LOGCONFIG("${TAG_ADDON_CLIMATE}", " Relay: %u", heater_relay);
ESP_LOGE_IF("${TAG_ADDON_CLIMATE}", (heater_relay != 1 and heater_relay != 2), " Relay: %u", heater_relay);
#endif // NSPANEL_EASY_ADDON_CLIMATE_HEAT
#ifdef NSPANEL_EASY_ADDON_CLIMATE_DUAL
ESP_LOGCONFIG("${TAG_ADDON_CLIMATE}", " Dual: Enabled");
ESP_LOGCONFIG("${TAG_ADDON_CLIMATE}", " Relay (cooler): %u", cooler_relay);
ESP_LOGE_IF("${TAG_ADDON_CLIMATE}", (cooler_relay != 1 and cooler_relay != 2), " Relay (cooler): %u", cooler_relay);
ESP_LOGCONFIG("${TAG_ADDON_CLIMATE}", " Relay (heater): %u", heater_relay);
ESP_LOGE_IF("${TAG_ADDON_CLIMATE}", (heater_relay != 1 and heater_relay != 2), " Relay (heater): %u", heater_relay);
#endif // NSPANEL_EASY_ADDON_CLIMATE_DUAL
- id: !extend page_climate
then:
- lambda: |-
if (current_page_id != get_page_id("climate")) return;
if (not id(is_embedded_thermostat)) return;
if (detailed_entity->state.empty()) return;
if (detailed_entity->state != "embedded_climate") return;
ESP_LOGV("${TAG_ADDON_CLIMATE}", "Construct climate page with embedded climate");
// Get climate traits
ESP_LOGV("${TAG_ADDON_CLIMATE}", "Get climate traits");
const ClimateTraits traits = thermostat_embedded->get_traits();
// Set page label
ESP_LOGV("${TAG_ADDON_CLIMATE}", "Set page label");
disp1->set_component_text("page_label", addon_climate_friendly_name.c_str());
// Feed watchdog
delay(${DELAY_SHORT});
App.feed_wdt();
if (current_page_id != get_page_id("climate")) return;
// Extract temperature values (static since they don't change during runtime)
ESP_LOGV("${TAG_ADDON_CLIMATE}", "Extracted temperature values:");
#if NSPANEL_EASY_HW_TEMPERATURE_IS_FAHRENHEIT
static const float temp_step = traits.get_visual_target_temperature_step() * 1.8f;
static const float temp_offset = celsius_to_fahrenheit(traits.get_visual_min_temperature());
static const float temp_max = celsius_to_fahrenheit(traits.get_visual_max_temperature());
#else // Celsius
static const float temp_step = traits.get_visual_target_temperature_step();
static const float temp_offset = traits.get_visual_min_temperature();
static const float temp_max = traits.get_visual_max_temperature();
#endif // NSPANEL_EASY_HW_TEMPERATURE_IS_FAHRENHEIT
ESP_LOGV("${TAG_ADDON_CLIMATE}", " temp_step: %f${temp_units}", temp_step);
ESP_LOGV("${TAG_ADDON_CLIMATE}", " temp_offset: %f${temp_units}", temp_offset);
ESP_LOGV("${TAG_ADDON_CLIMATE}", " temp_max: %f${temp_units}", temp_max);
// Feed watchdog
delay(${DELAY_SHORT});
App.feed_wdt();
if (current_page_id != get_page_id("climate")) return;
// Calculate static values
ESP_LOGV("${TAG_ADDON_CLIMATE}", "Calculated static values:");
static uint16_t total_steps;
total_steps = static_cast<uint16_t>(std::round((temp_max - temp_offset) / temp_step));
ESP_LOGV("${TAG_ADDON_CLIMATE}", " temp_step: %f${temp_units}", temp_step);
ESP_LOGV("${TAG_ADDON_CLIMATE}", " temp_offset: %f${temp_units}", temp_offset);
ESP_LOGV("${TAG_ADDON_CLIMATE}", " total_steps: %i", total_steps);
// Feed watchdog
delay(${DELAY_SHORT});
App.feed_wdt();
if (current_page_id != get_page_id("climate")) return;
// Get dynamic temperature values
ESP_LOGV("${TAG_ADDON_CLIMATE}", "Get dynamic temperature values:");
static float temp_target;
static float temp_target_high;
static float temp_target_low;
#if NSPANEL_EASY_HW_TEMPERATURE_IS_FAHRENHEIT
temp_target = celsius_to_fahrenheit(thermostat_embedded->target_temperature);
temp_target_high = celsius_to_fahrenheit(thermostat_embedded->target_temperature_high);
temp_target_low = celsius_to_fahrenheit(thermostat_embedded->target_temperature_low);
const float temp_current = celsius_to_fahrenheit(thermostat_embedded->current_temperature);
#else // Celsius
temp_target = thermostat_embedded->target_temperature;
temp_target_high = thermostat_embedded->target_temperature_high;
temp_target_low = thermostat_embedded->target_temperature_low;
const float temp_current = thermostat_embedded->current_temperature;
#endif // NSPANEL_EASY_HW_TEMPERATURE_IS_FAHRENHEIT
ESP_LOGV("${TAG_ADDON_CLIMATE}", " temp_target: %f${temp_units}", temp_target);
ESP_LOGV("${TAG_ADDON_CLIMATE}", " temp_target_high: %f${temp_units}", temp_target_high);
ESP_LOGV("${TAG_ADDON_CLIMATE}", " temp_target_low: %f${temp_units}", temp_target_low);
ESP_LOGV("${TAG_ADDON_CLIMATE}", " temp_current: %f${temp_units}", temp_current);
feed_wdt_delay(${DELAY_SHORT});
if (current_page_id != get_page_id("climate")) return;
#ifdef NSPANEL_EASY_ADDON_CLIMATE_DUAL
ESP_LOGV("${TAG_ADDON_CLIMATE}", "Is add-on Climate dual: YES");
#else
ESP_LOGV("${TAG_ADDON_CLIMATE}", "Is add-on Climate dual: NO");
#endif // NSPANEL_EASY_ADDON_CLIMATE_DUAL
// Set vars for set_climate
ESP_LOGV("${TAG_ADDON_CLIMATE}", "Set vars for set_climate");
set_climate_current_temp = temp_current;
set_climate_supported_features = 0;
#ifdef NSPANEL_EASY_ADDON_CLIMATE_DUAL
set_climate_target_temp = -999;
set_climate_target_temp_high = temp_target_high;
set_climate_target_temp_low = temp_target_low;
#else
set_climate_target_temp = temp_target;
set_climate_target_temp_high = -999;
set_climate_target_temp_low = -999;
#endif // NSPANEL_EASY_ADDON_CLIMATE_DUAL
set_climate_temp_step = int(roundf(temp_step*10));
set_climate_total_steps = total_steps;
set_climate_temp_offset = int(roundf(temp_offset*10));
set_climate_climate_icon = "";
set_climate_embedded_climate = true;
feed_wdt_delay(${DELAY_SHORT});
if (current_page_id != get_page_id("climate")) return;
// Execute set_climate
ESP_LOGV("${TAG_ADDON_CLIMATE}", "Call set_climate");
set_climate->execute();
// Update target temp icon
ESP_LOGV("${TAG_ADDON_CLIMATE}", "Call update_climate_icon");
update_climate_icon->execute("climate.target_icon",
int(thermostat_embedded->action), int(thermostat_embedded->mode));
// Update buttons bar
// Hide not supported hotspots
ESP_LOGV("${TAG_ADDON_CLIMATE}", "Update buttons bar");
disp1->hide_component("button01");
disp1->set_component_font_color("climate.button01", static_cast<uint16_t>(Colors::GRAY_DARK));
#ifdef NSPANEL_EASY_ADDON_CLIMATE_DUAL
disp1->show_component("button02");
disp1->set_component_font_color("climate.button02", static_cast<uint16_t>(
(thermostat_embedded->mode==climate::CLIMATE_MODE_HEAT_COOL) ? Colors::WHITE : Colors::GRAY_LIGHT));
#else
disp1->hide_component("button02");
disp1->set_component_font_color("climate.button02", static_cast<uint16_t>(
(thermostat_embedded->mode==climate::CLIMATE_MODE_HEAT_COOL) ? Colors::WHITE : Colors::GRAY_DARK));
#endif // NSPANEL_EASY_ADDON_CLIMATE_DUAL
feed_wdt_delay(${DELAY_SHORT});
if (current_page_id != get_page_id("climate")) return;
#if defined(NSPANEL_EASY_ADDON_CLIMATE_HEAT) || defined(NSPANEL_EASY_ADDON_CLIMATE_DUAL)
disp1->show_component("button03"); // Heat
disp1->set_component_font_color("climate.button03", static_cast<uint16_t>(
(thermostat_embedded->mode==climate::CLIMATE_MODE_HEAT) ? Colors::DEEP_ORANGE : Colors::GRAY_LIGHT));
#else
disp1->hide_component("button03"); // Heat
disp1->set_component_font_color("climate.button03", static_cast<uint16_t>(
(thermostat_embedded->mode==climate::CLIMATE_MODE_HEAT) ? Colors::DEEP_ORANGE : Colors::GRAY_DARK));
#endif // NSPANEL_EASY_ADDON_CLIMATE_HEAT || NSPANEL_EASY_ADDON_CLIMATE_DUAL
feed_wdt_delay(${DELAY_SHORT});
if (current_page_id != get_page_id("climate")) return;
#if defined(NSPANEL_EASY_ADDON_CLIMATE_COOL) || defined(NSPANEL_EASY_ADDON_CLIMATE_DUAL)
disp1->show_component("button04"); // Cool
disp1->set_component_font_color("climate.button04", static_cast<uint16_t>(
(thermostat_embedded->mode==climate::CLIMATE_MODE_COOL) ? Colors::BLUE : Colors::GRAY_LIGHT));
#else
disp1->hide_component("button04"); // Cool
disp1->set_component_font_color("climate.button04", static_cast<uint16_t>(
(thermostat_embedded->mode==climate::CLIMATE_MODE_COOL) ? Colors::BLUE : Colors::GRAY_DARK));
#endif // NSPANEL_EASY_ADDON_CLIMATE_COOL || NSPANEL_EASY_ADDON_CLIMATE_DUAL
feed_wdt_delay(${DELAY_SHORT});
if (current_page_id != get_page_id("climate")) return;
disp1->hide_component("button05");
disp1->set_component_font_color("climate.button05", static_cast<uint16_t>(Colors::GRAY_DARK));
feed_wdt_delay(${DELAY_SHORT});
if (current_page_id != get_page_id("climate")) return;
disp1->hide_component("button06");
disp1->set_component_font_color("climate.button06", static_cast<uint16_t>(Colors::GRAY_DARK));
feed_wdt_delay(${DELAY_SHORT});
if (current_page_id != get_page_id("climate")) return;
disp1->show_component("button07"); // Off
disp1->set_component_font_color("climate.button07", static_cast<uint16_t>(
(thermostat_embedded->mode==climate::CLIMATE_MODE_OFF)
? Colors::BLUE_INDIGO : Colors::GRAY));
- id: !extend page_home
then:
- lambda: |-
if (id(is_embedded_thermostat)) {
update_climate_icon->execute(hmi::home::CHIP_CLIMATE.name,
int(thermostat_embedded->action), int(thermostat_embedded->mode));
}
- id: !extend stop_all
then:
- lambda: |-
update_climate_icon->stop();
- id: update_climate_icon
mode: single
parameters:
component: string
action: uint
mode: uint
then:
- lambda: |-
ESP_LOGV("${TAG_ADDON_CLIMATE}", "Update climate icon");
ESP_LOGV("${TAG_ADDON_CLIMATE}", " component: %s", component.c_str());
ESP_LOGV("${TAG_ADDON_CLIMATE}", " action: %d", action);
ESP_LOGV("${TAG_ADDON_CLIMATE}", " mode: %d", mode);
ESP_LOGV("${TAG_ADDON_CLIMATE}", " visibility: %" PRIu8, id(climate_chip_visibility));
// Determine visibility based on user preference and current climate state
const auto visibility = static_cast<nspanel_easy::ClimateChipVisibility>(id(climate_chip_visibility));
const bool is_active = (action == nspanel_easy::CLIMATE_ACTION_COOLING ||
action == nspanel_easy::CLIMATE_ACTION_HEATING ||
action == nspanel_easy::CLIMATE_ACTION_DRYING ||
action == nspanel_easy::CLIMATE_ACTION_FAN);
bool visible = false;
if (visibility == nspanel_easy::CLIMATE_CHIP_NEVER) {
visible = false; // Never show
} else if (visibility == nspanel_easy::CLIMATE_CHIP_ALWAYS) {
visible = true; // Always show
} else {
visible = is_active; // Active only (default)
}
ESP_LOGV("${TAG_ADDON_CLIMATE}", " visible: %s", YESNO(visible));
const char* icon = Icons::NONE;
uint16_t color = Colors::BLACK;
if (visible) {
if (action == nspanel_easy::CLIMATE_ACTION_OFF) {
// Handle OFF action — only reached when visibility != NEVER
if (mode <= nspanel_easy::CLIMATE_MODE_AUTO) {
icon = climate_off_mode_icons[mode].icon;
color = climate_off_mode_icons[mode].color;
}
} else if (is_active) {
// Handle actively running states (heating/cooling/drying/fan)
icon = climate_action_icons[action].icon;
color = climate_action_icons[action].color;
} else if (action == nspanel_easy::CLIMATE_ACTION_IDLE) {
// Handle idle — only reached when visibility == ALWAYS
icon = climate_action_icons[nspanel_easy::CLIMATE_ACTION_IDLE].icon;
color = climate_action_icons[nspanel_easy::CLIMATE_ACTION_IDLE].color;
}
} // #endif visible — icon/color remain NONE/BLACK when hidden
// Extract component information using helper function
const esphome::nspanel_easy::NSPanelEasyNextionComponent comp =
extractNextionComponent(component, page_names[current_page_id]);
// Determine target ID format based on page context
const char* target_id;
char full_id[30]; // 14 + 1 (dot) + 14 + 1 (null) = 30
if (strcmp(comp.page, page_names[current_page_id]) == 0) {
// Use short format for current page: "id"
target_id = comp.component_id;
} else {
// Use full format for other pages: "page.id"
snprintf(full_id, sizeof(full_id), "%s.%s", comp.page, comp.component_id);
target_id = full_id;
}
ESP_LOGV("${TAG_ADDON_CLIMATE}", " target: %s", target_id);
// Apply the icon and color to the display component
disp1->set_component_text(target_id, icon);
disp1->set_component_font_color(target_id, static_cast<uint16_t>(color));
...