forked from aiolos/ESPHome-config
-
Notifications
You must be signed in to change notification settings - Fork 0
/
P1-water-gas-custom.yaml
475 lines (410 loc) · 12.3 KB
/
P1-water-gas-custom.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
# ⬇ Config your entity names here: ⬇ #
substitutions:
device_description: P1 poort smartmeter lezer en waterverbruik
friendly_name: P1-smartmeter_watermeter
devicename: p1-dsmr-watermeter
esphome:
name: $devicename
comment: ${device_description}
platform: ESP8266
board: d1_mini
esp8266_restore_from_flash: true
name_add_mac_suffix: false
wifi:
ssid: !secret wifi_ssid
password: !secret wifi_password
domain: .lan
# Enable fallback hotspot (captive portal) in case wifi connection fails
ap:
ssid: “${devicename} Fallback AP"
password: !secret fallback_ap_password
manual_ip:
static_ip: 192.168.1.152
gateway: 192.168.1.1
subnet: 255.255.255.0
captive_portal:
# ⬇ Enable Home Assistant API ⬇
ota:
password: !secret ota_password
safe_mode: true #go to safe_mode if update fails
num_attempts: 5
api:
#password: !secret api_password
encryption:
key: !secret api_key_password
# ⬇ Enable webinterface ⬇
web_server:
port: 80
include_internal: true
# Disable logging (uses the same uart as P1)
logger:
level: WARN
baud_rate: 0
dsmr:
id: dsmr_instance
max_telegram_length: 1500
# ⬇ trottle the DSMR telegram OUTPUT for every X-seconds, DSMR5.0 default: 1 msg/second⬇
request_interval: 10s
uart:
- rx_pin: RX
baud_rate: 115200
rx_buffer_size: 1700 #1024
#----------------------end of config--------------------------------------------------------#
# ⬇ Default globals for watermeter statistics ⬇ #
globals:
- id: main_counter_pulses
type: int
restore_value: yes
initial_value: '0'
- id: secondary_counter_pulses
type: int
restore_value: yes
initial_value: '0'
- id: event_quantity
type: int
restore_value: no
initial_value: '0'
- id: last_event_quantity
type: int
restore_value: no
initial_value: '0'
- id: event_counter
type: int
restore_value: no
initial_value: '0'
- id: current_event_quantity
type: int
restore_value: no
initial_value: '0'
script:
- id: reset_main_counter
then:
- lambda: |-
id(main_counter_pulses) = 0;
id(water_main_consumption).publish_state(id(main_counter_pulses));
- id: reset_secondary_counter
then:
- lambda: |-
id(secondary_counter_pulses) = 0;
id(water_secondary_consumption).publish_state(id(secondary_counter_pulses));
- id: publish_states
then:
- lambda: |-
id(water_main_consumption).publish_state(id(main_counter_pulses));
id(water_secondary_consumption).publish_state(id(secondary_counter_pulses));
# ⬇ Enable time component voor reset elke nacht ⬇ #
time:
- platform: homeassistant
id: time_homeassistant
sensor:
#------------------------# Watermeter #------------------------#
# - platform: integration
# name: "Water usage"
# sensor: water_pulse_counter
# time_unit: min
# accuracy_decimals: 0
# unit_of_measurement: "liter"
# restore: true
# - platform: integration
# unit_of_measurement: "liter"
# name: "Water usage day"
# sensor: water_pulse_counter
# time_unit: d
# accuracy_decimals: 0
# restore: true
# internal: true
# - platform: pulse_counter
# pin: GPIO2
# id: water_pulse_counter
# name: "water pulse counter"
# state_class: measurement
# icon: "mdi:water"
# internal_filter: 100ms #10us
# update_interval: 10s
# accuracy_decimals: 0
# unit_of_measurement: "L/min"
# filters:
#- delayed_on_off: 50ms
#------------------------# P1 DSMR meter #------------------------#
- platform: dsmr
energy_delivered_tariff1:
name: "Energy Consumed Tariff 1"
id: EDT1
# state_class: total_increasing
unit_of_measurement: "kWh"
# filters:
# - lambda: |-
# static float last_value = NAN;
# if (isnan(last_value) || id(EDT1).state >= last_value) {
# last_value = id(EDT1).state;
# return id(EDT1).state;
# } else {
# return NAN;
# }
energy_delivered_tariff2:
name: "Energy Consumed Tariff 2"
id: EDT2
# state_class: total_increasing
unit_of_measurement: "kWh"
# filters:
# #- filter_out: nan
# - lambda: |-
# static float last_value = NAN;
# if (isnan(last_value) || id(EDT2).state >= last_value) {
# last_value = id(EDT2).state;
# return id(EDT2).state;
# } else {
# return NAN;
# }
energy_returned_tariff1:
name: "Energy Produced Tariff 1"
id: EDR1
icon: mdi:CurrencyEur
# state_class: total_increasing
unit_of_measurement: "kWh"
filters:
- filter_out: nan
energy_returned_tariff2:
name: "Energy Produced Tariff 2"
id: EDR2
# state_class: total_increasing
unit_of_measurement: "kWh"
filters:
- filter_out: nan
power_delivered:
name: "Power Consumed"
id: PowerC
# accuracy_decimals: 3
# unit_of_measurement: "W"
power_returned:
name: "Power Produced"
id: PowerR
# accuracy_decimals: 3
# unit_of_measurement: "W"
current_l1:
name: "Current Phase 1"
icon: mdi:alternating-current
electricity_failures:
name: "Electricity Failures"
icon: mdi:alert
electricity_long_failures:
name: "Long Electricity Failures"
icon: mdi:alert
voltage_l1:
name: "Voltage Phase 1"
icon: mdi:high-voltage
voltage_l2:
name: "Voltage Phase 2"
icon: mdi:high-voltage
voltage_l3:
name: "Voltage Phase 3"
icon: mdi:high-voltage
# ⬇ 3 phase systems are disabled by default in HA frontend, enable here or in the HA frontend ⬇ #
current_l2:
disabled_by_default: true
name: "Current Phase 2"
icon: mdi:alternating-current
current_l3:
disabled_by_default: true
name: "Current Phase 3"
icon: mdi:alternating-current
power_delivered_l1:
disabled_by_default: true
name: "Power Consumed Phase 1"
accuracy_decimals: 3
power_delivered_l2:
disabled_by_default: true
name: "Power Consumed Phase 2"
accuracy_decimals: 3
power_delivered_l3:
disabled_by_default: true
name: "Power Consumed Phase 3"
accuracy_decimals: 3
power_returned_l1:
disabled_by_default: true
name: "Power Produced Phase 1"
accuracy_decimals: 3
power_returned_l2:
disabled_by_default: true
name: "Power Produced Phase 2"
accuracy_decimals: 3
power_returned_l3:
disabled_by_default: true
name: "Power Produced Phase 3"
unit_of_measurement: "W"
accuracy_decimals: 3
#----------------------------------------⬇GASMETER⬇----------------------------------------------------#
# ⬇ disable when no gasmeter is used ⬇ #
gas_delivered:
name: "Gas Consumed"
icon: mdi:GasCylinder
device_class: 'gas'
state_class: total_increasing
unit_of_measurement: "m³"
#--------------------------------------⬇TEMPLATE SENSORS⬇-----------------------------------------------#
- platform: template
name: total energy consumed
unit_of_measurement: "kWh"
state_class: "total_increasing"
lambda: |-
if ((id(EDT1).state + id(EDT2).state) > 0) {
return (id(EDT1).state + id(EDT2).state);
} else {
return 0;
}
# return (id(EDT1).state + id(EDT2).state);
- platform: template
name: total energy returned
lambda: |-
return (id(EDR1).state + id(EDR2).state);
unit_of_measurement: "kWh"
state_class: "total_increasing"
##------------------------- ⬇ Watermeter template sensors for stats ⬇ -------------##
- platform: template
id: water_main_consumption
name: "Water verbruik Liter"
unit_of_measurement: "L"
state_class: "total_increasing"
device_class: 'water'
accuracy_decimals: 0
icon: "mdi:cube-outline"
- platform: template
id: watermeter_total
name: "watermeter totaal stand"
state_class: "total_increasing"
icon: mdi:water
#update_interval: 6s
unit_of_measurement: "m³"
device_class: 'water'
accuracy_decimals: 3
lambda: return ( (id(water_main_consumption).state) * 0.001);
- platform: template
id: water_secondary_consumption
name: "secondary water verbruik"
unit_of_measurement: "L"
device_class: 'water'
accuracy_decimals: 0
icon: "mdi:water"
- platform: template
id: current_water_consumption
name: "current water consumption"
unit_of_measurement: "L"
device_class: 'water'
accuracy_decimals: 0
icon: "mdi:water"
- platform: template
id: last_water_consumption
name: "last water consumption"
unit_of_measurement: "L"
device_class: 'water'
accuracy_decimals: 0
icon: "mdi:water"
binary_sensor:
# Nabijheidssensor
- platform: gpio
id: water_pulse_counter
pin: GPIO2
internal: true
filters:
#- delayed_on_off: 50ms
- lambda: |-
id(main_counter_pulses) += x;
id(secondary_counter_pulses) += x;
id(event_quantity) += x;
return x;
on_state: #on_state
- script.execute: publish_states
interval:
# Saves the last consumption
# An event is published when a water flow (>= 1L / 15 seconds) is
# detected and followed by a stop of consumption for a defined time.
- interval: 15sec
then:
- lambda: |-
if (id(event_quantity) != id(last_event_quantity)) {
// Water continues to flow
// Reset event counter
id(event_counter) = 0;
} else {
// Water no longer flows
if (id(event_quantity)) {
// 4 * 15 * 5 = 5min
if (id(event_counter) < 4 * 5) {
// Timeout is not reaches
id(event_counter)++;
} else {
// Timeout is reaches
id(last_water_consumption).publish_state(id(event_quantity));
// Send event to Home Assistant
api::HomeAssistantServiceCallAction<> *api;
api = new api::HomeAssistantServiceCallAction<>(api_apiserver, true);
// Event id length limit is 32 characters
api->set_service("esphome.last_consumption_changes");
api->play();
id(event_quantity) = 0;
}
}
}
id(last_event_quantity) = id(event_quantity);
# Track the current water consumption
- interval: 2sec
then:
- lambda: |-
if (id(event_quantity) != id(current_event_quantity)) {
id(current_water_consumption).publish_state(id(event_quantity));
}
id(current_event_quantity) = id(event_quantity);
#--------------------------------------INTERNAL SENSORS⬇-----------------------------------------------#
text_sensor:
- platform: dsmr
identification:
name: DSMR Identification
internal: true
p1_version:
name: DSMR Version
internal: true
electricity_tariff:
name: current tariff plan
id: CTP
electricity_failure_log:
name: "electricity failure log"
message_short:
name: "electricity meter message"
#internal: true
message_long:
name: "electricity meter message long"
internal: true
- platform: wifi_info
ip_address:
name: IP-adres
id: ip_adres
icon: mdi:ip-network
ssid:
name: Netwerk
id: netwerk
icon: mdi:access-point-network
internal: true
mac_address:
name: Mac-adres
id: mac_adres
icon: mdi:folder-key-network-outline
internal: true
- platform: version
name: ESPHome Version
hide_timestamp: true
internal: true
#--------------------------------------⬇Buttons⬇-----------------------------------------------#
button:
- platform: restart
name: "${friendly_name} restart"
entity_category: config
- platform: template
name: "${friendly_name} reset main counter button"
icon: "mdi:restart"
on_press:
- script.execute: reset_main_counter
- platform: template
name: "${friendly_name} reset secondary counter button"
icon: "mdi:restart"
on_press:
- script.execute: reset_secondary_counter