I have currently the issue, that when the ESP32 is restarted, that the state of the gas count from before the restart is not restored from flash although I set it in the configuration. The state after a reboot is always set back to the initial value I set in the config.
This is annoying as my statistics in Home Assistant are showing wrong results after a reboot with a negativ amount of gas consumption. As far as I understand the configuration, the ESP32 always sends the total value of the gas meter and Home Assistant consumes this.
Would it be better, if the ESP32 only sends a pulse and the counting is done in Home Assistant? If this would be done via MQTT, it would be also work when there are networking issues as counting counting continues when everything is back.
Does anybody know if there is another setup based on this logic? I did not find one so far. Or do I miss something why such a setup wouldnât be better?
EDIT: Read one answer below before bothering with this stuff, Ben solved my stuff with his answer. If you still want an answer to the initial question, read on.
Hi
i posted a similar request today (the topic just before this one) and i might have a solution for you, solving my problem, too.
My gas meter sensor is a D1 mini (ESP6288) running Tasmota and i was using roughly this approach. Since i had the same problems like you, i altered the thing like this:
Tasmota Configuration: (try something similar in ESPhome probably)
So instead of configuring D7 as a counter like suggested in the link above i set it up as Switch. Also i set âSwitchMode 13â and âCounterDebounce 500â on Tasmota console. As a result Tasmota sends only âONâ statements via MQTT every time the reed sensor is activated, no âOFFâ or other statements.
EDIT: âSwitchRetain 1â might be a good idea, too.
HA configuration:
I made a new helper counter (using UI) named gas_counter, no min/max, starting value 0, youcan use a different starting value of course.
The counter is increased by an automation fetching MQTT data:
Do you have it defined as âtotal_increasingâ? If so, HA should ignore negative adjustments and only consider when itâs increased. Thatâs how my utility values are setup and Iâve never had an issue when they reset after a power-cycle.