HowTo? Re/Set Riemann integration?

Hi,

base on the new energy integration I use the “Riemann sum integral” integration to calulate time based kWh based on Watt pulses.

While configuring all, I defined some inputs the wrong way, so the “Riemann sum” explodes in very large number.

I will not use the “utility meter” to reset the value, because I will fix it.

Using set state will be overwritten by the running integration instance.
Also disalbe the integration (remove the entry from configuration.yaml) → restating HA → delete all entries from database (states and statistic tables) → add the integration → restarting HA again - ends up with the same invalid value :(. Where it comes from?

The sensor.py source code unsing
state = await self.async_get_last_state()
but I dont know how to minipulate that or the internal
self._state.

Also I will fix the state by time, if the Riemann sum runs out of sync with my
electricity meter.

Thx

1 Like

Answer found here:

  • ssh to home asstant
  • ha core stop
  • edit /config/.storage/core.restore_state
  • ha core start

Reason:
The sensor read the last state on startup and polling / overwriting it sometimes.
Also the RestoreState class writes all state known states down on tear down / ha stop.

If you overwrite a state via the states dev tool or the API, it will not impact the actual device. If the device state is being polled, it will overwrite the state in the state machine the next polling.

4 Likes

@cku, I’d just like to publicly thank you for sharing that awesome 4-step approach to changing a stored value. I want you to know that I’ve favorited your post and I have referred back to it two or three times now in the last couple of years and plan to continue referring to it into the future – I can’t seem to remember these steps. :stuck_out_tongue: