I do not understand why the filter sensor is not updated when the source sensor is. I have defined a time_date sensor. I would expect the filter to update every time the source sensor is updated. Is that an incorrect expectation? This is a moving window but I have also tried it with lowpass with same behaviour. The system has been running for a while since last restart and I can see delays of over 30 mins sometimes.
Just trying to smooth some temperatures. I could do it in Node-Red but if the filter but if the filter sensor has a problem that should be raised as an issue.
I donât think itâs a problem⊠have you tried to set the filterâs log level to debug and see what itâs doing?
The reason your filtered state is not updated is because it hasnât changed.
It hasnât changed because of the filterâs configuration - it looks at previous value(s) and calculates the current one and pushes it as a new one but if itâs the same as the state machine has, you wonât see any change because thatâs the way HA works (unless you force_update).
So you need to find a way to configure your filter(s) so they work as you want.
I had an issue with âspikesâ in my room temperatureâs readings and tried filter with no satisfactory outcome.
Ended up creating a custom jitter_filter and my hair temperature graph is much smoother now
EDIT: And my last piece of advice, if the temperature hasnât changed on the main device, a record is not created in the database. If the record doesnât get created, you wonât see a change on the filtered device. That coupled with a low number of samples in the 5 minute window, you may end up with results that only update periodically. Especially if the temperature doesnât change much.
I think Iâll post it in Share your project one day but need time to at least a) upload it to Github and b) write readme.md as it has some more features compared to ordinary sensors - for example, I can dynamically change its attributes (like window_size etc) without restarting HA so a clever automation can adjust the filtering process depends on some factors.
The main thing is itâs designed for sensors that send their states regularly like my temperature sensors (every 50s).
I am in a similar situation. I have a sensor that reports either 0 or 100 values. But when it is flipping from one value to another, it is flipping between the two for 5 minutes or so until it gets stable.
I wanted to write a filter sensor that would smooth out the period when it is flipping back and forth. The filter sensor works correctly until the original sensor flips the last time. After that the filter sensor is not updated anymore and the filter value is stuck.
Just ran into the same issue. The filter component is completely broken. As it only updates when the source data actually changes, it canât deal with stable source data and will get stuck on its last (incorrect) value as soon as the source stabilizes. The only situation where it doesnât generate incorrect values is when the source is guaranteed to constantly change (basically like noise).
Iâm trying to lowpass filter wind speed data. As soon as there is no wind anymore (source value is 0), the filtered value gets stuck on its last value, even if itâs hours / days old. Is there any way to trigger an update of the filter value manually or through an automation, say every n minutes ? Calling update_entity does not work with the filter component, itâs simply ignored.
I ended up ditching the filter sensor. I rewrote the filter myself and integrated it directly into the firmware of the MCU that provides the data. So it now provides the prefiltered data directly to HA.
Another alternative is to use an automation with a time trigger, firing maybe every 5 minutes, that will do the filtering and write the result into an input_number. I did this for a trend filter for atmospheric pressure and it works well. I used pyscript to do it, as it provides persistent storage for intermediate values.
It wouldnât be too helpful, as it has tons of dependencies and wonât work on its own. But at the core itâs just a simple time trigger. It will process the value at regular intervals even if it didnât change, so the filtered results will be correct. Rough example with a very simple exponential lowpass:
@time_trigger("period(now+10s, 5m)")
def process_filter():
a = sensor.raw_value
b = input_number.filtered_value
w = 0.1
input_number.filtered_value = a * w + b * (1 - w)
To make it robust, you need to add code handling situations where your sensor is unavailable, etc.
Is there still no general solution? It would be great if there was an option to use the last value in the window instead of the first.
In my case it is power consumtion of a heater (orange) that apears to use more power than it actually does.
(White is general power consumtion of all devices.)
You can write an automation to update the sensor when the source isnât changing using the homeassistant.update_entity service. Slap a timepattern trigger on that and youâll have a consistent update frequency on any entity you supply to the homeassistant.update_entity service.
Unless they fixed that since, last time I tried the filter sensor will simply ignore calls to update_entity. Thatâs why I eventually turned to using the pyscript (see snippet above) to do my own filtering.