i have a template sensor and want to prevent peaks.
For that reason i had the idea to only update the sensor, when the difference before and now is not that high.
It is for my Smart Meter, so the kWh can be only growing. But for some reason my sensor send sometimes peaks with really high kWh or minus kWh which cannot be real.
So my idea was to make state for the sensor, that the sensor only updates when the difference is lower than 1kWh.
Any ideas how i can do that?
This is my Template Sensor
Trigger off state changes, work out the difference between trigger.to_state.state and trigger.from_state.state. If you want to reject the new value, set the sensor to this.state for no change.
Thinking about it further, you don’t actually need a trigger. I was thinking you would need to compare the previous and new values of your smart meter sensor, but you don’t — you just need to compare against your template sensor. Something like this:
Template says “if the absolute difference between this sensor’s existing value and the incoming smart meter sensor is greater than 1kWh, keep the prior value; otherwise update to the smart meter value”.
Might do some odd things at startup. If the smart meter sensor is unknown, then the |float(0) substitutes in 0 as the value to use.