Hi, I have a watermeter pulse counter which I created a while ago. Now when I restart the ESP I have to manually (re)set the measured value. It goes back to the initial value which it was set to before and looses the counted values during last runtime. This is the relevant config.
how can I get the counted value also after reset or power failure (I take the risk of loosing pulses during power failures since I can manually call the service after that.
Via HA: # HA - Developer Tools - Services - ESPHome: meter_water - set value with point
api:
services:
- service: meter_water
variables:
meter_value: float
then:
- globals.set:
id: totalWaterUsage
value: !lambda "return ( meter_value ) ;"
# HA - Developer Tools - Services - ESPHome: meter_water - set value with point
globals:
- id: totalWaterUsage
type: float
restore_value: yes
sensor:
#------------------------# Watermeter #------------------------#
- platform: template
name: "Water Consumption Now"
id: watermeter_flow
accuracy_decimals: 1
unit_of_measurement: "L/min"
icon: "mdi:water"
lambda: return (id(watermeter_pulse).state);
update_interval: 2s
# watermeter pulses #
- platform: pulse_meter
pin:
number: GPIO21
inverted: true
mode:
input: true
pullup: true
id: watermeter_pulse
name: "Watermeter Pulse"
state_class: measurement
accuracy_decimals: 1
internal: true
internal_filter_mode: PULSE
timeout: 10s
# WaterMeter Total - m3 #
total:
id: sensor_pulse_meter_total
name: "Watermeter Total (since start ESP)"
icon: "mdi:cube-outline"
state_class: "total_increasing"
unit_of_measurement: "m3"
accuracy_decimals: 3
filters:
- multiply: 0.001
internal: true
- platform: template
id: watermeter_total
name: "Watermeter Value"
state_class: "total_increasing"
icon: "mdi:cube-outline"
update_interval: 1s
unit_of_measurement: "m3"
accuracy_decimals: 3
lambda:
return id(totalWaterUsage) + id(sensor_pulse_meter_total).state;
time:
- platform: homeassistant
id: homeassistant_time