Limych / ha-average

Average Sensor for Home Assistant

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Avoid that unavailable and unknown values are used to make average.

Melkor82 opened this issue · comments

commented

Environment

  • Home Assistant Core release with the issue:
  • This custom component release with the issue:
  • Last working this custom component release (if known):
  • Operating environment (Home Assistant/Supervisor/Docker/venv):

Describe the bug
I use the average sensor to calculate average temperature in the house. I am using 6 zigbee sensor. If the battery of one gets
low it disconnects and it reports unavailable or unknown as state. I can notice this as the average value drops because i think
that the value is used to make the average is 0.

Configuration.yaml

Add your configs here if any.

Steps to Reproduce
Just make one sensor states to report "unavailable" or "unknown"

Expected behavior

Ignore "unavailable" and "unknown" states of the sensors

Debug log


Add your logs here.

Additional context

Came here to report this; I now have millions of logs from this component because it can't find the average for an unknown or unavailable entity id.

Hi. Even though in the documentation is stated that: "By default, undefined values are not included in the average calculation" upon HA core restart i get low and zero values:
image

I believe this happens because the availability of the sensors. It also causes issues with other entities that use the average sensor as input:
image

For me it seems that this started when I updated HA from 2021.12.2 to 2021.12.8. At least for me this hasn't happened before that upgrade. Upgraded Average to 2.2.1 didn't help.

image

  - platform: average
    name: 'Average Temperature House'
    unique_id: __legacy__
    duration:
      minutes: 30
    entities:
      - sensor.kitchen_ble_temperature
      - sensor.guestroom_ble_temperature
      - sensor.livingroom_ble_temperature
      - sensor.xiaomi_temp_childrensroom_temperature

As you can see from the picture all entities are between 20.9 and 22.6, and still average is 16.26. One of those sensors is offline since 10:10. But that big drop happened at 11:05.

I would assume that one sensor would be ruled out as it has happened before. Could you please check into this?

Edit:
Added second average to verify my findings. Second average is with same setup but without livingroom_ble_temperature sensor. All other details are same, except this one calculates average without that one failed sensor. This one calculates average correctly. So ruling out bad sensors doesn't work as it supposed to.
image

Any update on this one? I'm currently using built-in mean calculation instead of this, because it can handle missing values just fine. But it obviously isn't as versatile as this. And it doesn't calculate average during some time period. That's why I would like to use this component instead.

I think the restart related part of this issue is related to #98. Though I wasn't able to figure out the root cause.

I'm having the same problem.
When a sensor becomes unavailable, the average value is wrong, considering the value as 0 instead of ignoring it

commented

Same here, I see problem still open

commented

I switched to the native HA average sensor in the helpers page. It is behaving as supposed

Though the built-in HA integrations behave differently, eg. they go unavailable immediately after the sensor goes unavailable (eg. WiFi outage), and generic_thermostat will not change state on unavailable temperature.

In my case I've added a wrapper sensor to get a default value for the thermostat, and I use the built-in filter (average) integration sensor to draw graphs (without the jumps to the default temperature). See: https://community.home-assistant.io/t/average-sensor/111674/154

Same issue here, an undefined value drops the average.