-
Notifications
You must be signed in to change notification settings - Fork 5
/
pump_controller.yaml
373 lines (341 loc) · 10.6 KB
/
pump_controller.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
# Underfloor Heating Pump Controller
# ESPHome - Sonoff S20 extended with Dallas temperature sensor
#
# Controls a underfloor heating-pump. When warm water is received from the
# central heater, warm water is entering the pump via its pipes. This is
# detected by the temperature sensor and the pump will be switched on.
# When the heater stops (requested temperature is reached) the flow of water
# will cool down. The temperature sensor will detect this and will shut
# down the pump.
#
# Two thresholds are used to determine when to switch on or of
# the pump. These are set by two service calls.
# - threshold_on
# - threshold_off
#
# Multi room temperature control
# If warm water is received by the pump, but the room is currently empty,
# it is better to not start the pump. It may act as a valve. No warm water
# will be spread through the pipes and this will save some energy.
# For this, the controller can be set in manual mode. In this mode the pump
# is controlled by a template switch. The temperature sensor is ignored.
#
# Anti corrosion
# If the pump has not run for a longer period of time (days, weeks), it is
# possible that it corrodes. The pump is not rotating anymore. The controller
# makes sure that every day the pump runs for a minute (at midnight).
#
# The S20 green light indicates the mode. In automatic mode (default) flashes
# slowly. In manual mode the green led is just on.
#
# The S20 push button sequences through the following options:
# 1- When in automatic mode
# - Manual mode is selected
# - Pump input switch is set to 'OFF'
#
# 2- When in manual mode and Pump is 'OFF'
# - pump input switch is set to 'ON'
#
# 3- When in manual mode and Pump is 'ON'
# - Automatic mode is selected
# - pump input switch is set to 'OFF'
#
# In case the controller is unable to connect with Home Assistant for 5 minutes,
# the controller switches over to automatic mode.
#
esphome:
name: pump_controller
platform: ESP8266
board: esp01_1m
esp8266_restore_from_flash: yes
comment: Underfloor heating pump controller.
on_boot:
then:
- script.execute: led_signaling
- script.execute: controller
wifi:
ssid: !secret wifi_ssid
password: !secret wifi_password
ota:
password: !secret esphome_ota_password
# Enable logging
logger:
# Enable Home Assistant API
api:
password: !secret ha_api_password
services:
- service: threshold_off
variables:
value: float
then:
- lambda: |-
if (value < 0.0f){
return;
}
if (value > 48.0f){
value = 48.0;
}
id(g_threshold_temp_off) = value;
auto d = id(g_threshold_temp_on) - id(g_threshold_temp_off);
if (d < 2.0){
id(g_threshold_temp_on) = value + 2.0;
}
- script.execute: controller
- service: threshold_on
variables:
value: float
then:
- lambda: |-
if (value > 50.0f){
return;
}
if (value < 2.0) {
value = 2.0;
}
id(g_threshold_temp_on) = value;
auto d = id(g_threshold_temp_on) - id(g_threshold_temp_off);
if (d < 2.0){
id(g_threshold_temp_off) = value - 2.0;
}
- script.execute: controller
globals:
# true when in automatic mode
# false when in manual mode
- id: g_automatic_mode
type: bool
restore_value: no
initial_value: "true"
# if water temperature below this threshold
# pump demand automatic will be 'off' (false)
- id: g_threshold_temp_off
type: float
restore_value: yes
initial_value: "23.0"
# if water temperature above this threshold
# pump demand automatic will be 'on' (true)
- id: g_threshold_temp_on
type: float
restore_value: yes
initial_value: "30.0"
# manual demand pump
- id: g_pump_demand_manual
type: bool
restore_value: no
initial_value: "false"
# true in case anti corrosion is active
- id: g_pump_demand_anti_corr
type: boolean
restore_value: no
initial_value: "false"
# demand based on water temperature
- id: g_pump_demand_automatic
type: boolean
restore_value: no
initial_value: "false"
dallas:
- pin:
number: GPIO3
update_interval: 1s
sensor:
- platform: dallas
id: sensor_water_temperature
name: "Water temperature"
address: 0xEC031564F652FF28
unit_of_measurement: "°C"
accuracy_decimals: 1
filters:
- delta: 0.1
on_value:
then:
# the controller is notified when the water temperature crosses
# one of the thresholds
- lambda: |-
/* only useful when in automatic mode */
if(!id(g_automatic_mode)){
return;
}
/* only submit when something has changed */
auto water_temperature = id(sensor_water_temperature).state;
if (
water_temperature < id(g_threshold_temp_off)
&& id(g_pump_demand_automatic)){
id(g_pump_demand_automatic) = false;
id(controller).execute();
}
else if (
water_temperature > id(g_threshold_temp_on)
&& !id(g_pump_demand_automatic)){
id(g_pump_demand_automatic) = true;
id(controller).execute();
}
- platform: template
name: "Threshold off"
id: sensor_threshold_temp_off
unit_of_measurement: "°C"
accuracy_decimals: 1
lambda: return id(g_threshold_temp_off);
update_interval: 1ms
filters:
- delta: 0.1
- platform: template
id: sensor_threshold_temp_on
name: "Threshold on"
unit_of_measurement: "°C"
accuracy_decimals: 1
lambda: return id(g_threshold_temp_on);
update_interval: 1ms
filters:
- delta: 0.1
binary_sensor:
# The S20 push button can be used to select the automatic mode and
# the manual demand. This is an alternative for both template switches
# sw_automatic_mode and sw_on_off.
- platform: gpio
id: s20_push_button
pin:
number: GPIO0
mode: INPUT_PULLUP
inverted: True
on_press:
then:
- lambda: |-
if(id(g_automatic_mode)){
id(g_automatic_mode) = false;
id(g_pump_demand_manual) = false;
}
else if(!id(g_pump_demand_manual)){
id(g_pump_demand_manual) = true;
}
else{
id(g_automatic_mode) = true;
id(g_pump_demand_manual) = false;
}
- script.execute: led_signaling
- script.execute: controller
# In case the API connection is lost, the controller will change
# to automatic mode.
- platform: template
id: sensor_api_connected
lambda: return global_api_server->is_connected();
filters:
- delayed_off: 5min
on_release:
then:
- logger.log: Lost API connection, selecting automatic mode
- switch.turn_on: sw_automatic_mode
# template sensor to publish pump state
- platform: template
name: "Pump"
id: sensor_pump_state
lambda: return id(s20_relay).state;
switch:
# relay, switches pump on and off
- platform: gpio
pin: GPIO12
id: s20_relay
# Boolean input to toggle between manual or automatic mode
- platform: template
name: Manual/Automatic
id: sw_automatic_mode
lambda: return id(g_automatic_mode);
turn_on_action:
- globals.set:
id: g_automatic_mode
value: "true"
- script.execute: controller
- script.execute: led_signaling
turn_off_action:
- globals.set:
id: g_automatic_mode
value: "false"
- script.execute: controller
- script.execute: led_signaling
# Boolean input to control manual demand
- platform: template
name: "On/Off"
id: sw_on_off
lambda: return id(g_pump_demand_manual);
turn_on_action:
- globals.set:
id: g_pump_demand_manual
value: "true"
- script.execute: controller
turn_off_action:
- globals.set:
id: g_pump_demand_manual
value: "false"
- script.execute: controller
time:
- platform: sntp
on_time:
# schedule anti corrosion action, once a day
- hours: 1
then:
- globals.set:
id: g_pump_demand_anti_corr
value: "true"
- script.execute: controller
- delay: 60s
- globals.set:
id: g_pump_demand_anti_corr
value: "false"
- script.execute: controller
script:
# script for calculating the demand for the pump. Should
# it run or not. Applies the changes to the relay.
- id: controller
then:
- lambda: |-
/* calculate if pump should be on or not */
bool demand = false;
if (id(g_pump_demand_anti_corr)){
/* anti corrosion run */
demand = true;
}
else if (!id(g_automatic_mode)){
/* manual mode */
demand = id(g_pump_demand_manual);
}
else{
/* automatic mode */
demand = id(g_pump_demand_automatic);
}
/* only send commands when needed */
if (demand && !id(s20_relay).state) {
id(s20_relay).turn_on();
} else if (!demand && id(s20_relay).state){
id(s20_relay).turn_off();
}
- id: led_signaling
then:
# The green led is used to show the mode of operation:
# - manual mode, led is on
# - automatic mode, led blinks
- lambda: |-
if (id(g_automatic_mode)){
auto call = id(s20_led).turn_on();
call.set_effect("auto_effect");
call.perform();
} else {
auto call = id(s20_led).turn_on();
call.set_effect("none");
call.perform();
}
output:
- platform: esp8266_pwm
id: s20_green_led
pin:
number: GPIO13
inverted: True
light:
- platform: monochromatic
output: s20_green_led
id: s20_led
effects:
- strobe:
name: auto_effect
colors:
- brightness: 100%
duration: 1s
- brightness: 0%
duration: 2s