-
Notifications
You must be signed in to change notification settings - Fork 0
/
dhwmonitor.yaml
528 lines (490 loc) · 14.3 KB
/
dhwmonitor.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
#<<: !include secrets.yaml
esphome:
name: dhwmonitor
platform: ESP32
board: esp32doit-devkit-v1
includes:
- dhwmonitor.h
- text_wrap.h
- text_wrap.cpp
on_boot:
priority: 30
then:
- light.turn_on:
id: back_light
brightness: 60%
#bluetooth_proxy:
wifi:
ssid: !secret wifi_ssid
password: !secret wifi_password
domain: .local
# Enable fallback hotspot (captive portal) in case wifi connection fails
ap:
ssid: "DHWMonitor1 Fallback Hotspot"
password: "mYJr5Q9cloL4"
# Enable logging
logger:
# Enable Home Assistant API
api:
services:
- service: play_rtttl
variables:
song_str: string
then:
- rtttl.play:
rtttl: !lambda "return song_str;"
ota:
platform: esphome
time:
- platform: homeassistant
id: esptime
timezone: Europe/London
font:
- file: "segoeui.ttf"
id: font_sml
size: 13
#glyphs: "!%()+,-_.:°0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ abcdefghijklmnopqrstuvwxyz▂▄▆█"
- file: "segoeui.ttf"
id: font_med
size: 30
- file: "segoeui.ttf"
id: font_max
size: 72
- file: "materialdesignicons-webfont.ttf"
id: font_icon
size: 30
glyphs: [
"\U000F0FC6", # mdi-lock-open
"\U000F0319", # mdi-lan-disconnect
]
animation:
- file: "flame10.gif"
id: flame_gif
resize: 32x32
type: RGB24
- file: "sun3.gif"
id: sun_gif
resize: 32x32
type: RGB24
# interval:
# - interval: 0.2s
# then:
# lambda: |-
# id(flame_gif).next_frame();
color:
- id: darkbrown1
red: 76%
green: 61%
blue: 42%
- id: darkblue1
red: 2%
green: 14%
blue: 24%
- id: lightblue1
red: 35%
green: 42%
blue: 52%
- id: lightbrown1
red: 78%
green: 71%
blue: 58%
- id: my_red
red: 100%
green: 3%
blue: 5%
- id: black1
red: 0%
green: 0%
blue: 0%
# spi:
# clk_pin: GPIO18
# mosi_pin: GPIO19
sensor:
- platform: wifi_signal
name: Wifi SSI
id: wifi_ssi
update_interval: 5s
internal: true
- platform: homeassistant
name: "Tank Sensor 1 HA"
entity_id: sensor.temperature1
id: temperature1
internal: true
- platform: homeassistant
name: "Tank Sensor 2 HA"
entity_id: sensor.temperature2
id: temperature2
internal: true
- platform: homeassistant
name: "Tank Sensor 3 HA"
entity_id: sensor.temperature3
id: temperature3
internal: true
- platform: homeassistant
name: "Tank Sensor 4 HA"
entity_id: sensor.temperature4
id: temperature4
internal: true
- platform: homeassistant
name: "Tank Sensor 5 HA"
entity_id: sensor.temperature5
id: temperature5
internal: true
- platform: homeassistant
name: "Tank Sensor 6 HA"
entity_id: sensor.temperature6
id: temperature6
internal: true
- platform: homeassistant
name: "Tank Sensor 7 HA"
entity_id: sensor.temperature7
id: temperature7
internal: true
- platform: homeassistant
name: "HW Remaining L"
entity_id: sensor.hot_water_remaining_l
id: hwremaining_l
internal: true
- platform: homeassistant
id: current_temperature
entity_id: climate.heating
attribute: current_temperature
internal: true
- platform: homeassistant
id: target_temperature
entity_id: climate.heating
attribute: temperature
internal: true
- platform: homeassistant
entity_id: input_number.dhw_boost_target
id: dhw_boost_tgt_ha
internal: false
interval:
- interval: 1sec
then:
if:
condition:
for:
time: 3sec
condition:
lambda: |-
return (int(id(dhw_boost_tgt_ha).state*10) != id(dhw_boost_tgt_local));
then:
- lambda: "id(dhw_boost_tgt_local) = 0;"
text_sensor:
- platform: wifi_info
ssid:
name: Connected SSID
id: wifi_ssid
internal: true
- platform: homeassistant
id: ch_mode
entity_id: climate.your_thermostat
attribute: preset_mode
internal: true
- platform: homeassistant
id: dhw_mode
entity_id: water_heater.hot_water
attribute: operation_mode
internal: true
- platform: homeassistant
id: votd_text
entity_id: sensor.votd_text
- platform: homeassistant
id: votd_ref
entity_id: sensor.votd_ref
output:
- platform: ledc
pin: GPIO21
id: beeper
- platform: ledc
pin: 15
id: gpio_32_backlight_pwm
inverted: true
# this works but the sound is really not that amazing!
rtttl:
output: beeper
on_finished_playback:
- logger.log: "Song ended!"
script:
- id: beep
then:
#beeper temporarily disabled
- output.turn_off: beeper
- output.ledc.set_frequency:
id: beeper
frequency: "2000Hz"
- output.set_level:
id: beeper
level: "50%"
- delay: 0.01s
- output.turn_off: beeper
spi:
clk_pin: 18
mosi_pin: 23
miso_pin: 19
touchscreen:
platform: xpt2046
id: tscreen
cs_pin: 14
interrupt_pin: 27
update_interval: 50ms
#report_interval: 1s
calibration:
x_min: 3839
x_max: 269
y_min: 257
y_max: 3855
transform:
mirror_x: false
mirror_y: true
swap_xy: true
on_touch:
- lambda: |-
ESP_LOGI("cal", "x=%d, y=%d, x_raw=%d, y_raw=%d",
touch.x,
touch.y,
touch.x_raw,
touch.y_raw
);
binary_sensor:
# - platform: touchscreen
# id: ch_boost_key0
# x_min: 20 #0+20
# x_max: 180 #320/2-20
# y_min: 20 #0+20
# y_max: 220 #240-20
# on_press:
# then:
# - script.execute: beep
# - if:
# condition:
# lambda: 'return id(ch_boost_local).state == "none";'
# then:
# - select.set:
# id: ch_boost_local
# option: "boost"
# else:
# - select.set:
# id: ch_boost_local
# option: "none"
- platform: touchscreen
id: dhw_boost_key0
x_min: 180 #320/2+20
x_max: 300 #320-20
y_min: 20 #0+20
y_max: 220 #240-20
on_press:
then:
- script.execute: beep
- lambda: 'ESP_LOGI("main", "dhwboost pressed");'
# - if:
# condition:
# lambda: "return (id(dhw_boost_tgt_local) + 5 < 20);"
# then:
# #- lambda: 'ESP_LOGI("main", "condition true");'
# - lambda: "id(dhw_boost_tgt_local) += 5;"
# #- lambda: 'ESP_LOGI("main", "%.1f", id(dhw_boost_tgt_local));'
# else:
# #- lambda: 'ESP_LOGI("main", "condition false");'
# - lambda: "id(dhw_boost_tgt_local) = 0;"
# #- lambda: 'ESP_LOGI("main", "setting dhwboost");'
# - homeassistant.service:
# service: script.intelligent_boost_hot_water_2
# data_template:
# new_boost_target: "{{ my_var }}"
# variables:
# my_var: |-
# return ((float)id(dhw_boost_tgt_local)/10);
# - if:
# condition:
# lambda: 'return id(dhw_boost_local).state == "none";'
# then:
# - select.set:
# id: dhw_boost_local
# option: "boost"
# - homeassistant.service: # intelligent boost dhw
# service: script.1632605690960
# else:
# - select.set:
# id: dhw_boost_local
# option: "none"
# - homeassistant.service: # intelligent boost dhw stop
# service: script.turn_off
# data:
# entity_id: script.1632605690960
# - homeassistant.service: # also stop the boost.
# service: hive.boost_hot_water
# data:
# on_off: "off"
# entity_id: water_heater.hot_water
# time_period: "00:01:00"
# on_state:
# # - lambda: 'ESP_LOGI("main", "key0: %s", (x ? "touch" : "release"));'
- platform: homeassistant
entity_id: binary_sensor.aqaradoor3
id: conservatory_door_lock
internal: true
- platform: homeassistant
entity_id: binary_sensor.aqaradoor5
id: garage_door_lock
internal: true
- platform: homeassistant
entity_id: binary_sensor.aqaradoor4
id: kitchen_door_lock
internal: true
- platform: homeassistant
id: solar_heater
entity_id: switch.immersion_heater
internal: true
- platform: homeassistant
id: ip_ping
entity_id: binary_sensor.internet_ip_ping
internal: true
globals:
- id: dhw_boost_tgt_local
type: int
restore_value: no
initial_value: "0"
select:
# - platform: template
# id: dhw_boost_local
# optimistic: true
# options:
# - "none"
# - "boost"
- platform: template
id: ch_boost_local
optimistic: true
options:
- "none"
- "boost"
#internal: true
# font:
# - file: "arial.ttf"
# id: my_font
# size: 20
# Define a monochromatic, dimmable light for the backlight
light:
- platform: monochromatic
output: gpio_32_backlight_pwm
name: "ILI9341 Display Backlight"
id: back_light
restore_mode: ALWAYS_ON
display:
- platform: ili9xxx
model: TFT 2.4
cs_pin: 5
dc_pin: 4
#led_pin: 15
reset_pin: 22
rotation: 90
id: tft_ha
color_palette: IMAGE_ADAPTIVE
color_palette_images:
- "display_design.png"
update_interval: 1s
invert_colors: false
lambda: |-
id(flame_gif).next_frame();
id(sun_gif).next_frame();
//it.fill(Color::BLACK);
signed int ssi = (signed int)id(wifi_ssi).state;
it.strftime(1, 2, id(font_sml), lightblue1, TextAlign::TOP_LEFT, "%H:%M", id(esptime).now());
it.printf(it.get_width()-30-5, 2, id(font_sml), lightblue1, TextAlign::TOP_RIGHT, "%s", id(wifi_ssid).state.c_str());
it.printf(it.get_width()-30, 2, id(font_sml), lightblue1, TextAlign::TOP_LEFT, "%c%c%c%c", ssi > -80 ? '-' : 'x', ssi>-75 ? '-' : ' ', ssi>-70 ? '-' : ' ', ssi>-67 ? '-' : ' ');
// draw temperature gradient filled sausage shaped tank.
int x = 320-100;
int y = 22;
int width = 100;
int height =180;
float temps[] = {
id(temperature1).state,
id(temperature2).state,
id(temperature3).state,
id(temperature4).state,
id(temperature5).state,
id(temperature6).state,
id(temperature7).state
};
int count=7;
for (int i=0; i<count; i++)
{
it.printf(320-102, 22+(height*i/(count)), id(font_sml), lightblue1, TextAlign::TOP_RIGHT, "%.1f", temps[i]);
}
assert(count > 1);
float r = (float)width/2;
float w, x1, x2, l;
// Draw out a tank a line at a time.
for (int i=0; i<height; i++)
{
// calculate the start and finish x coordinates of each line.
if (i<r) // top semicircle
{
w = sqrt(2*r*i - i*i);
//printf("x=%3.1f\n", r-x);
}
else if (i<(height-r)) //middle straight section
{
w = r;
}
else // bottom semicircle
{
l = (height - i);
w = sqrt(2*r*l - l*l);
}
x1 = int(r - w);
x2 = int(r + w);
int i1 = i * (count-1)/ height;
int i2 = i1+1;
// Calculate interpolated temperature at this height.
float temp1 = temps[i1];
float temp2 = temps[i2];
int h1 = i1 * (float)height/(count-1);
int h2 = i2 * (float)height/(count-1);
float temp = temp1 + (temp2-temp1) * (float)(i-h1)/(float)(h2-h1);
// convert temperature to a color
Color c = temp_to_color(temp);
it.line(x + x1, y + i, x + x2, y + i, c);
}
// CH info
it.printf(it.get_width()/4, 100, id(font_max), COLOR_ON, TextAlign::BOTTOM_CENTER, "%.1f", id(current_temperature).state);
it.printf(it.get_width()/4, 100, id(font_med), COLOR_ON, TextAlign::TOP_CENTER, "%.1f°C", id(target_temperature).state);
if (id(ch_boost_local).state == "on" || id(ch_boost_local).state == "boost") {
//Color (100, 85, 0) yellow
it.print(it.get_width()/4, 140, id(font_med), COLOR_ON, TextAlign::TOP_CENTER, "BOOST");
}
//it.printf(it.get_width()/4, 160, id(font_med), COLOR_ON, TextAlign::TOP_CENTER, "s=%s", id(ch_mode).state.c_str());
if (id(ch_mode).state == "boost") {
it.image(it.get_width()/4-15, 203, id(flame_gif), COLOR_ON, COLOR_OFF);
}
// DHW info
it.printf(320-width/2, 80, id(font_med), COLOR_ON, TextAlign::BOTTOM_CENTER, "%.0fL", id(hwremaining_l).state);
// WIP !!!!!! NEED TO CHANGE 120 to use HA variable, not local literal.
it.printf(320-width/2, 75, id(font_med), COLOR_ON, TextAlign::TOP_CENTER, "(%.1f)", id(hwremaining_l).state/120);
int tgt_local = id(dhw_boost_tgt_local);
int tgt_ha = (int)(id(dhw_boost_tgt_ha).state*10);
if (id(dhw_boost_tgt_local) != 0) {
Color c = (tgt_local != tgt_ha) ? (Color::BLACK) : (Color::WHITE);
it.print(320-width/2, 150, id(font_med), c, TextAlign::BOTTOM_CENTER, "iBoost");
it.printf(320-width/2, 145, id(font_med), c, TextAlign::TOP_CENTER, "%.1f", ((float)tgt_local)/10);
it.image(it.get_width() - 50-16, 203, id(flame_gif));
}
if (id(solar_heater).state) {
it.image(it.get_width() - 50-16, 203, id(sun_gif));
}
if (!id(ip_ping).state) {
it.print(it.get_width()/2, 200, id(font_icon), my_red, TextAlign::BOTTOM_CENTER, "\U000F0319");
it.print(it.get_width()/2, 201, id(font_sml), my_red, TextAlign::TOP_CENTER, "Internet offline");
}
else if (id(garage_door_lock).state || id(kitchen_door_lock).state || id(garage_door_lock).state) {
it.print(it.get_width()/2, 200, id(font_icon), my_red, TextAlign::BOTTOM_CENTER, "\U000F0FC6");
it.printf(it.get_width()/2, 201, id(font_sml), my_red, TextAlign::TOP_CENTER, "%s%s%s",
id(conservatory_door_lock).state ? "Conservatory " : "",
id(kitchen_door_lock).state ? "Kitchen " : "",
id(garage_door_lock).state ? "Garage " : "");
}
x=0; y=138; w=188; int h=102;
auto green = Color(0, 255, 0);
//it.rectangle(x, y, w, h, green);
wrap_text_box2(&it, x, y, w, h, id(font_sml), TextAlign::TOP_LEFT, 1.0, "%s -- %s", id(votd_text).state.c_str(), id(votd_ref).state.c_str());