Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Time Simple Moving Average shows wrong state when the input sensor doesn't change state #57337

Closed
hk-ret opened this issue Oct 8, 2021 · 7 comments

Comments

@hk-ret
Copy link

hk-ret commented Oct 8, 2021

The problem

If a sensor doesn't change its state for a longer time (e.g. power produced by a solar panel during the night) the moving average filter remains at the state it had the last time the sensor changed. Only when a new change happens from the sensor the filtered state jumps to the value of the sensor during the 'static period'.

grafik

What is version of Home Assistant Core has the issue?

core-2021.9.7

What was the last working version of Home Assistant Core?

No response

What type of installation are you running?

Home Assistant Core

Integration causing the issue

Filter Sensor

Link to integration documentation on our website

https://www.home-assistant.io/integrations/filter/#time-simple-moving-average

Example YAML snippet

sensor:
  - { platform: simulated, name: test_sim, period: 3600, spread: 0.1 }
  - { platform: filter, name: test_sim_rng, entity_id: sensor.test_sim,
      filters: [{ filter: range, lower_bound: -0.2 }],
    }
  - { platform: filter, name: test_sim_sma, entity_id: sensor.test_sim_rng,
      filters: [{ filter: time_simple_moving_average, window_size: "00:10" }],
    }

Anything in the logs that might be useful for us?

see pic above

Additional information

the filtered state should be updated after some time if there is no change of input state.

@probot-home-assistant
Copy link

filter documentation
filter source
(message by IssueLinks)

@probot-home-assistant
Copy link

Hey there @dgomes, mind taking a look at this issue as it has been labeled with an integration (filter) you are listed as a code owner for? Thanks!
(message by CodeOwnersMention)

@Danielhiversen
Copy link
Member

I think it works as intended.
I have a plan to add another filter that works as you (and me) expect: #53053

@dgomes
Copy link
Contributor

dgomes commented Oct 8, 2021

@Danielhiversen is absolutely right, hope he can finish that PR 😉

@hk-ret
Copy link
Author

hk-ret commented Oct 8, 2021

EDIT: Please disregard my answer below. I see that #53053 addresses this issue. However I think IMO this should not be a new feature but a bugfix.

If it works as intended depends on the intention😉. As I understand the referenced paper the time-SMA is the average of values during a certain period weighting each observation value by the amount of time it remained unchanged. This amount changes over time for the first and last observation and observations fall out of this period over time as well. If the observed value does not change anymore the average will approach the last observation more and more. If the observed value has not changed for longer than the observation period, the average si identical to the last value.

Therefor the time SMA filter must not only change when there is a new observation but continuously (or periodically) over time.

@dgomes
Copy link
Contributor

dgomes commented Oct 8, 2021

The big difference is what triggers an update: a new event from the source, or a time event (clock).

#53053 is the right direction (new filter) as the current implementation already reflects many users needs.

@hk-ret
Copy link
Author

hk-ret commented Oct 8, 2021

I agree that it might be unfortunate for users already using this filter. I suggest that the documentation is updated to indicate the he existing filter is somewhat a mixture between the rolling average (based on observation events) end the time-SMA (based on state duration). The new filter would then be a proper implementation of the algorithm described in the referenced Eckner paper.

@github-actions github-actions bot added the stale label Nov 7, 2021
@github-actions github-actions bot locked and limited conversation to collaborators Dec 14, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

3 participants