I already have a MQTT sensor that gives me the current kWh used within current hour. This sensor is reset to 0 on every hour. My power meter reports data every 2.5 seconds, so the last value can be received few seconds after the hour has ended.
The problem is that when the device that sends the MQTT message restarts the kWh is reset to 0. This can happen for instance 25 minutes past the hour, which will mess up my automations and calculations.
Below is a screenshot of the issue. At 9:43 the sensor is reset to 0.
What I want to achieve, and some help in how to do this, as I’m a bit new to HA, is to create a new sensor that mitigate that the value resets during an hour.
- I probably need to store current value as previous_value (Do I use Input Text integration for this?)
- If current value is lower than previous value and current hour minute is larger than zero add current value + previous_value and store this as the new previous value. Keep doing this until current minute is 0, and current value is between 0 and 0.01.
Does this sounds like a good plan? The problem is that I don’t know how to configure this in HA.