Help with statistics sensor

I am trying to add a statistics sensor to normalize a sensor that gets updated about every minute. I would like to get a mean, as well as 24h min/max values.

It’s sensor that shows the current price of Dogecoin.

Seems pretty straightforward, however it’s not working. What am I doing wrong here?

sensor:
  platform: statistics
  name: Dogecoin Statistics
  entity_id: sensor.dogecoin
  sampling_size: 1500

does sensor.dogecoin have any state and history? Have you excluded it from History?

I have a history and the recorder includes all my sensors, too

Did you try adding

    max_age:
      hours: 24

Yes, I had that originally. Tried removing it for simplicity. It’s like the stat sensor doesn’t see the reference sensor values.

Sounds like there is a typo somewhere.
Can you show us the config of the dogecoin sensor?

sensor:
  platform: cryptostate
  resources:
      #Example of the first formula
    - compare: doge-eur
      name: dogecoin

It’s from a custom component
https://github-dotcom.gateway.web.tr/PepegaBruh/CryptoTracker

Looking in Developer Tools / States, what is the actual entity id and state of your dogecoin sensor?

I had the idea, the value might actually be a string not a number, but it is.

States are always strings. That’s not the issue.

I’m not sure what is. Looks like you have the correct configuration for the statistics sensor. Correct sampling size as well. It’s just not getting any samples. When was the last time sensor.dogecoin updated?

Try this in the template editor:

{{ relative_time(states.sensor.dogecoin.last_changed) }}

EDIT:

Does this only appear once in your configuration:

sensor:

And do you have other sensors under it?

If so you need to make the sensor configuration a list item with -

sensor:
  - platform: statistics
    name: Dogecoin Statistics
    entity_id: sensor.dogecoin
    sampling_size: 1500

  - platform: some_other_sensor...

At least one statistic sensor :wink:

1 Like

image

I use the system by Frenck (I believe), where I have a single file for each sensor. I have lots and it works, that shouldn’t be the issue here.

Ok so the sensor is updating and the config is correct, that just leaves the way you have split your config.

I really don’t think so, but I’ll try to rule it out.

This is my configuration.yaml. I added the sensor on the bottom. I haven’t used any other style of configuration in a while. This should work, shouldn’t it?

#
# The configuration.yaml is only used to bootstrap the system.
#
homeassistant:
  # Load packages
  packages: !include_dir_named integrations


# Configure a default setup of Home Assistant (frontend, api, etc)
default_config:

# Uncomment this if you are using SSL/TLS, running in Docker container, etc.
# http:
#   base_url: example.duckdns.org:8123

# Text to speech
tts:
  - platform: google_translate

group: !include groups.yaml
automation: !include automations.yaml
script: !include scripts.yaml
scene: !include scenes.yaml

sensor:
  - platform: statistics
    name: Dogecoin Statistics neu
    entity_id: sensor.dogecoin
    sampling_size: 1500
    max_age:
      hours: 24

No. Where is the sensor.dogecoin sensor that the statistics sensor is using?

Alrighty. I removed both sensors from my main config and added them here:

#
# The configuration.yaml is only used to bootstrap the system.
#
homeassistant:
  # Load packages
  packages: !include_dir_named integrations


# Configure a default setup of Home Assistant (frontend, api, etc)
default_config:

# Uncomment this if you are using SSL/TLS, running in Docker container, etc.
# http:
#   base_url: example.duckdns.org:8123

# Text to speech
tts:
  - platform: google_translate

group: !include groups.yaml
automation: !include automations.yaml
script: !include scripts.yaml
scene: !include scenes.yaml

sensor:
  - platform: cryptostate
    resources:
        #Example of the first formula
      - compare: doge-eur
        name: dogecoin
  - platform: statistics
    name: Dogecoin Statistics
    entity_id: sensor.dogecoin
    sampling_size: 1500
    max_age:
      hours: 24

I’ll wait a bit, if any updates show up in the statistics sensor.

The statistics sensor should update as soon as it has two samples from sensor.dogecoin.

Well, that was unexpected. It worked, the sensor has data now.

I really do not understand why, though. I have about 100 sensors with varying platforms set up this way. Have never had an issue. Maybe there was still a typo somewhere? I’m confused now.

I think I found the issue.

I did not restart Home Assistant after adding the statistics sensor to my configuration. I only clicked the reload button in the Server settings. There was no error and the sensor appeared afterwards.

But when I changed my configuration.yaml earlier, I did a full restart (just to be sure) and the sensor appeared.

I just returned to my original configuration and did a full restart. The statistics sensor works now.

This is probably a bug in Home Assistant, isn’t it?

Anyway, thanks for debugging this with me @DavidFW1960 @Hellis81 and @tom_l ! I wouldn’t have found the issue otherwise!

1 Like

No. That is as expected.
All configuration.yaml changes needs a restart