Daily average temperature of a sensor

Is there a way to get a report of the average temperature in a day based on the temperature readings of a sensor and then to get daily historical data of that average? For instance, if the sensor reported 10 different temperature readings within 24 hours I would like to be able to get the total of the 10 readings from within a days period then divide that by 10 to get the average. Then I would like to be able to get daily historical data of that average.

I just implemented this platform: sql example and the Average Sensor Since 24 hours haven’t passed I don’t know what they will do after the 24 hours have passed. Does anyone know if I can use either of those to then get a daily record of the daily average or do I need yet a different solution to get what I need?

The Min/Max integration only does an average of two sensors and not an individual sensor which is why I never used that one.

have a look at this custom component

That is the Average Sensor that I had mentioned in my post. What I don’t know is if that will allow me to get daily historical data of that average in HA. Is that what it will do?

the average sensor will give you a rolling 24 hour average if you set it up that way. e.g. if it’s 8am now, you’ll get an average from 8am yesterday to 8am today.

If you want to have a static midnight to midnight only, you’ll need to use the sql look up.

Actually that’s wrong. There is an example on the average custom-component showing how to set it for midnight to midnight…

I am having trouble understanding if I use the following example as a guide as to whether or not I will get the daily avg and also historical data of the daily average. Do you have an idea?

# Example configuration.yaml entry
  - platform: average
    name: 'Average Temperature'
      days: 1
      - sensor.gismeteo_temperature

You won’t - it will give you the last 24 hours. The docs for that component show (with an example) exactly how to set midnight as the start time.
It’s maybe not going to give you historic information easily as you want though.

Ah yes, I see.

end: '{{ now().replace(hour=0).replace(minute=0).replace(second=0) }}'
  hours: 24


You can use the SQL request to answer to your need.

You can find some example on this website (in french sorry, but the syntax is the same) : Hapourtous.fr

Thanks, but I had already implemented platform: sql example as per my initial post. What I wanted was the historical data on a per day basis.

I was finally able to get what I wanted using the platform: sql example, InfluxDB, and Grafana. I had to setup Grafana with field value last since the last value has the average for the whole day, group by 24h or 1d, add tz as Country/City so that the time started at 00:00, then change visualization to Bars under Draw Mode. In order to get the color changed to the HA theme I used the hex color code from HA and put it in add series override.

I verified that the average was accurate by placing the temperature sensor in different temperature extremes for each day of 3 different days and I could see an immediate change as soon as a new day started even if I had moved the sensor prior to the start of the new day.

Is this still working ok for you? I’m looking to do something similar.

Yes it is still working for me.

1 Like

Hi, i would like show average senosr for PV power wich start on sunrise and end on sunset every day. Unfortunately i cant set Start: and End: right. Can anyone here help me pls?
Many thanks

  - platform: average
    name: power_pv_avg_day
#    start: '{{ now().replace(hour=6).replace(minute=0).replace(second=0) }}'
    **start: "{{ (state_attr('sun.sun', 'next_rising') | as_datetime - timedelta(hours=23)) | as_timestamp }}"**
    end: now()
      - sensor.solax_pv_power_total

The problem is the next_rising or next_setting events are always in the future. You’ll need to get the custom integration sun2 to get todays rising and setting.