I’ve got an ESP32 and a reed sensor, with which I can count rotations of my water meter, using a pulse_counter. With it, I assume I can keep track of the total pulses, as well as the amount of pulses per minute.
I still have to figure out how many rotations go into a liter, but I assume 2-4. That means that the amount of pulses needs to be divided by some integer, and the result will most likely be a float, rather than an integer. And why not keep track of the amount of pulses as well? The more data, the merrier.
But I can’t figure out how to use the sensor values and calculate them, and then publish those calculated values as well. I thought numbers might do the trick. But then it turns out you can’t use number without a template. And you can’t use a template number without max_value. But a maximum value makes no sense on a water meter, which will obviously only increment its value.
And how can I get the sensor values into those numbers…?
This is what I have so far:
sensor:
- platform: pulse_counter
pin:
number: 14
inverted: true
mode:
input: true
pullup: true
name: watermeter_pulsering_per_minuut
id: watermeter_pulsering_per_minuut
update_interval: 1s
total:
name: watermeter_totaal_aantal_pulseringen
id: watermeter_totaal_aantal_pulseringen
I would like to add two floats:
watermeter_verbruik_per_minuut= the value ofwatermeter_pulsering_per_minuutdivided by 4 (let’s say)watermeter_totaal_verbruik= = the value ofwatermeter_totaal_aantal_pulseringendivided by 4 (let’s say)
I tried something like this:
number:
- platform: template
name: watermeter_verbruik_per_minuut
id: watermeter_verbruik_per_minuut
update_interval: 1s
entity_category: ''
device_class: volume_flow_rate
unit_of_measurement: L/min
lambda: |-
return id(watermeter_pulsering_per_minuut).state/4;
- platform: template
name: watermeter_totaal_verbruik
id: watermeter_totaal_verbruik
update_interval: 1s
entity_category: state
device_class: water
unit_of_measurement: L
lambda: |-
return id(watermeter_totaal_aantal_pulseringen).state/4;
But then the compiler complained about the missing max_value… I suppose I can set that to an unrealistically high integer, but I assume there’s a better way?
Thanks in advance for everyone’s help!
