Statistics sensors - too complicated?

Hello everybody,

I’ve been playing around with my sensors and added a statistics sensor for one of my temperature sensors. After that, I’ve created three additional sensors, monitoring min, max and mean of the last 24 hours, but it is somehow not working as I would expect it to.

The green line is showing what the physical sensor actually recorded and the yellow dots should mark the maximum value of the latest 24 hours. The first max has been recorded at 20:52h having 23,59°C. The next value is 24 hours and 17 minutes later showing 23,52°C and then at 22:09h a max of 23,33°C.

Doing the math seems to be quite simple and I would have expected to see the curve dropping constantly exactly 24 hours after the max has been reached at 20:52h the day before.

Any idea of what I miss?


next time post your config (yaml files) :roll_eyes:

Thank you for your answer, but I still don’t know, what else I could provide?

From the sensors.yaml:

  - platform: statistics
    entity_id: sensor.wohnzimmer_aqara_temperature
    name: wohnzimmer_statistics_temperature
    sampling_size: 2000
      minutes: 1440
  - platform: template
        friendly_name: "Wohnzimmer Max 24h"
        value_template: "{{ state_attr('sensor.wohnzimmer_statistics_temperature', 'max_value') }}"
        unit_of_measurement: "°C"

What else could be helpful?

That’s not all of your config. Are you using recorder integration? etc.
Aside , I really don’t understand what you are trying to do? I mean you have a measurement sample size of ~33 minutes , without recording so startup will be affected, then on top of that you have a measurement age of ~24 minutes . I don’t know how this can be expected to do what you allude to in your OP .
What is it you actually are trying to do? in simple terms

EDIT. I will be AFK now until later. If you are trying to take a max measurement every 24 hours, then you could try:-

  - platform: min_max
    name: aqara_max_temp
      - sensor.wohnzimmer_aqara_temperature

#-- run sometihing at 1 min past midnight every day
  - alias: 'some name'
    # -- change time to suit
      - platform: time
        at: "00:00:01"
      #- Define what it is you want to do...
      service: ...
        ... something using {{ states('sensor.aqara_max_temp') }} maybe?!

Alternatively if you want to graph every day upto 10 days then just delete the automation, graph the sensor.aqara setting the refresh parameters in the card for 24hrs - or use a custom graphing card, there are plenty , search. I boldface upto 10 days because by default HA stores only 10 days worth of history. This can be changed by for example using the recorder integration.\

Your requirement is not clear to me and I’m speculating at what you are trying to do. There’s more than one way to do what I suggest above.

Thanks again for taking the time to think about my issue.

What I’ve posted is all I use in this context. I do not use the recorder integration, because it has been unknown to me until now.

I also don’t understand, where your values of 24/33 minutes are coming from.

What I tried to do was pretty simple, at least from my understanding. I have a physical sensor recording the temperature and so I’ve created a new sensor noting down min, mean and max values. I set max_age to 1440 minutes, just to be able to cover 24h. Then I guessed that 2000 samples within 24 minutes should be enough to cover all changes during the day.

Now I was expecting that I could print a graph, showing e.g. the max temperature during the last 24 hours. This is a moving window, so the max value could change each minute, because the physical sensor might record a new max value and then the artificially created sensor should immediately be updated.

But the graph shows that doesn’t work as I thought it would. The first max value looks fine, but the next value does not fit into the picture I have in my mind. So I guess I still miss something.

times are seconds (insofar as config on the integrations you use are concerned)

Sorry, I don’t get it. I clearly says ‘minutes’:

right. I give up.
this is too painful having to extract information in pebble inches and get the point over.
someone else can take over.

Fine for me.

You are talking about seconds and the API doc clearly shows that using minutes is allowed and this is what I did. So where is the problem?