Average Sensor

I just noticed some entities not graphing since I did the 2023.11 update. Having looked I found the culprit to be 4 “Average” platform sensors in my config file. I read the post above from sweetpotatobeef and thought a Restart would solve. It’s refusing to restart with 4 errors being

Platform error sensor.average - No module named 'homeassistant.util.temperature'

Googling I found that homeassistant.util.temperature was deprecated a year ago so probably was removed in the 2023.11 release.
Anyone else with this problem?
Is it going to get fixed?

A great additional feature (or did I just miss it?) would be to also consider the last_seen attribute of sensors. So it should be options like “ignore sensor if last update is older than timespan” (timespan being e.g. 1h) and “ignore value of sensors older than timespan compared to newest available sensor value”.

This would cover sensors that just don’t update timely sometimes by just ignoring them until they catch up to a more current reading.

Hey, I am using the sensor to calculate the average daily temperature like the following:

  - platform: average
    name: "Average Outside Temperature"
    end: '{{ now().replace(hour=0).replace(minute=0).replace(second=0) }}'
    duration:
      hours: 24
    entities:
      - sensor.vicare_outside_temperature

Is it possible to fill out based on the temperature sensor the historic values of the past days somehow?

Thanks!

For some reason my Average Sensors stopped working today.
I have no idea why…never had any issues so far.

Only change was moving from a Pi 4 to a Pi 5 but everything else still works…

Hi

I’m using the average sensor to become the average outside temperature at the end of each day.

But I could not find what sampling rate is used. How regularly are you taking a measure?

I may be wrong, but for a correct average it’s important to take a measure example each 1 second. After 24 hours you will have a sum of 86.400 measures. Or a sum of 1.440 measures when taking a sample each minute.

What is the sampling rate you are using?

This is my configuration
sensor:
- platform: average
name: Gemiddelde dagtemperatuur tuin
unique_id: Gemiddelde_dagtemperatuur_tuin
entities:
- sensor.temp_tuin
#ends today at 00:00, last 24 hours.
end: ‘{{ now().replace(hour=0).replace(minute=0).replace(second=0) }}’
duration:
hours: 24

Can anyone affirm that this is a daily average? starting from 00:00 ?

thank you


sensor:
  - platform: average
    name: "Average Daily Solar Running Capacity"
    start: '{{ now().replace(hour=0).replace(minute=0).replace(second=0) }}'
    duration:
      hours: 24
    entities:
      - sensor.solar_running_capacity

I’m unable to install this from HACS, I get an “unspecified error” when attempting to download.

For a manual install, do I just need the average folder that it’s inside the ha-average-2.3.1/custom_components folder in the ZIP, or do I follow the Manual Installation instructions on GitHub and place the entire contents of ha-average-2.3.1/ into /config/custom-components/average? If so, I’ll end up with /config/custom_components/average/ha-average-2.3.1/custom_components/average which seems off to me.

Hi, I turned on debug logging in HACS and there is a problem with the specification for the current Average sensor release. HACS is looking for https://github.com/Limych/ha-average/releases/download/2.3.1/average_sensor.zip and gets a 404. As you note, the path https://github.com/Limych/ha-average/releases/download/2.3.1/average.zip does work.

I had no problem installing from HACS yesterday, got version 2.3.3

I stumbled over Average Sensor while searching for a solution that gives me a averaged hourly value. The input sensor is household power consuption (not energy), which is one reading every minute.

The following setting averages power per hour, but I’m one hour of as a conesequence

  - platform: average
    name: 'Power Consumed Avg Hr'
    unique_id: sensor.power_consumed_avg_hr
    start: >-
      {{ as_timestamp(
        now().replace(
               hour=int(now().replace(minute=(now().minute // 60) * 15, second=0).strftime('%H'))-1
           ).replace(
               minute=int(now().replace(minute=(now().minute // 60) * 15, second=0).strftime('%M'))
           ).replace(
               second=0
           )
        ) }}
    end: >-
      {{ as_timestamp(
        now().replace(
               hour=int(now().replace(minute=(now().minute // 60) * 15, second=0).strftime('%H'))
           ).replace(
               minute=int(now().replace(minute=(now().minute // 60) * 15, second=0).strftime('%M'))
           ).replace(
               second=0
           )
        ) }}
    entities:
      - sensor.power_consumed

sensor.power_consumed_avg_hr:
image

Source sensor, sensor.power_consumed, averaged in Excel:
image

Hi all,

I am trying to come up with a way to implement the average sensor for a specific use case: I would like to know the average duration a specific switch is turned on.

So, if a switch is on for 10 minutes, then the next day it’s turned on for 5 minutes, and later that same day it is turned on for 8 minutes, I would like this “averaged” sensor to be (10+5+8) / 3 = 7.66 minutes. Note that I do not want to take into account how long the switch has been off, so it does not matter if it has been days between times it was used or not.

Is there any way I can implement this with ha-average?

Thank you!

If you do your SQL query against the ‘statistics’ or ‘statistics_short_term’ database, then it also takes time into account and should be equally accurate.

Seems to me that the sensor skips peaks with short duration? See this post.

I am looking for a real aggregation option. I actually want to save only one value per period (e.g. calendar day) from the average to reduce data and be able to access finished aggregated values ​​immediately. The average sensor calculates the average, but still generates a lot of individual values, almost continuously. On the current day, the sensor would have to continually overwrite the old value until the period ends. Then a new individual value is generated.

I have three “average” sensors in my Configuration.yaml

image

‘AußentemperaturAverageDaily’ is working fine.
‘WP_LastAverageEver’ is not even displayed in the entities overview.
‘WP_LastAverageDaily’ is found in the entities overview but with a “Unavailable” remark.
image

Has anyone an idea why only one of the three is working?

The sensor “sensor.heat_generator_1_current_capacity_specification_compressorture” itself is also working fine.
It is a percentage. Maybe this is playing a role?

Thanks a lot.

Hi,
my shelly DS18B20 temperature sensor for the pool delivers data like this:

So it is jumping always up and down for about 0,1°C.

This is during heatup:

The pools temp can decrease due to cooling down and increase normally only with heatpump.
To calculate my heatpumps COP I need to sum up all increasing temp data as long the heatpump is running. And to calculate the yearly COP I want to sum up the increasing temp data over the whole year.
But doing this with e.g. statistics sensor (change) will also sum up all the small jumps up and down, which is wrong.

Any idea who I can solve this (e.g. with filters and if yes with what kind of them)?

thanks