-
Notifications
You must be signed in to change notification settings - Fork 1
/
LG_thermaV_logic.yaml
636 lines (565 loc) · 22.6 KB
/
LG_thermaV_logic.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
esphome:
name: esp-wp-control
esp32:
board: mhetesp32minikit
framework:
type: arduino
# Enable Home Assistant API
api:
encryption:
key: "[xxxxx]"
ota:
password: "[xxxxx]"
wifi:
ssid: [xxxxx]
password: [xxxxx]
manual_ip:
static_ip: 192.168.108.101 // change accordingly
gateway: 192.168.108.1 // change accordingly
subnet: 255.255.255.0
# Enable fallback hotspot (captive portal) in case wifi connection fails
ap:
ssid: "[name it]"
password: "[xxxxx]"
button:
- platform: restart
id: restart_button
name: "Herstart ESP module"
# Enable logging. Disable modbus controller debug messages
logger:
logs:
modbus_controller.sensor: error
modbus_controller.output: error
esp32.preferences: DEBUG
sensor: error
globals:
- id: stooklijn_target
type: float
restore_value: yes
initial_value: '28'
- id: force_update_stooklijn
type: bool
restore_value: no
initial_value: 'true'
number:
- platform: template
id: stooklijn_min_oat
name: "Stooklijn Minimum Buitentemperatuur"
min_value: -15
max_value: 4
step: 1
restore_value: yes
initial_value: -5
unit_of_measurement: "°C"
optimistic: true
icon: mdi:thermometer-minus
set_action:
then:
- lambda: |-
id(force_update_stooklijn) = true;
- platform: template
id: stooklijn_max_oat
name: "Stooklijn Maximum Buitentemperatuur"
min_value: 5
max_value: 20
step: 1
restore_value: yes
initial_value: 13
unit_of_measurement: "°C"
optimistic: true
icon: mdi:thermometer-plus
set_action:
then:
- lambda: |-
id(force_update_stooklijn) = true;
- platform: template
id: stooklijn_max_wtemp
name: "Stooklijn Maximum Watertemperatuur"
min_value: 30
max_value: 35
step: 1
restore_value: yes
initial_value: 30
unit_of_measurement: "°C"
optimistic: true
icon: mdi:water-thermometer-outline
set_action:
then:
- lambda: |-
id(force_update_stooklijn) = true;
- platform: template
id: stooklijn_min_wtemp
name: "Stooklijn Minimum Watertemperatuur"
min_value: 25
max_value: 30
step: 1
restore_value: yes
initial_value: 28
unit_of_measurement: "°C"
optimistic: true
icon: mdi:water-thermometer
set_action:
then:
- lambda: |-
id(force_update_stooklijn) = true;
# offset op stooklijn. Handig voor nachtverlaging of buiten de deur? Kijk uit met hysterese settings van de controller!
- platform: template
name: "Stooklijn offset"
id: wp_stooklijn_offset
min_value: -4
max_value: 4
initial_value: 0
step: 1
restore_value: yes
unit_of_measurement: "°C"
optimistic: true
set_action:
then:
- lambda: |-
id(force_update_stooklijn) = true;
# offset op de stooklijn voor simultaan gebruik
- platform: template
name: "Stooklijn offset Overshoot"
id: overshoot_stooklijn_offset
internal: true # verberg voor HA, wordt alleen gebruikt voor overshoot logic
min_value: -4
max_value: 4
initial_value: 0
step: 1
restore_value: yes
unit_of_measurement: "°C"
optimistic: true
set_action:
then:
- lambda: |-
id(force_update_stooklijn) = true;
# mee aan het testen
- platform: template
id: oat_silent_always_off
name: "Buitentemperatuur silent uit"
min_value: 0
max_value: 10
step: 1
restore_value: yes
initial_value: 2
unit_of_measurement: "°C"
optimistic: true
icon: mdi:volume-plus
- platform: template
id: oat_silent_always_on
name: "Buitentemperatuur silent aan"
min_value: 0
max_value: 10
step: 1
restore_value: yes
initial_value: 6
unit_of_measurement: "°C"
optimistic: true
icon: mdi:volume-off
switch:
- platform: output
name: "Silent Mode"
id: silent_mode_switch
output: 'modbus_set_silent_mode'
icon: mdi:volume-off
- platform: template
id: stooklijn_on_off
name: "Stooklijn On/Off"
optimistic: true
icon: mdi:chart-bell-curve-cumulative
- platform: template
id: overshootcontrol_on_off
name: "Overshoot Control On/Off"
optimistic: true
icon: mdi:rocket
uart:
id: mod_bus
tx_pin: GPIO23
rx_pin: GPIO19
baud_rate: 9600
stop_bits: 1
parity: NONE
modbus:
flow_control_pin: GPIO18
send_wait_time: 1000ms
id: modbus_lg
modbus_controller:
- id: lg
## the Modbus device addr
address: 0x1
modbus_id: modbus_lg
setup_priority: -10
update_interval: 10s
output:
- platform: modbus_controller
modbus_controller_id: lg
id: water_temp_target_output
register_type: holding
address: 2
value_type: U_WORD
multiply: 1000
- platform: modbus_controller
modbus_controller_id: lg
id: modbus_set_silent_mode
register_type: coil
address: 2
binary_sensor:
- platform: modbus_controller
modbus_controller_id: lg
name: "Pump Running"
id: pump_running
register_type: discrete_input
skip_updates: 3
address: 1
- platform: modbus_controller
modbus_controller_id: lg
name: "Compressor Running"
id: compressor_running
register_type: discrete_input
skip_updates: 3
address: 3
- platform: modbus_controller
modbus_controller_id: lg
name: "Defrosting"
id: defrosting
register_type: discrete_input
skip_updates: 3
address: 4
- platform: modbus_controller
modbus_controller_id: lg
name: "Silent Mode"
id: silent_mode
register_type: coil
skip_updates: 3
address: 2
on_state:
then:
- lambda: |-
if(id(silent_mode).state != id(silent_mode_switch).state) id(silent_mode_switch).publish_state(id(silent_mode).state);
sensor:
- platform: modbus_controller
modbus_controller_id: lg
name: "INV discharge temperature"
id: INV
register_type: read
address: 19
unit_of_measurement: "°C"
accuracy_decimals: 0
filters:
- multiply: 0.1
- platform: modbus_controller
modbus_controller_id: lg
name: "Bedrijfsmodus"
id: bedrijfsmodus
register_type: read
address: 1
value_type: U_WORD
- platform: modbus_controller
modbus_controller_id: lg
name: "Water retour"
id: water_temp_retour
register_type: read
address: 2
unit_of_measurement: "°C"
value_type: U_WORD
accuracy_decimals: 1
filters:
- multiply: 0.1
- platform: modbus_controller
modbus_controller_id: lg
name: "Compressor"
id: compressor_hz
register_type: read
address: 24
unit_of_measurement: "Hz"
value_type: U_WORD
accuracy_decimals: 0
- platform: modbus_controller
modbus_controller_id: lg
name: "LowPress"
id: LowPress
register_type: read
address: 23
unit_of_measurement: "mBar"
value_type: U_WORD
accuracy_decimals: 0
- platform: modbus_controller
modbus_controller_id: lg
name: "HighPress"
id: HighPress
register_type: read
address: 22
unit_of_measurement: "mBar"
value_type: U_WORD
accuracy_decimals: 0
- platform: modbus_controller
modbus_controller_id: lg
name: "Pipe in Temp"
id: Pipein
register_type: read
address: 16
unit_of_measurement: "°C"
value_type: U_WORD
accuracy_decimals: 0
filters:
- multiply: 0.1
- platform: modbus_controller
modbus_controller_id: lg
name: "Pipe out Temp"
id: pipeout
register_type: read
address: 17
unit_of_measurement: "°C"
value_type: U_WORD
accuracy_decimals: 0
filters:
- multiply: 0.1
- platform: modbus_controller
modbus_controller_id: lg
name: "flow rate"
id: flow
register_type: read
address: 8
unit_of_measurement: "l/min"
value_type: U_WORD
accuracy_decimals: 1
filters:
- multiply: 0.1
- platform: modbus_controller
modbus_controller_id: lg
name: "Water aanvoer"
id: water_temp_aanvoer
register_type: read
address: 3
unit_of_measurement: "°C"
value_type: U_WORD
accuracy_decimals: 1
filters:
- multiply: 0.1
on_value:
then:
- lambda: |-
static unsigned long last_publish_time = 0;
static bool compressorHzLessThanEqualOneInLastMinute = false;
static bool resetCompressorHzFlag = false;
static bool OvershootLogic = false;
static int state = 0;
if(id(bedrijfsmodus).state != 2 ) return;
if(isnan(id(buiten_temp).state)) return;
if(!id(stooklijn_on_off).state) return;
if (millis() - last_publish_time < 10000) {
return;
}
last_publish_time = millis();
static float prev_oat = 0; // hold previous script run ota value to check if it changed since last run
static float prev_tr = id(water_temp_retour).state;
float temp_new_target = id(watertemp_target).state; //nieuw Ta target
static bool target_reached = false; //system logic (to switch off after target is reached)
static unsigned long last_offset_publish_time = 0;
float oat = round(id(buiten_temp).state);
const float Z = ((float)id(stooklijn_min_wtemp).state-(float)id(stooklijn_max_wtemp).state) / ((float)id(stooklijn_max_oat).state - (float)id(stooklijn_min_oat).state);
ESP_LOGD("stooklijn", "verwarmen volgens stooklijn, met buitentemp: %.1f, Z: %.1f",oat, Z);
// Controleer de compressor status
auto checkCompressorState = [&]() {
unsigned long currentTime = millis();
for (unsigned long time = currentTime - 100 * 1000; time <= currentTime && (!compressorHzLessThanEqualOneInLastMinute || resetCompressorHzFlag); time += 1000) {
if (id(compressor_hz).raw_state <= 1.00) {
ESP_LOGD("debug", "Controlleer status compressor");
compressorHzLessThanEqualOneInLastMinute = true;
resetCompressorHzFlag = false; // Reset the flag here
ESP_LOGD("debug", "Compressor Hz is 0.00, (her)start: %s", compressorHzLessThanEqualOneInLastMinute ? "true" : "false");
id(overshoot_stooklijn_offset).publish_state(-0);
ESP_LOGD("debug", "Current state: %d", state);
break;
}
}
if (compressorHzLessThanEqualOneInLastMinute && id(compressor_hz).raw_state > 1.00) {
ESP_LOGD("debug", "Compressor Hz is greater than 1.00 again");
resetCompressorHzFlag = true; // Set the flag to indicate that the condition has been met
}
};
checkCompressorState(); // Call the compressor state check
// Update de stooklijn bij verwarming
bool inschakelUpdate = false;
if (id(bedrijfsmodus).state == 2 && !inschakelUpdate){
id(stooklijn_target) = (int)round(Z * (oat - id(stooklijn_min_oat).state) + id(stooklijn_max_wtemp).state) +
(id(wp_stooklijn_offset).state) + (id(overshoot_stooklijn_offset).state);
ESP_LOGD("Stooklijn", "Stooklijn bijgewerkt");
inschakelUpdate = true;
} else if (id(bedrijfsmodus).state != 2) {
// Reset flag
inschakelUpdate = false;
}
// --------warmtepomp is actief ----------------------
if (id(compressor_running).state) {
ESP_LOGD("debug", "Compressor is running - checking overshoot control");
ESP_LOGD("debug", "overshootcontrol_on_off.state: %s", id(overshootcontrol_on_off).state ? "true" : "false");
ESP_LOGD("debug", "OvershootLogic: %s", OvershootLogic ? "true" : "false");
ESP_LOGD("debug", "Huidige state: %d", state);
// zet bij defrost stille modus uit
if (id(defrosting).state) {
id(silent_mode_switch).turn_off();
ESP_LOGD("debug", "Silent Mode switch set to OFF");
}
if ((id(overshootcontrol_on_off).state && compressorHzLessThanEqualOneInLastMinute) || (id(overshootcontrol_on_off).state && OvershootLogic)) {
ESP_LOGD("debug", "Current state: %d", state);
float temp_target_incremented = 0.0;
if (state == 0) {
ESP_LOGD("debug", "Start de OvershootLogic");
id(overshoot_stooklijn_offset).publish_state(-4); // stooklijn verlaging in aantal graden Ta
ESP_LOGD("debug", "overshoot stooklijn -4");
OvershootLogic = true;
ESP_LOGD("debug", "OvershootLogic: %s", OvershootLogic ? "true" : "false");
last_offset_publish_time = millis();
id(stooklijn_target) = (int)round(Z * (oat - id(stooklijn_min_oat).state) + id(stooklijn_max_wtemp).state) +
(id(wp_stooklijn_offset).state) + (id(overshoot_stooklijn_offset).state);
ESP_LOGD("stooklijn", "gecorrigeerd target stap 1 overshoot: %.1f", id(stooklijn_target));
id(watertemp_target).publish_state(id(stooklijn_target));
state++;
} else if (state == 1) {
// reset compressor state
compressorHzLessThanEqualOneInLastMinute = false;
ESP_LOGD("debug", "Compressor Hz is 0.00: %s", compressorHzLessThanEqualOneInLastMinute ? "true" : "false");
ESP_LOGD("debug", "OvershootLogic: %s", OvershootLogic ? "true" : "false");
ESP_LOGD("debug", "Timer in seconden: %.0f", (millis() - last_offset_publish_time) / 1000.0);
if (millis() - last_offset_publish_time >= 4 * 60 * 1000) { // duur van 1e verlaging in minuten EVENTUEEL WIJZIGEN
ESP_LOGD("debug", "bezig met timer state 1");
id(overshoot_stooklijn_offset).publish_state(-3); // stooklijn verlaging in aantal graden Ta, 1 hoger dan vorige stap
ESP_LOGD("debug", "overshoot stooklijn 3");
last_offset_publish_time = millis();
id(stooklijn_target) = (int)round(Z * (oat - id(stooklijn_min_oat).state) + id(stooklijn_max_wtemp).state) +
(id(wp_stooklijn_offset).state) + (id(overshoot_stooklijn_offset).state);
ESP_LOGD("stooklijn", "gecorrigeerd target stap 2 overshoot: %.1f", id(stooklijn_target));
id(watertemp_target).publish_state(id(stooklijn_target));
state++;
}
} else if (state == 2) {
ESP_LOGD("debug", "OvershootLogic: %s", OvershootLogic ? "true" : "false");
ESP_LOGD("debug", "Timer in seconden: %.0f", (millis() - last_offset_publish_time) / 1000.0);
if (millis() - last_offset_publish_time >= 4 * 60 * 1000) { // duur van 2e verlaging in minuten EVENTUEEL WIJZIGEN
ESP_LOGD("debug", "bezig met timer state 2");
id(overshoot_stooklijn_offset).publish_state(-2); // stooklijn verlaging in aantal graden Ta, 1 hoger dan vorige stap
ESP_LOGD("debug", "overshoot stooklijn -2");
last_offset_publish_time = millis();
id(stooklijn_target) = (int)round(Z * (oat - id(stooklijn_min_oat).state) + id(stooklijn_max_wtemp).state) +
(id(wp_stooklijn_offset).state) + (id(overshoot_stooklijn_offset).state);
ESP_LOGD("stooklijn", "gecorrigeerd target stap 3 overshoot: %.1f", id(stooklijn_target));
id(watertemp_target).publish_state(id(stooklijn_target));
state++;
}
} else if (state == 3) {
ESP_LOGD("debug", "OvershootLogic: %s", OvershootLogic ? "true" : "false");
ESP_LOGD("debug", "Timer in seconden: %.0f", (millis() - last_offset_publish_time) / 1000.0);
if (millis() - last_offset_publish_time >= 4 * 60 * 1000) { // duur van 3e verlaging in minuten EVENTUEEL WIJZIGEN
ESP_LOGD("debug", "bezig met timer state 3");
id(overshoot_stooklijn_offset).publish_state(-1);
ESP_LOGD("debug", "overshoot stooklijn-1");
last_offset_publish_time = millis();
id(stooklijn_target) = (int)round(Z * (oat - id(stooklijn_min_oat).state) + id(stooklijn_max_wtemp).state) +
(id(wp_stooklijn_offset).state) + (id(overshoot_stooklijn_offset).state);
ESP_LOGD("stooklijn", "gecorrigeerd target stap 4 overshoot: %.1f", id(stooklijn_target));
id(watertemp_target).publish_state(id(stooklijn_target));
state++;
}
} else if (state == 4) {
ESP_LOGD("debug", "OvershootLogic: %s", OvershootLogic ? "true" : "false");
ESP_LOGD("debug", "Timer in seconden: %.0f", (millis() - last_offset_publish_time) / 1000.0);
if (millis() - last_offset_publish_time >= 3 * 60 * 1000) { // duur van laatste verlaging in minuten EVENTUEEL WIJZIGEN
ESP_LOGD("debug", "bezig met timer state 4");
id(overshoot_stooklijn_offset).publish_state(-0);
ESP_LOGD("debug", "overshoot stooklijn 0");
OvershootLogic = false;
ESP_LOGD("debug", "KLAAR");
id(stooklijn_target) = (int)round(Z * (oat - id(stooklijn_min_oat).state) + id(stooklijn_max_wtemp).state) +
(id(wp_stooklijn_offset).state) + (id(overshoot_stooklijn_offset).state);
ESP_LOGD("stooklijn", "origineel target: %.1f", id(stooklijn_target));
id(watertemp_target).publish_state(id(stooklijn_target));
state = 0;
}
}
}
}
else if (!id(compressor_running).state) {
ESP_LOGD("debug", "Compressor not running. Resetting state to 0");
state = 0;
// Reset timer only if the compressor is not running
last_offset_publish_time = millis();
}
if (id(compressor_running).state) {
temp_new_target = std::min(temp_new_target, id(stooklijn_target));
ESP_LOGD("target", "RETURN_TEMP: %.1f OUTLET_TEMP: %.1f TARGET: %.1f NEW_TARGET: %.1f ",
id(water_temp_retour).state, id(water_temp_aanvoer).state, id(stooklijn_target), temp_new_target);
id(pendel_watertemp_target).publish_state(temp_new_target);
id(water_temp_target_output).set_level(temp_new_target * 0.01);
} else if (!id(compressor_running).state) {
id(water_temp_target_output).set_level(id(stooklijn_target) * 0.01);
target_reached = false;
}
// ----------------calculate stooklijn target---------------------------------
if(prev_oat != oat || id(force_update_stooklijn)){ // if no oat change, no update needed, unless forced or first run
prev_oat = oat;
id(force_update_stooklijn) = false; //reset force boolean
const float Z = ((float)id(stooklijn_min_wtemp).state-(float)id(stooklijn_max_wtemp).state) / ((float)id(stooklijn_max_oat).state - (float)id(stooklijn_min_oat).state);
ESP_LOGD("stooklijn", "verwarmen volgens stooklijn, met buitentemp: %.1f, Z: %.1f",oat, Z);
if(oat < id(stooklijn_min_oat).state) { //if oat below minimum oat, clamp to minimum value
oat = id(stooklijn_min_oat).state;
} else if(oat > id(stooklijn_max_oat).state) { //if oat above max value, clamp to maximum value
oat = id(stooklijn_max_oat).state;
}
id(stooklijn_target) = (int)round(Z * (oat - id(stooklijn_min_oat).state) + id(stooklijn_max_wtemp).state) + (id(wp_stooklijn_offset).state) + (id(overshoot_stooklijn_offset).state);
ESP_LOGD("stooklijn", "New stooklijn target value (after correction): %.1f", id(stooklijn_target));
id(watertemp_target).publish_state(id(stooklijn_target)); //publish new stooklijn value to watertemp value sensor
}
- platform: modbus_controller
modbus_controller_id: lg
name: "Tempbuiten"
id: buiten_temp
register_type: read
skip_updates: 3
address: 12
unit_of_measurement: "°C"
value_type: S_WORD
accuracy_decimals: 1
filters:
- multiply: 0.1
- sliding_window_moving_average:
window_size: 15
send_every: 15
- platform: modbus_controller
modbus_controller_id: lg
name: "Binnentemperatuur"
id: binnen_temp
register_type: read
skip_updates: 3
address: 7
unit_of_measurement: "°C"
value_type: U_WORD
accuracy_decimals: 1
filters:
- multiply: 0.1
- platform: modbus_controller
modbus_controller_id: lg
name: "Doeltemperatuur"
id: doel_temp
register_type: holding
address: 2
unit_of_measurement: "°C"
value_type: U_WORD
accuracy_decimals: 1
skip_updates: 1
filters:
- multiply: 0.1
- platform: template
name: "Stooklijn Watertemp Target"
id: watertemp_target
unit_of_measurement: "°C"
update_interval: 10s
lambda: |-
return id(stooklijn_target);
- platform: template
name: "Anti-pendel Watertemp Target"
id: pendel_watertemp_target
unit_of_measurement: "°C"
update_interval: 10s
web_server:
port: 80