I have a rain gauge hooked up to a D1mini. When there is “enough” rain collected it swings over and a pin is shortly pulled high on the D1mini. Integrated with ESPhome I have a binary sensor that is called binary_sensor.rain_pulse
To calculate the amount of rain falling per minute I have the following code:
- platform: template
sensors:
rain_pulse:
friendly_name: Rain Pulse
value_template: >-
{% if is_state('binary_sensor.rain_pulse', 'on') %}
1
{% elif is_state('binary_sensor.rain_pulse', 'off') %}
0
{% else %}
0
{% endif %}
- platform: statistics
entity_id: sensor.rain_pulse
precision: 0
name: rain_gauge_pulse_1
state_characteristic: count
sampling_size: 120
max_age:
minutes: 1
- platform: template
sensors:
rain_1:
friendly_name: Rain 1 minute
unit_of_measurement: 'mm'
value_template: >-
{{ (states("sensor.rain_gauge_pulse_1")) |float /2 * 0.367 }}
result: if there was rain enough to measure 0.367mm of rain in the last minute the sensor outputs 0.37 if there was enough rain to do to measure twice in the last minute it outputs 0.73 and so on and on.
My issue is however that when templates are reloaded (now via developer tools > yaml > YAML configuration reloading > template entities) or at reboot, the sensor output is 0,18. (half of the 0.367 rounded to 2 decimals.)
I understand what the issue is, going from “unavailable” to “0” is counted and calculated with /2 * 0.367
I… ehm… just don’t know how to fix it…
Does anyone have the brilliance to make me feel dumb and fix this? Much appreciated!
1 post - 1 participant