generated from esphome/esphome-project-template
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathlytko-101-v1.yaml
643 lines (579 loc) · 21.3 KB
/
lytko-101-v1.yaml
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
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
substitutions:
devicename: "lytko101v1" # Host name, will be available as ${devicename}.local
friendly_devicename: "Bathroom" # UI visible name, will be added to all sensors and controls exposed to HA
target_temperture_low: "27.0" # Default low mark of the target temperature, can be changed from HA Thermostat GUI
target_temperture_high: "29.0" # Default high mark of the target temperature, can be changed from HA Thermostat GUI
# Hysteresis is calculated as temperature_high - teplerature_low
# Target temperature is calculated as the middle point between temperature_high and teplerature_low
# Target temperture can be changed from Lytko screen
# Compile time parameters
min_temperature: "5.0" # Minimal temperature in HA Thermostat GUI
max_temperature: "40.0" # Maximal temperature in HA Thermostat GUI
temperature_step: "0.5" # Temperature step in HA Thermostat GUI
temperature_shift: "0.0" # Constant shift (positive or negative) for the built in temperature sensor
temperature_sensor: int_ntc # Name of a temperature sensor. int_ntc is a built-in NTC sensor. If you want to hookup
# an external sensor using HA Sensor. See https://esphome.io/components/sensor/homeassistant.html
# Example sensor can be found below in the 'sensor' section
# NTC Thermistor Parameters, see thermistor manual for the detailed info
ntc_beta_constant: "3911" # NTC thermistor Beta coefficient
ntc_ref_temperature: "25" # Temperature when thermistor has the reference resistance, in C
ntc_ref_resistance: "10000" # Nominal / reference resistance of the attached thermistor in Ohms
ntc_measurement_resistor: "2200" # Measurement resistor, board has 2.2kOhm resistor, if you add another 2.2kOms resistor as described
# in the Lytko manual, it will have parallel connection to the board resistor, so
# the value of 1100 should be put here. Calculate as parallely connected resistors in case another
# nominal is used
# Heating floor parameters
floor_resistance: "813.8" # Resistance of heating cable / matt in Ohm
floor_mains_voltage: "230" # Typical mains voltage of your system (better to use a value from smart meter via HA, see below
# This should point to the public location of this yaml file.
dashboard_import:
package_import_url: github://anatoly-savchenkov/lytko-configs/lytko-101-v1.yaml@main
import_full_config: true
esphome:
name: ${devicename}
name_add_mac_suffix: true
platformio_options:
board_build.f_cpu: 160000000L
project:
name: "Lytko.Thermostat-101-v1"
version: "1.0"
on_boot:
priority: -100
then:
- lambda: |-
id(boot_counter) += 1;
preferences:
flash_write_interval: 1h
external_components:
#ESPHome 2022.12.0 + work around for soft UART issue + no bogus command during connect
- source:
type: git
url: https://github.com/anatoly-savchenkov/esphome
ref: lytko_nextion
components: [ nextion ]
esp8266:
board: nodemcuv2
restore_from_flash: true
board_flash_mode: dout
early_pin_init: false
# Enable logging
logger:
baud_rate: 74880
level: VERBOSE
uart:
id: uart_nextion
rx_pin: GPIO5
tx_pin: GPIO4
baud_rate: 9600
display:
- platform: nextion
id: disp
uart_id: uart_nextion
# update_interval: 60s
on_setup:
lambda: |-
if (wifi::global_wifi_component->has_sta()) {
id(disp).goto_page("loading_page");
} else {
id(disp).goto_page("config_wifi");
id(qr_presented) = true;
}
id(disp).set_component_value("temperature.lock_mode", id(child_lock));
on_page:
lambda: |-
if(x == 0x08) id(disp).set_backlight_brightness(id(locked_brightness).state/100.0f);
else id(disp).set_backlight_brightness(1.0f);
switch (x) {
case 0x01: /* temperature */
id(disp).set_component_value("signal_fill", id(wifi_level).state);
/* fall thorugh */
case 0x08: /* lock_page */ {
ESP_LOGD("main","Display shows temperature / lock page");
bool is_on = (id(lytko_therm).mode == CLIMATE_MODE_HEAT);
bool is_heating = (id(lytko_therm).action == CLIMATE_ACTION_HEATING);
id(disp).set_component_value("arrow_temp", is_heating);
id(disp).set_component_value("H_active", is_on);
id(disp).set_component_text_printf("degree_big", "%.1f", (id(lytko_therm).target_temperature_high + id(lytko_therm).target_temperature_low) / 2.0f);
if (!std::isnan(id(lytko_therm).current_temperature)) {
id(disp).set_component_text_printf("degree", "%.1f", id(lytko_therm).current_temperature);
} else {
id(disp).set_component_text("degree", "ERR");
}
break;
}
case 0x18: /* config_wifi */
ESP_LOGD("main","Display shows WiFi config page");
id(disp).set_component_text_printf("qr_wifi", "WIFI:T:nopass;S:%s;P:;;", wifi::global_wifi_component->get_ap().get_ssid().c_str());
break;
case 0x1C: { /* QR code for Web site, page name unknown */
ESP_LOGD("main","Display shows web config page");
auto ip = wifi::global_wifi_component->get_ip_address();
id(disp).set_component_text_printf("qr_ip", "http://%s", ip.str().c_str());
id(disp).set_component_text("label_ip", ip.str().c_str());
break;
}
case 0x0F: /* debug_page */
ESP_LOGD("main","Display shows debug page");
id(disp).set_component_text("uptime", id(uptime_human).state.c_str());
id(disp).set_component_text_printf("memory", "%uB / %u%% / %uB", (uint32_t)id(free_heap).state, (uint32_t)id(heap_frag).state, (uint32_t)id(max_heap_block).state);
break;
case 0x0D: /* temp_settings */
ESP_LOGD("main","Display shows Settings: min/max temperature page");
id(disp).set_component_text_printf("min_temp", "%.1f", id(lytko_therm).get_traits().get_visual_min_temperature());
id(disp).set_component_text_printf("max_temp", "%.1f", id(lytko_therm).get_traits().get_visual_max_temperature());
break;
case 0x06: /* config_hyster */
ESP_LOGD("main","Display shows Settings: temperature hysteresis/shift page");
id(disp).set_component_text_printf("hysteresis", "%.1f", id(lytko_therm).target_temperature_high - id(lytko_therm).target_temperature_low);
id(disp).set_component_text_printf("sensor_corr", "%.1f", ${temperature_shift});
break;
case 0x02: /* firmware_upd */
ESP_LOGD("main","Display shows vesion info page");
id(disp).set_component_text("esp_version", ("ESPHome " + id(esph_version).state).c_str());
break;
case 0x07: /* sensor_page */ {
ESP_LOGD("main","Display shows Settings: sensor type page");
uint16_t sensors[] = {3300, 5000, 6800, 10000, 12000, 15000, 14800, 20000, 33000, 47000};
int16_t active_sensor = -1;
for(int i = 0; i < sizeof(sensors)/sizeof(sensors[0]); i++) {
if( 0.99f * sensors[i] <= ${ntc_ref_resistance} && ${ntc_ref_resistance} <= 1.01f * sensors[i]) { active_sensor = i + 1; break; }
}
if (active_sensor != -1) {
id(disp).set_component_value("active_sensor", active_sensor);
}
break;
}
default:
ESP_LOGD("main","Display shows new page %u", x);
break;
}
debug:
update_interval: 5s
ota:
on_begin:
- lambda: |-
id(disp).goto_page("upd_progress");
id(disp).set_backlight_brightness(1.0f);
on_progress:
- lambda: |-
id(disp).set_component_value("update", (uint32_t)x);
id(disp).set_component_text_printf("percent", "%u", (uint32_t) roundf(x));
on_end:
- lambda: |-
id(disp).set_component_value("update", 100);
id(disp).set_component_text("percent", "100");
on_error:
- switch.turn_on: reboot
wifi:
ap: {} # This spawns an AP with the device name and mac address with no password.
on_connect:
- lambda: |-
id(disp).goto_page("temperature");
id(qr_presented) = false;
on_disconnect:
- lambda: |-
id(disp).goto_page("no_wifi_page");
mdns:
disabled: false
captive_portal:
# Enable Home Assistant API
api:
# Set timeout to none, as device can be used standalone
reboot_timeout: 0s
time:
- platform: homeassistant
#mqtt:
# broker: 192.168.0.101
# username: mqtt_user
# password: mqtt_password
# discovery: true
# discovery_prefix: lytko/homeassistant
# reboot_timeout: 60s
# keepalive: 15s
# log_topic: lytko/logs
globals:
- id: boot_counter
type: int
restore_value: yes
initial_value: '0'
- id: child_lock
type: bool
restore_value: yes
initial_value: 'false'
- id: qr_presented
type: bool
restore_value: no
initial_value: 'false'
web_server:
port: 80
version: 2
local: true
interval:
- interval: 10s
then:
- if:
condition:
for:
time: 65s # rely on 60 seconds default ap_timeout value and add 5 seconds to start Fallback AP
condition:
not:
- wifi.connected:
then:
if:
condition:
- lambda: return !id(qr_presented);
then:
- logger.log: WiFi is not connected for 1 minute, show WiFi configuration QR code
- lambda: |-
id(disp).goto_page("config_wifi");
id(qr_presented) = true;
switch:
- platform: gpio
pin: GPIO15
id: heater
restore_mode: ALWAYS_OFF
internal: true
- platform: restart
name: ${friendly_devicename} Restart
id: reboot
- platform: factory_reset
name: ${friendly_devicename} Factory Reset
id: reset
binary_sensor:
- platform: status
name: ${friendly_devicename} Status
entity_category: diagnostic
- platform: nextion
page_id: 0x01
component_id: 0x0D
internal: true
id: n_temp_up
on_press:
- lambda: |-
auto traits = id(lytko_therm).get_traits();
float step = traits.get_visual_target_temperature_step();
float max_temp = traits.get_visual_max_temperature();
if (id(lytko_therm).target_temperature_high + step <= max_temp) {
auto call = id(lytko_therm).make_call();
call.set_target_temperature_high(id(lytko_therm).target_temperature_high + step);
call.set_target_temperature_low(id(lytko_therm).target_temperature_low + step);
call.perform();
}
id(n_temp_up).publish_state(false); /* Reset the state back to off */
- platform: nextion
page_id: 0x01
component_id: 0x0E
internal: true
id: n_temp_down
on_press:
- lambda: |-
auto traits = id(lytko_therm).get_traits();
float step = traits.get_visual_target_temperature_step();
float min_temp = traits.get_visual_min_temperature();
if (id(lytko_therm).target_temperature_low - step >= min_temp) {
auto call = id(lytko_therm).make_call();
call.set_target_temperature_high(id(lytko_therm).target_temperature_high - step);
call.set_target_temperature_low(id(lytko_therm).target_temperature_low - step);
call.perform();
}
id(n_temp_down).publish_state(false); /* Reset the state back to off */
- platform: nextion
page_id: 0x01
component_id: 0x11
internal: true
id: n_heat_on
on_press:
- lambda: |-
auto call = id(lytko_therm).make_call();
call.set_mode("HEAT");
call.perform();
id(n_heat_on).publish_state(false); /* Reset the state back to off */
- platform: nextion
page_id: 0x01
component_id: 0x14
internal: true
id: n_heat_off
on_press:
- lambda: |-
auto call = id(lytko_therm).make_call();
call.set_mode("OFF");
call.perform();
id(n_heat_off).publish_state(false); /* Reset the state back to off */
- platform: nextion
page_id: 0x0A
component_id: 0x01
internal: true
id: n_reset
on_press:
- switch.turn_on: reset
- platform: nextion
page_id: 0x06
component_id: 0x03
internal: true
id: n_lock_on
on_press:
- lambda: |-
id(child_lock) = true;
id(n_lock_on).publish_state(false); /* Reset the state back to off */
- platform: nextion
page_id: 0x06
component_id: 0x04
internal: true
id: n_lock_off
on_press:
- lambda: |-
id(child_lock) = false;
id(n_lock_off).publish_state(false); /* Reset the state back to off */
text_sensor:
- platform: version
hide_timestamp: true
internal: true
id: esph_version
- platform: template
name: ${friendly_devicename} Uptime
id: uptime_human
icon: mdi:clock-start
entity_category: diagnostic
update_interval: never
on_value:
lambda: |-
id(disp).set_component_text("uptime", id(uptime_human).state.c_str());
sensor:
# Report basic device information like it's reboot counter, Wi-Fi signal strength and uptime
- platform: uptime
internal: true
id: uptime_sensor
update_interval: 60s
on_raw_value:
- text_sensor.template.publish:
id: uptime_human
state: !lambda |-
int seconds = round(id(uptime_sensor).raw_state);
int days = seconds / (24 * 3600);
seconds = seconds % (24 * 3600);
int hours = seconds / 3600;
seconds = seconds % 3600;
int minutes = seconds / 60;
seconds = seconds % 60;
return (
(days ? String(days) + "d " : "") +
(hours ? String(hours) + "h " : "") +
(minutes ? String(minutes) + "m" : "0m")
).c_str();
- platform: template
name: ${friendly_devicename} Boot Counter
lambda: |-
static int last_boot_counter = 0;
if (last_boot_counter != id(boot_counter)) {
last_boot_counter = id(boot_counter);
return id(boot_counter);
} else {
return {};
}
update_interval: 60s
state_class: total_increasing
accuracy_decimals: 0
entity_category: diagnostic
- platform: template
id: wifi_level
entity_category: diagnostic
internal: true
update_interval: never
filters:
- delta: 1.0
on_value:
lambda: |-
id(disp).set_component_value("signal_fill", x);
- platform: wifi_signal
name: ${friendly_devicename} WiFi Signal
update_interval: 10s
id: rssi_level
entity_category: diagnostic
filters:
- delta: 1.0
on_value:
lambda: |-
int32_t level;
if (-1.0f > x && x >= -50.0f) { level = 4; id(rssi_level).set_icon("mdi:wifi-strength-4");}
else if (-50.0f > x && x >= -61.0f) { level = 3; id(rssi_level).set_icon("mdi:wifi-strength-3");}
else if (-61.0f > x && x >= -72.0f) { level = 2; id(rssi_level).set_icon("mdi:wifi-strength-2");}
else if (-72.0f > x && x >= -83.0f) { level = 1; id(rssi_level).set_icon("mdi:wifi-strength-1");}
else if (-83.0f > x && x >= -94.0f) { level = 0; id(rssi_level).set_icon("mdi:wifi-strength-outline");}
else { level =-1; id(rssi_level).set_icon("mdi:wifi-strength-off-outline");}
id(wifi_level).publish_state(level);
- platform: debug
free:
id: free_heap
internal: true
# on_value:
# then:
# lambda: |-
# id(disp).set_component_text_printf("memory", "%uB / %u%% / %uB", (uint32_t)x, (uint32_t)id(heap_frag).state, (uint32_t)id(max_heap_block).state);
fragmentation:
id: heap_frag
internal: true
# on_value:
# then:
# lambda: |-
# id(disp).set_component_text_printf("memory", "%uB / %u%% / %uB", (uint32_t)id(free_heap).state, (uint32_t)x, (uint32_t)id(max_heap_block).state);
block:
id: max_heap_block
internal: true
# on_value:
# then:
# lambda: |-
# id(disp).set_component_text_printf("memory", "%uB / %u%% / %uB", (uint32_t)id(free_heap).state, (uint32_t)id(heap_frag).state, (uint32_t)x);
- platform: ntc
sensor: resistance_sensor
calibration:
b_constant: ${ntc_beta_constant}
reference_temperature: ${ntc_ref_temperature}°C
reference_resistance: ${ntc_ref_resistance}Ohm
name: ${friendly_devicename} Temperature
accuracy_decimals: 1
state_class: measurement
device_class: temperature
unit_of_measurement: "°C"
id: int_ntc
filters:
- delta: 0.1 # Prevent repetitive actions using the same value
- offset: ${temperature_shift}
- platform: resistance
id: resistance_sensor
sensor: voltage_sensor
configuration: UPSTREAM
resistor: ${ntc_measurement_resistor}
internal: true
- platform: adc
id: voltage_sensor
pin: A0
update_interval: 1s
internal: true
filters:
- lambda: |-
/* 10 bit ADC, readouts below 10 (1%) are considered noise, NTC is not connected */
return (x < 10.0f/1024 ? NAN : x );
- exponential_moving_average:
alpha: 0.1
send_every: 10
send_first_at: 1
- platform: template
name: ${friendly_devicename} NTC Reference Resistance
accuracy_decimals: 0
unit_of_measurement: "Ω"
update_interval: 60s
icon: "mdi:flash"
lambda: |-
return ${ntc_ref_resistance};
filters:
- delta: 0.1 # Prevent repetitive actions using the same value
- platform: template
name: ${friendly_devicename} Heating Resistance
accuracy_decimals: 1
unit_of_measurement: "Ω"
update_interval: 60s
icon: "mdi:heat-wave"
lambda: |-
return ${floor_resistance};
filters:
- delta: 0.1 # Prevent repetitive actions using the same value
- platform: template
update_interval: 1s
internal: true
id: mains_voltage
state_class: measurement
device_class: voltage
icon: "mdi:flash"
lambda: |-
return ${floor_mains_voltage};
filters:
- delta: 0.01 # Prevent repetitive actions using the same value
# If Smart Meter is available, uncomment the sensor below and comment out template sensor above
# Get current mains voltage from a smart meter
# - platform: homeassistant
# id: mains_voltage
# entity_id: sensor.pzem_004t_v3_voltage
# internal: true
# filters:
# - filter_out: nan
# - delta: 0.01 # Prevent repetitive actions using the same value
- platform: template
update_interval: 1s
internal: true
name: ${friendly_devicename} Power
id: floor_power
state_class: measurement
device_class: power
accuracy_decimals: 0
unit_of_measurement: "W"
icon: "mdi:flash"
lambda: |-
return id(heater).state * id(mains_voltage).state * id(mains_voltage).state / (float)${floor_resistance};
- platform: integration
name: ${friendly_devicename} Energy
sensor: floor_power
time_unit: h
integration_method: left
restore: true
accuracy_decimals: 3
unit_of_measurement: "kWh"
icon: "mdi:flash"
device_class: energy
state_class: total_increasing
filters:
- multiply: 0.001 # Wh to kWh
output:
- platform: esp8266_pwm
pin:
number: GPIO2
inverted: true
frequency: 1000 Hz
id: pwm_output
light:
- platform: monochromatic
output: pwm_output
restore_mode: ALWAYS_OFF
id: blue_led
internal: true
climate:
- platform: bang_bang
name: ${friendly_devicename} Heating Controller
sensor: ${temperature_sensor}
default_target_temperature_low: ${target_temperture_low} °C
default_target_temperature_high: ${target_temperture_high} °C
id: lytko_therm
visual:
min_temperature: ${min_temperature} °C
max_temperature: ${max_temperature} °C
temperature_step: ${temperature_step} °C
heat_action:
- switch.turn_on: heater
- light.turn_on: blue_led
idle_action:
- switch.turn_off: heater
- light.turn_off: blue_led
on_state:
- lambda: |-
bool is_on = (id(lytko_therm).mode == CLIMATE_MODE_HEAT);
bool is_heating = (id(lytko_therm).action == CLIMATE_ACTION_HEATING);
id(disp).set_component_value("arrow_temp", is_heating);
id(disp).set_component_value("H_active", is_on);
id(disp).set_component_text_printf("degree_big", "%.1f", (id(lytko_therm).target_temperature_high + id(lytko_therm).target_temperature_low) / 2.0f);
if (!std::isnan(id(lytko_therm).current_temperature)) {
id(disp).set_component_text_printf("degree", "%.1f", id(lytko_therm).current_temperature);
} else {
id(disp).set_component_text("degree", "ERR");
}
number:
- platform: template
name: ${friendly_devicename} Locked Screen Brightness
id: locked_brightness
min_value: 0
max_value: 100
step: 1
icon: mdi:brightness-percent
optimistic: true
restore_value: true
entity_category: config
unit_of_measurement: '%'
mode: slider