-
-
Notifications
You must be signed in to change notification settings - Fork 32.3k
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
Statistics sensor not counting 0 #19800
Comments
I think this also affects statistics for non-binary sensors. I've got a DHT temperature sensor hooked up and I'd like to display some stats for it, mainly the change in temperature over the past 5 minutes. - platform: dht
sensor: AM2302
pin: 23
monitored_conditions:
- temperature
- platform: statistics
name: Temperature Stats
entity_id: sensor.dht_sensor_temperature
sampling_size: 12
max_age:
minutes: 5 The temperature sensor itself updates every 30 seconds, but the temperature readings don't change very often. When I look at the statistics sensor, it only ever collects 1-2 samples in the 5 minute window ( This prevents the statistics sensor from calculating Perhaps some kind of |
Is this still an issue you are experiencing? Can you please try upgrading to the latest version of Home Assistant (0.90) and report back if this is still a problem? Thanks! |
@alex-gh I can confirm this is still an issue on 0.90.1 |
I think I found the reason for this however I am not directly sure how to solve it. I have a setup with a MQTT switch and sensor where the sensor shows power consumption and only get updated if there is a change. So if I turn off the switch, power consumption goes to 0. In this moment, the statistics component calculates and the value lowers. But as there are no state change events afterwards (0 stays 0 after all), the component does not get triggered and therefore doesn't update. So when using max_date, the sensor needs an additional time-based listener (or similar) that automatically refreshes at a certain interval. Not sure if this is even possible though or if there is a workaround e.g. using an automation (as sensors don't have services that could be triggered) |
Any developments on this, I hate the clunky way I've got it implemented at the moment. |
Just bumping this again. Is this the intended behaviour or a bug? |
also having this issue with the binary sensor. I use a binary sensor for my water meter (with line tracking sensor) and the statistics sensor keeps a count with max_age 1 min so I can see the used liter/min. In the current situation the sensor does not reset to 0 but it will stay on the last value. So e.g. when I use 10 liter and nothing after that, then it will stay on 10 as if I was using 10 liter/min all the time. |
I thought I'd give it a try to fix this by adding scheduled updates if However, I've run into the following issue: If there are no state changes anymore, the scheduled update after @tungmeister: I guess the above change would work for your particular use-case. @mickdekkers: I think your use-case is a bit different. If the sensor you are monitoring does not change its state, i.e. the value does not change and the sensor does not force update its value, then I don't know how the statistics sensor can help you here. The statistics sensor listens for state changes recorded in the the HA state machine, but if the monitored sensor does not record a change, then there is not much we can do I'm afraid. @rikroe: I'm unsure of the above scheduled update would help in your case. If you are monitoring a sensor that captures power consumption, and if at some point this sensor turns to @Westenberg: I understand you have a binary sensor that if |
@exxamalte Will this change be in the next release and is there a commit I can try? |
I've just pushed a branch with that commit: exxamalte@db1ef8f At the moment I am a bit unsure if the risk of this change ("breaking change" potential) outweighs the benefit. Hence I was asking for feedback. |
I'll test it later today |
I will test as well, although I'm not sure I'll get it done today. For me your implementation (the value going to 0 or unkown) should be fine, basically I want to check on |
Tested, it works now for my use case. After the defined I just wondered if it is also possible to define some refresh interval (e.g. in Nevertheless, thanks for your enhancement @exxamalte 🎉 It makes this sensor much better! |
Thanks for the feedback, @rikroe. |
@rikroe: I have made one more change to this: Instead of waiting the whole If you get a chance, could you please try the latest changes of the statistics sensor? |
@exxamalte sorry for the late response. Thanks, your solution fixed my issue! Looking forward to the update! |
Home assistant: 84.6
I've got a statistics sensor setup as below:
I would expect this to show the count for the binary sensor from the last 2 seconds and then return to 0 if the sensor doesn't change in the next 2 seconds. Rather than this the count always shows the last recorded value e.g. 1 or 2 and will only change when new values are recorded rather than the absence of values.
The text was updated successfully, but these errors were encountered: