-
Notifications
You must be signed in to change notification settings - Fork 30
/
wm-esp32.yaml
executable file
·1172 lines (1068 loc) · 39.5 KB
/
wm-esp32.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
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
---
## ---------------------------------------------------------------------------
## WMBUS METER az-delivery-devkit-v4 + CC1101 for Diehl IZAR RC 868 I R4 PL
## Hardware: ESP32 240MHz, 520KB RAM, 4MB Flash
##
## This version shows data from the defined watermeter and
## uses the watermeterID (HEX) from the secrets.yaml file.
##
## usage: 1. Using the last wM-Bus component
## 2. Using Homassistant API (discovery + devices)
## 3. Using HTTP Post to service server (optional)
## 4. Using wmbusmeters i a pipe (optional)
## 5. uses backup component (optinal)
## 6. uses syslog component (optinal)
##
## Backup: http://water-meter-esp.local/config.yaml
## curl -v 'http://water-meter-esp/config.yaml' --digest -u USERNAME:PASSWORD -o config.yaml
## REST: curl -i http://water-meter-esp.local/text_sensor/watermeterdata
## SYSLOG: tail -f /var/log/syslog | grep "water-meter"
##
## ---------------------------------------------------------------------------
substitutions:
## device settings
device_name_short: "water-meter-esp"
device_description: "Wasserzähler ESP32, CUL - CC1101, IZAR module (Diehl IZAR RC 868 I R4 PL (SzczepanLeon) my Watermeter"
projectname: "Diehl IZAR RC 868.Watermeter"
friendly_name: "Watermeter" # device name
appversion: "2.0.9"
## logger settings
log_level: "VERBOSE" # not that logging need memory, so in production mode use "WARN"
log_wmbus: "ERROR" # Loglevel for wmbus meters component
log_baudrate: "115200" # use 0 to disable serial UART port logging.
## data service (optional, default: False)
## use only if you have a service host present
service_enabled: "false"
service_url: !secret service_host
service: "izar.watermeter"
## -----------------------------------------------------------------
## HARDWARE az-delivery-devkit-v4,ESP32 240MHz, 520KB RAM, 4MB Flash
## -----------------------------------------------------------------
esp32:
board: az-delivery-devkit-v4
framework:
type: arduino
# Customize the frequency in which data is flushed to the flash.
preferences:
flash_write_interval: 10min
## ----------------------------------------------------------------
## APPLICATION ESPHOME
## ----------------------------------------------------------------
esphome:
name: ${device_name_short}
comment: ${device_description}
# Automatically add the mac address to the name
# so you can use a single firmware for all devices
name_add_mac_suffix: false
# additiona compile otions
platformio_options:
platform: espressif32
board: az-delivery-devkit-v4
## larger stack size required with all registers enable_load_test
build_flags:
- "-DCONFIG_ARDUINO_LOOP_STACK_SIZE=32768"
# monitor_filters: esp32_exception_decoder
project:
name: ${projectname}
version: ${appversion}
build_path: ./build/${device_name_short}
on_boot:
then:
- globals.set:
id: boot_counter
value: !lambda "return id(boot_counter)+=1;"
- globals.set:
id: send_millisecond
value: !lambda "return millis();"
- logger.log:
level: WARN
tag: "system"
format: "BOOTMESSAGE:${device_name_short} API is connected, Device ready!"
- component.update: bootcounter
on_shutdown:
then:
- logger.log:
level: ERROR
tag: "system"
format: "BOOTMESSAGE:${device_name_short} is down!"
## ----------------------------------------------------------------
## EXTERNAL COMPONENTS
## ----------------------------------------------------------------
external_components:
# uses the latest version from SzczepanLeon (github)
# https://github.com/SzczepanLeon/esphome-components
# You can make ESPHome check the repository every time by setting this option to 0s
- source: github://SzczepanLeon/esphome-components@main
refresh: 0s
components: [wmbus]
# optinal: use local component from
# https://github.com/zdzichu6969/esphome-components
- source:
type: local
path: custom_components
components: [backup]
# optinal: use local component from
# https://github.com/TheStaticTurtle/esphome_syslog
- source:
type: local
path: custom_components
components: [syslog]
# ----------------------------------------------------------------
# Save your ESPHome device configuration in firmware and and
# recover it if you lost source files.
# ----------------------------------------------------------------
backup:
auth:
username: !secret web_username
password: !secret web_password
force_update: false
## ---------------------------------------------------
## COMPONENT SYSLOG SERVICE ENABLED
## ---------------------------------------------------
syslog:
ip_address: !secret syslog_server
port: !secret syslog_port
min_level: DEBUG
enable_logger: true
## ---------------------------------------------------
## COMPONENT LOGGER
## ---------------------------------------------------
logger:
id: appslogger
level: ${log_level}
baud_rate: ${log_baudrate}
logs:
wmbus: ${log_wmbus}
wMBus-lib: ${log_wmbus}
sensor: WARN
sensor.filter: WARN
text_sensor: WARN
api.service: ERROR
json: ERROR
mqtt: WARN
scheduler: ERROR
internal_temperature: ERROR
wifi: WARN
component: ERROR
api: WARN
## ----------------------------------------------------------------
## GLOBALS VARIABLES
## ----------------------------------------------------------------
globals:
- id: boot_counter
type: int
restore_value: yes
initial_value: "0"
- id: last_value
type: float
restore_value: yes
initial_value: "0.00"
- id: current_value
type: float
restore_value: yes
initial_value: "0.00"
- id: hour_value
type: float
restore_value: yes
initial_value: "0.00"
- id: daily_value
type: float
restore_value: yes
initial_value: "0.00"
- id: yesterday_value
type: float
restore_value: yes
initial_value: "0.00"
- id: week_value
type: float
restore_value: yes
initial_value: "0.00"
- id: lastmonth_value
type: float
restore_value: yes
initial_value: "0.00"
- id: year_value
type: float
restore_value: yes
initial_value: "0.00"
- id: send_millisecond
type: int
restore_value: no
initial_value: '0'
- id: cc1101_state
type: int
restore_value: no
initial_value: '0'
- id: alarm_error_text
type: std::vector<std::string>
restore_value: no
# initial_value: '{"no error", "general_alarm","leakage","meter_blocked","back_flow","underflow","overflow","submarine","sensor_fraud","mechanical_fraud"}'
initial_value: '{"Keiner", "Fehler","Zähler undicht","Zähler blockiert","Wasser Rückfluss","Wasser Unterlauf","Wasser Überlauf","Überschwemung","Sensor Fehler", "Mechanischer Fehler"}'
- id: cc1101_state_message
type: std::vector<std::string>
restore_value: no
initial_value: '{"Init", "Warte auf Daten", "Daten empfangem", "Ready", "Error"}'
## ---------------------------------------------------
## WIFI Settings
## ---------------------------------------------------
wifi:
networks:
# unifi accesspoint 2.4Ghz
- ssid: !secret ssid4_name
password: !secret ssid4_pswd
priority: 1
# office apple capsulate accesspoint 2.4Ghz
- ssid: !secret ssid3_name
password: !secret ssid3_pswd
priority: 2
# living room apple capsulate accesspoint 2.4Ghz
- ssid: !secret ssid2_name
password: !secret ssid2_pswd
priority: 3
domain: !secret domain
ap:
# ssid (Optional, string): The name of the access point to create. Leave empty to use the device name.
password: !secret app_pswd
## ---------------------------------------------------
## mDNS Component
## ---------------------------------------------------
mdns:
# if mDNS is disabled, they will no longer be able to automatically find your devices.
# It is recommended to leave mDNS enabled.
disabled: false
## ---------------------------------------------------
## COMPONENT CAPTIVE PORTAL
## ---------------------------------------------------
captive_portal:
## ---------------------------------------------------
## COMPONENT OTA
## ---------------------------------------------------
ota:
password: !secret ota_pswd
safe_mode: false
on_begin:
then:
- logger.log:
format: "OTA Start"
tag: "OTA"
level: WARN
on_progress:
then:
- logger.log:
level: WARN
tag: "OTA"
format: "OTA progress %0.1f%%"
args: ["x"]
on_end:
then:
- logger.log:
format: "OTA End"
tag: "OTA"
level: WARN
on_error:
then:
- logger.log:
format: "OTA update error %d"
tag: "OTA"
level: ERROR
args: ["x"]
## ---------------------------------------------------
## COMPONENT WEBSERVER (local hosted)
## ---------------------------------------------------
web_server:
port: 80
version: 2
js_url: !secret webserver_jsurl
## ---------------------------------------------------
## COMPONENT Home Assistant API
## Homeassistant service call (all values in liter):
## ---------------------------------------------------
## service: esphome.water_meter_esp_set_watermeter_esp_data
## data:
## water_val_hour: 0.00
## water_val_day: 167.00
## water_val_yesterday: 240.35
## water_val_week: 901.00
## water_val_year: 33143.00
## water_val_lastmonth: 7580.25
## ---------------------------------------------------
api:
id: espapi_wmbus_esp32
port: 6053
reboot_timeout: 0s
# https://esphome.io/components/api.html?highlight=api
encryption:
key: "inH49O9jBeK5yTGb1X2g4WV/1aS6YKUpu3Vu277fDgw="
services:
- service: set_watermeter_esp_data
variables:
water_val_hour: float
water_val_day: float
water_val_yesterday: float
water_val_week: float
water_val_year: float
water_val_lastmonth: float
then:
- globals.set:
id: hour_value
value: !lambda |-
if((water_val_hour) and (water_val_hour)>0.001){
ESP_LOGD("system", "Set hourly value to: %f", water_val_hour);
return (water_val_hour);
}else{
ESP_LOGD("system", "Skip setting hourly value");
return id(hour_value);
};
id(waterhour).publish_state(id(hour_value));
- globals.set:
id: daily_value
value: !lambda |-
if((water_val_day) and (water_val_day)>0.001){
ESP_LOGD("system", "Set daily value to: %f", water_val_day);
return (water_val_day);
}else{
ESP_LOGD("system", "Skip setting hourly value");
return id(hour_value);
};
id(waterday).publish_state(id(daily_value));
- globals.set:
id: yesterday_value
value: !lambda |-
if((water_val_yesterday) and (water_val_yesterday)>0.001){
ESP_LOGD("system", "Set yesterday value to: %f", water_val_yesterday);
return (water_val_yesterday);
}else{
ESP_LOGD("system", "Skip setting yesterday value");
return id(yesterday_value);
};
id(wateryesterday).publish_state(id(hour_value));
- globals.set:
id: week_value
value: !lambda |-
if((water_val_week) and (water_val_week)>0.001){
ESP_LOGD("system", "Set weekly value to: %f", water_val_week);
return (water_val_week);
}else{
ESP_LOGD("system", "Skip setting weekly value");
return id(week_value);
};
id(waterweek).publish_state(id(week_value));
- globals.set:
id: lastmonth_value
value: !lambda |-
if((water_val_lastmonth) and (water_val_lastmonth)>0.001){
ESP_LOGD("system", "Set last month value to: %f", water_val_lastmonth);
return (water_val_lastmonth);
}else{
ESP_LOGD("system", "Skip setting last month value");
return id(lastmonth_value);
};
id(waterlastmonth).publish_state(id(lastmonth_value));
- globals.set:
id: year_value
value: !lambda |-
if((water_val_year) and (water_val_year)>0.001){
ESP_LOGD("system", "Set last yearly value to: %f", water_val_year);
return (water_val_year);
}else{
ESP_LOGD("system", "Skip setting last yearly value");
return id(year_value);
};
id(wateryear).publish_state(id(year_value));
- logger.log:
tag: "system"
format: "All new Values set: hour: %.3f, day: %.3f, week: %.3f, last month: %.3f, year: %.3f"
level: INFO
args:
[
"id(hour_value)",
"id(daily_value)",
"id(week_value)",
"id(lastmonth_value)",
"id(year_value)",
]
## ---------------------------------------------------
## SNTP COMPONENT
## ---------------------------------------------------
time:
- platform: sntp
id: time_sntp
timezone: Europe/Berlin
servers:
- !secret local_sntp
- 0.at.pool.ntp.org
- 0.pool.ntp.org
on_time_sync:
# Components should trigger on_time_sync when they update the system clock.
then:
- if:
condition:
lambda: 'return id(device_lastBoot_time).state == "";'
then:
- text_sensor.template.publish:
id: device_lastBoot_time
state: !lambda return id(time_sntp).now().strftime("%Y-%m-%dT%H:%M:%S %Z");
- logger.log:
level: WARN
tag: "system"
format: "Synchronized sntp clock"
- script.execute: set_status_message
on_time:
# check cc1101 telegram state message every 30s
- seconds: 30
then:
- script.execute: set_status_message
# reset hourly value
- seconds: 0
minutes: 0
then:
- globals.set:
id: hour_value
value: "0.00"
- lambda: id(waterhour).publish_state(id(hour_value));
- logger.log:
tag: "system"
level: INFO
format: "Reset value hour, starting next hour"
# reset daily value and set yesterday value
- seconds: 0
minutes: 0
hours: 0
then:
- lambda: |-
id(yesterday_value)=id(daily_value);
id(wateryesterday).publish_state(id(yesterday_value));
id(daily_value)=0.00;
id(waterday).publish_state(id(daily_value));
- logger.log:
tag: "system"
level: INFO
format: "Set yesterday value and reset value daily, starting new day"
# reset weekly value, start new week
- seconds: 0
minutes: 0
hours: 0
days_of_week: MON
then:
- globals.set:
id: week_value
value: "0.00"
- lambda: id(waterweek).publish_state(id(week_value));
- logger.log:
tag: "system"
level: INFO
format: "Reset value weekly, starting new week"
# new year, reset yearly value
- seconds: 0
minutes: 0
hours: 0
days_of_month: 1
months: JAN
then:
- globals.set:
id: year_value
value: "0.00"
- lambda: id(wateryear).publish_state(id(year_value));
- logger.log:
tag: "system"
level: INFO
format: "Reset value yearly, starting new year"
## ---------------------------------------------------
## COMPONENT HTTP (optional)
## Prepare for sending HTTP requests
## ---------------------------------------------------
http_request:
id: http_request_data
useragent: ${service}
timeout: 10s
## ---------------------------------------------------
## COMPONENT SCRIPTS
## ---------------------------------------------------
script:
# id(set_status_message).execute();
- id: set_status_message
then:
- lambda: |-
int msgcode = int(id(cc1101_state));
std::string message = id(cc1101_state_message)[msgcode];
ESP_LOGD("wmbus", "cc1101 state message: %s, error code: %d", message.c_str(), msgcode);
id(watermeter_status_message).publish_state(message);
# id(post_device_state).execute();
- id: post_device_state
then:
- if:
condition:
lambda: return "${service_enabled} =='true'";
then:
- logger.log:
tag: "system"
level: INFO
format: "Post new data to the ${service_url}${device_name_short}, service enabled: ${service_enabled}"
- http_request.post:
url: "${service_url}/${device_name_short}"
verify_ssl: false
headers:
Content-Type: application/json
json: |-
root["device"] = "${device_name_short}";
root["waterdisplay"] = id(waterdisplay).state;
root["current"] = id(id(watercurrent)).state;
root["hour"] = id(waterhour).state;
root["day"] = id(waterday).state;
root["yesterday"] = id(wateryesterday).state;
root["week"] = id(waterweek).state;
root["month"] = id(watermonth).state;
root["lastmonth"] = id(waterhour).state;
root["year"] = id(wateryear).state;
root["bootcounter"] = id(bootcounter).state;
root["version"] = "${device_name_short} ${appversion}";
root["time"] = id(time_sntp).now().strftime("%Y-%m-%d %H:%M:%S");
on_response:
then:
- lambda: |-
if (status_code == 200) {
ESP_LOGI ("system", "HTTP POST o.k");
} else {
ESP_LOGI ("system", "HTTP POST failed");
}
## ------------------------------------------------------------------
## WMBUS CC1101 --> ESP32 az-delivery-devkit-v4
## ------------------------------------------------------------------
##
##
## o 1 (3.3V)
## |
## ╭――x――x――x――x――x――x――x――x――x――x――x――x――x――x――x――x――x――x――x――o―╮
## | |
## | EP32 |
## - | 5v az-delivery-devkit-v4 | -- ANT
## | |
## | 16 17 5 18 19 23 |
## ╰――x――x――x――x――x――x――x――x――o――x――o――o――o――o――o――o――o――o――o――o―╯
## | | | | | | |
## o | | o | | ╰-o - 2 (GND)
## 7 o | 4 o o
## GDO0 6 | CLK 5 3
## GD02 o MISO M0SI
## 8
## CSN
##
## ------------------------------------------------------------------
wmbus:
mosi_pin: GPIO23 ## SI: braun 3: MOSI Attached to Hardware SPI controller MOSI SPI Interface
miso_pin: GPIO19 ## SO: grün 5: MISO Attached to Hardware SPI controller MISO SPI Interface
clk_pin: GPIO18 ## SCLK: violett 4: SCK Attached to Hardware SPI controller CLK
cs_pin: GPIO05 ## CSN: orange 8: CSN Attached to Hardware SPI controller
gdo0_pin: GPIO16 ## GD00: gelb 7: RX Clock output. High Impedance !
gdo2_pin: GPIO17 ## GD02: weiss 6: TX FIFO status signals. High Impedance !
# log_unknown (Optional): Show telegrams from not configured meters in log. Defaults to False
log_unknown: False
## -------------------------------------------------
## Using wmbusmeters i a pipe (optional)
## uncomment for using
## -------------------------------------------------
# clients:
# - name: "wmbusmeters"
# ip_address: !secret wmbusmeter_host
# port: 7227
# format: rtlwMBus
# transport: UDP
## -------------------------------------------------
## setting: wmbusmeters.conf on wbusmeters server
## -------------------------------------------------
## loglevel: normal
## device: rtlwmbus:CMD(nc -lku 7227)
## donotprobe: /dev/ttyAMA0
## logtelegrams: false
## format: json
## logfile: /dev/stdout
## shell: /wmbusmeters/mosquitto_pub.sh "wmbusmeters/$METER_NAME" "$METER_JSON"
## -------------------------------------------------
## led blink mode (optional) xx = PIN
## -------------------------------------------------
# led_pin: GPIOxx
# led_blink_time: "100ms"
## ---------------------------------------------------
## BINARY SENSOR
## ---------------------------------------------------
binary_sensor:
# simulate led state (updated by id: "waterdisplay")
- platform: template
name: "Wasseruhr Status Led"
id: statusled
icon: mdi:led-outline
entity_category: "diagnostic"
lambda: "return id(current_value) > 0;"
## ---------------------------------------------------
## SENSORS
## ---------------------------------------------------
sensor:
- platform: wmbus
# Meter ID (usually from sticker). Can be specified as decimal or hex.
# only HEX is working for my watermeter !
# see: https://github.com/SzczepanLeon/esphome-components/issues/6
# edit watermeterid in the secrets file
# add_prefix: enable/disable add watermeterid to lqi, rssi, total_water_m3
meter_id: !secret watermeterId
type: izar
add_prefix: false
# The LQI value reported by the CC1101 is a 7 bit unsigned number with a range from 0 to 127.
# Note that a lower value indicates a better link.
# The LQI of a received packet will be bad (higher number) when there is lot of interference.
lqi:
id: wmbus_cc1101_lqi
name: "${friendly_name} CC1101 LQI"
entity_category: "diagnostic"
unit_of_measurement: "lqi"
state_class: "measurement"
# The RSSI value reported by the CC1101 is a 8 bit signed number with an effective
# range from -138 dBm to -10.5 dBm when the CC1101 is operating around 868 MHz.
# RSSI stands for received signal strength (power) indication (in dBm).
# A higher value indicates higher power. (internal only) see id: cc1101_rssi
rssi:
id: wmbus_cc1101_rssi
name: "${friendly_name} CC1101 RSSI"
filters:
- lambda: return min(max(2 * (x + 100.0), 0.0), 100.0);
unit_of_measurement: "%"
entity_category: "diagnostic"
state_class: "measurement"
icon: mdi:rss
# get the total watermter m3 from the wmbus telegram, log the timestamp
# for the last reading and calculates the statitics value
# and update all sensors: last_value, watercurrent, hour_value, daily_value
# week_value, month_value, year_value and watermeter_lastupdate
total_water_m3:
id: "waterdisplay"
name: "Wasseruhr Anzeige"
unit_of_measurement: "m³"
state_class: total_increasing
device_class: "water"
accuracy_decimals: 3
icon: mdi:counter
# Send the value periodically with the specified time interval.
# If the sensor value changes during the interval the interval will not reset.
# The last value of the sensor will be sent. 60s means, that every minute the
# last state will be published.
# The IZAR Watermeter will publish data all 8s (see transmit_period_s),
# but we need this only evers minute.
# filters:
# - heartbeat: 60s
# update and calulatet all watermeter sensor data values
on_value:
then:
- lambda: |-
if ((id(last_value) > 0.00) and (id(waterdisplay).state)>(id(last_value)) ) {
id(cc1101_state) = 2;
ESP_LOGI("wmbus", "Water Display value: %.3f, last value: %.3f", id(waterdisplay).state, id(last_value));
id(current_value) = float(id(waterdisplay).state-id(last_value)) * 1000.00;
id(watercurrent).publish_state(id(current_value));
id(hour_value)+=id(current_value);
id(waterhour).publish_state(id(hour_value));
id(daily_value)+=id(current_value);
id(waterday).publish_state(id(daily_value));
id(week_value)+=id(current_value);
id(waterweek).publish_state(id(week_value));
id(year_value)+=id(current_value);
id(wateryear).publish_state(id(year_value));
ESP_LOGD("wmbus", "Set current value to %.3f litre and publish the data", id(current_value));
if ( ${service_enabled} == true){
id(post_device_state).execute();
}else{
ESP_LOGD("wmbus", "Data Service to host disabled");
}
}else{
id(current_value) = 0.00;
id(cc1101_state) = 1;
id(watercurrent).publish_state(id(current_value));
ESP_LOGI("wmbus", "Reset current value to: %.3f, Waterdisplay value: %.3f, last value: %.3f", id(current_value), id(waterdisplay).state, id(last_value));
}
id(last_value)=id(waterdisplay).state;
# update the watermeter_lastupdate timestamp for the last waterdisplay state
- text_sensor.template.publish:
id: watermeter_lastupdate
state: !lambda return id(time_sntp).now().strftime("%Y-%m-%dT%H:%M:%S %Z");
# update watermeter_read_timeout the reading timeout for the watermeter display
- sensor.template.publish:
id: watermeter_read_timeout
state: !lambda |-
int time_used = ( millis() - id(send_millisecond) );
ESP_LOGD("wmbus", "Diff millisecond is: %d", time_used);
id(send_millisecond) = millis();
return float(time_used)/1000;
# update the watermeter status
- script.execute: set_status_message
# update the status led (statusled)
- binary_sensor.template.publish:
id: statusled
state: !lambda "return id(current_value) > 0;"
# water current month (wM-Bus v2.1.4)
current_month_total_water_l:
name: Wasser Monat
id: "watermonth"
accuracy_decimals: 2
unit_of_measurement: "L"
icon: mdi:water-outline
state_class: total_increasing
device_class: "water"
# get the last month total watermter m3 from the wmbus telegram (wM-Bus 2.1.10)
last_month_total_water_m3:
name: "Wasseruhr Anzeige letzter Monat"
id: "waterdisplay_lastmonth"
unit_of_measurement: "m³"
state_class: total_increasing
device_class: "water"
accuracy_decimals: 3
icon: mdi:counter
# get the battery life time (wM-Bus v2.1.4)
remaining_battery_life_y:
name: "Wasseruhr Batterielebensdauer"
id: "watermeter_batterie"
accuracy_decimals: 2
unit_of_measurement: "Jahre"
state_class: "measurement"
entity_category: "diagnostic"
icon: mdi:battery
# get the last transmit periode (wM-Bus v2.1.4)
transmit_period_s:
name: "Wasseruhr Update Intervall"
id: "watermeter_transmit_periode"
unit_of_measurement: "sec"
state_class: "measurement"
accuracy_decimals: 2
entity_category: "diagnostic"
icon: mdi:timelapse
## get the current watermeter alarms and publish the text message (wM-Bus 2.1.10)
## see: id: watermeter_alarm_message
current_alarms:
id: "watermeter_current_alarms"
name: "Wasseruhr Alarm Code"
entity_category: "diagnostic"
icon: mdi:message-alert-outline
on_value:
then:
- lambda: |-
int error_code = int(x);
std::string message = "";
if(error_code==0){
message = id(alarm_error_text)[error_code];
id(watermeter_alarm_message).publish_state(message);
ESP_LOGD("wmbus", "Alarm message: %s, error code: %d", message, error_code);
}else{
for (int i = 1; i < 10; ++i) {
if (error_code & (1 << i)) {
if (!message.empty()) {
message += ", ";
}
message += id(alarm_error_text)[i];
}
}
id(watermeter_alarm_message).publish_state(message);
ESP_LOGW("wmbus", "WARNING Alarm message: %s, error code: %d", message.c_str(), error_code);
id(watermeter_alarm_timestamp).publish_state(id(time_sntp).now().strftime("%Y-%m-%dT%H:%M:%S %Z").c_str());
}
## get the prevois watermeter alarms and publish the text message (wM-Bus 2.1.10)
## see: id: watermeter_alarm_perv_message
previous_alarms:
id: "watermeter_previous_alarms"
name: "Wasseruhr Alarm Code voriger"
icon: mdi:message-alert
entity_category: "diagnostic"
on_value:
then:
- lambda: |-
int error_code = int(x);
std::string message = "";
if(error_code==0){
message = id(alarm_error_text)[error_code];
id(watermeter_alarm_message).publish_state(message);
ESP_LOGD("wmbus", "Alarm message: %s, error code: %d", message, error_code);
}else{
for (int i = 1; i < 10; ++i) {
if (error_code & (1 << i)) {
if (!message.empty()) {
message += ", ";
}
message += id(alarm_error_text)[i];
}
}
ESP_LOGW("wmbus", "WARNING Alarm message: %s, error code: %d", message.c_str(), error_code);
id(watermeter_alarm_timestamp).publish_state(id(time_sntp).now().strftime("%Y-%m-%dT%H:%M:%S %Z").c_str());
}
id(watermeter_alarm_perv_message).publish_state(message);
if(id(watermeter_alarm_timestamp).has_state() == false) {
id(watermeter_alarm_timestamp).publish_state("--");
}
# water current (updated by id: "waterdisplay")
- platform: template
name: Wasser Aktuell
id: "watercurrent"
accuracy_decimals: 2
unit_of_measurement: "L"
icon: mdi:water-well
state_class: "measurement"
device_class: "water"
lambda: return (id(current_value));
# water current hour (updated by id: "waterdisplay")
- platform: template
name: Wasser Stunde
id: "waterhour"
accuracy_decimals: 2
unit_of_measurement: "L"
icon: mdi:water-well-outline
state_class: total_increasing
device_class: "water"
lambda: return (id(hour_value));
# water today (updated by id: "waterdisplay")
- platform: template
name: Wasser Tag
id: "waterday"
accuracy_decimals: 2
unit_of_measurement: "L"
icon: mdi:water-well-outline
device_class: "water"
state_class: total_increasing
lambda: return (id(daily_value));
# water yesterday (updated by id: "waterdisplay")
- platform: template
name: Wasser Gestern
id: "wateryesterday"
accuracy_decimals: 2
unit_of_measurement: "L"
icon: mdi:water-well-outline
device_class: "water"
state_class: total_increasing
lambda: return (id(yesterday_value));
# water current week (updated by id: "waterdisplay")
- platform: template
name: Wasser Woche
id: "waterweek"
accuracy_decimals: 2
unit_of_measurement: "L"
icon: mdi:water-well-outline
device_class: "water"
state_class: total_increasing
lambda: return (id(week_value));
# water last month (updated by id: "waterdisplay")
- platform: template
name: Wasser letzer Monat
id: "waterlastmonth"
accuracy_decimals: 2
unit_of_measurement: "L"
state_class: total_increasing
device_class: "water"
lambda: return (id(lastmonth_value));
# water current year (updated by id: "waterdisplay")
- platform: template
name: Wasser Jahr
id: "wateryear"
accuracy_decimals: 2
unit_of_measurement: "L"
state_class: total_increasing
device_class: "water"
lambda: return (id(year_value));
# service call delay (updated by id: "waterdisplay")
- platform: template
name: Wasseruhr Daten Intervall
id: watermeter_read_timeout
icon: mdi:clock-start
accuracy_decimals: 2
unit_of_measurement: "sec"
state_class: "measurement"
entity_category: "diagnostic"
# Wifi quality RSSI (%)
- platform: wifi_signal
name: "${friendly_name} WLAN Signal"
id: wifi_signal_db
update_interval: 60s
filters:
- lambda: return min(max(2 * (x + 100.0), 0.0), 100.0);
entity_category: "diagnostic"
unit_of_measurement: "%"
# device internal temperature (only webview)
- platform: internal_temperature
name: Device Internal Temperature
id: device_internal_temperature
icon: mdi:thermometer-lines
state_class: "measurement"
update_interval: 60s
entity_category: "diagnostic"
disabled_by_default: true
# the current size of free heap memory.
- platform: template
name: ${friendly_name} Free Heap Min
id: sysfreemapmin
icon: mdi:counter
lambda: return {static_cast<float>(esp_get_minimum_free_heap_size())};
unit_of_measurement: B
update_interval: 2s
entity_category: "diagnostic"
# Minimum free heap ever available
- platform: template
name: ${friendly_name} Free Heap
id: sysfreeheap
icon: mdi:counter
lambda: return {static_cast<float>(esp_get_free_heap_size())};
unit_of_measurement: B
update_interval: 2s
entity_category: "diagnostic"
# Free memory
- platform: template
name: "${friendly_name} - Free Memory"
# lambda: return heap_caps_get_free_size(MALLOC_CAP_INTERNAL) / 1024;