Why does this statistics sensor have an unknown state?

Can’t get my brain around this… My statistics sensor shows state ‘unknown’ a few minutes after the source sensor hits zero and stays there. The statistics sensor should remain at 0 imho. Instead it turns ‘unknown’.

Source sensor:
image

Statistics sensor:

YAML:

- platform: statistics
    name: wind_kph_avg
    entity_id: sensor.pws_wind_speed
    sampling_size: 3
    # max_age:
    #   minutes: 7

Tried both with and without max_age. Doesn’t seem to make a difference. Right now, the count stays at 0 and state remains unknown. The statistics sensor doesn’t seem to pick up the state changes, not even when I change the state around manually.

Any hints? I’m lost…

Same issue here…

Might be worthy to raise an issue on Github.

1 Like

done here Statistics sensor does not always check sensor availability · Issue #58748 · home-assistant/core · GitHub

In all the examples you posted there are no samples to calculate stats from (count = 0) so the sensor has to have an unknown state,

Changing the wind sensor state manually?

It would need at least two changes to be able to calculate the stats.

Thanks for your response @tom_l. Triggered by your input, I did some more testing. Can you educate me here? I seem to be missing something.

  1. Created input_number.statistics_test:
  statistics_test:
    name: 'Statistics test number'
    min: 0
    max: 99999
  1. Created a statistics sensor like this:
  - platform: statistics
    name: 'Test statistics sensor'
    entity_id: input_number.statistics_test
    sampling_size: 3
  1. Using Development Tools > Service input_number.set_value - I changed the number 5x with some random integers.
    Resulting in: state ‘unknown’ and count remains at 0.

In my mind, the statistics sensor should pick up the value changes, it doesn’t so this is a bug? Am I missing something?

same problem here. The documentation seems to lack in order to explain what is going on. Also tried with both max_age and samplig_size, same problem

Just in case someone else stumbles across this issue:

If your data comes from an MQTT sensor, then update your config to include the following line:

force_update: true

The statistics engine then has data to work with.

There is a feature request for this, also a workaround is described:

(have not tried it myself yet)

2 Likes

I have a luminance sensor connected via Zigbee2mqtt that is having this “unknown” state problem. I’m not sure where and in what file your parameter needs to be added.

For me, because my sensor entity (wind speed) was coming from RTL433, the force_update setting was configured in the RTL433 Auto Discovery add-on. I’m not sure if you can configure this for Zigbee2MQTT. I checked for you, but I don’t see an option right away.

I am having the same problem. It seems that a zero is not considered as a “valid” value.

Okay your question is a year old. But knowledge can never be too late…

In this topic (scroll to the bottom) they are talking about how to setup force_update for Zigbee2MQTT entities: Is it possible to force Zigbee2Mqtt to trigger state_changed (or similar) even if sensor value did not changed? - #9 by ldoppea