Average Sensor

I had to do the same, I was surprised to find duplicate sensors with a “_2” suffix (I don’t always read all changelogs… ! :stuck_out_tongue: )
It works perfectly fine after a HA restart.

You don’t have to read the changelog, but just pay attention to the version number:

Given a version number MAJOR.MINOR.PATCH, increment the:

  1. MAJOR version when you make incompatible API changes,
  2. MINOR version when you add functionality in a backwards compatible manner, and
  3. PATCH version when you make backwards compatible bug fixes.
2 Likes

Thanks, I did not know. :slight_smile:

Can anyone tell me why my average sensor might be ‘stuck’ on the same value for days?

  - platform: average
    name: average outdoor temp
    start: '{{ now().replace(hour=8).replace(minute=0).replace(second=0) }}'
    duration:
      hours: 8
    entities: 
      - sensor.terrace_table_light_am2301_temperature

Gives me this output in dev tools;

start: '2021-06-14T08:00:00+02:00'
end: '2021-06-14T10:05:16+02:00'
sources:
  - sensor.terrace_table_light_am2301_temperature
count_sources: 1
available_sources: 1
count: 2
max_value: 23.9
min_value: 23.9
unit_of_measurement: °C
friendly_name: average outdoor temp
device_class: temperature

The source sensor hasn’t been below 25 today. The 23.9 has been persistent for a few days and even persists through HA restarts.

Enable debug logs. By them, most likely, you can see the reason.

Are you sure about the entity “sensor.terrace_table_light_am2301_temperature” ?

@Limych are you still maintaining this? Or does anyone else know. It looks like there hasn’t been any activity for around a month. It would be nice to have an update for the new state_class/statistics graph etc.

I hope someone will maintain custom component in case @Limych doesn’t.

He did an update 2 months ago… what more do you want? He always jumps on bugs and is very responsive. Did you try a feature request on the repo? There’s also this wonderful feature called customize where you can add the class…

1 Like

Which is part of the reason I sponsor their work, and find it strange that there is no activity for so relatively long.

Well of course.

Sorry guys. I do all these projects in my free time. Recently, I somehow got tired very much, plus it was necessary to complete the repairs in the apartment, plus there were difficulties in my personal life … Everything somehow overlapped so that it became a little not up to these projects.

But, yes, perhaps it’s time for me to return …

3 Likes

Love this custom component. Works like a charm for my plant sensors. But is there a way to change the update frequency from 20 seconds? I have a duration of 7 days on average, but I don’t need an update every 20 seconds. Only like every 15 minutes. Is it possible to change that somewhere?

See here: Entity integration platform options - Home Assistant

1 Like

hi, I have this problem, the average temperature does not aggregate with the other temperatures, I think for a unit of measurement problem. how can i solve? Thanks

sensor:
  - platform: template
    sensors:
      termost_temp:
        friendly_name: "Termostato Soggiorno"
        unit_of_measurement: '°C'
        value_template: "{{ state_attr('climate.8600225284cca8ba5b29', 'current_temperature') }}"
      temp_esterna:
        friendly_name: "Temperatura Esterna"
        unit_of_measurement: '°C'
        value_template: "{{ state_attr('weather.casa_giavera', 'temperature') }}"
      temp_esterna_openw:
        friendly_name: "Temperatura Esterna Openw"
        unit_of_measurement: '°C'
        value_template: "{{ states('sensor.openweathermap_forecast_temperature') |  round(1) }}"
  - platform: average
    name: 'temperatura media esterna'
    entities:
      - sensor.temp_esterna
      - sensor.temp_esterna_openw
      - sensor.casa_giavera_realfeel_temperature

2 Likes

Strange thing is, it aggregated I think until 2021.11.0, if I remember right… just wondered about today, that suddenly there were 2 graphs instead of 1.

1 Like

Hello people,

Hoping you can help with this.

I started using the average sensor a while ago to calculate the average air quality over a 24h period.

At first, it seemed like it worked perfectly fine. But then I noticed that when the source sensor stabilises (value doesn’t change anymore), the average sensor doesn’t calculate this correctly.

For example, when the average value is 70 and the source sensor value is 10. I would expect the average to be going down (hard). Instead, it stays the same. It looks like the average sensor only works properly while the source sensor keeps changing values.
However, in one of the first messages in this thread, it’s said this average sensor should be able to handle that properly.

Any idea what I’m doing wrong? There are pictures of the 2 graphs in this thread:
https://community.home-assistant.io/t/24h-average-sensor-incorrect/368451/5

You can see that around 0800AM, the source sensor value is close to 0 for hours, while the average stays stable around 70.

I intended to use the Average Sensor attributes to determine the Min and Max values of the current day and yesterday’s day.
However, I can’t manage to use the Min and Max attributes. The result is always none. I have used the developer tool in HomeAssistant and tried different attributes. All are working, except of the min and max. Maybe I am overseeing something. So here is what I have done so far:

  1. In the configuration.yaml I added the following lines:
 sensor:
  - platform: average
    name: 'Average Temperature ATC1'
    entities:
      - sensor.ble_temperature_atc1
    duration:
      minutes: 10
    precision:
      1
  1. In the developer tools I tried some of the attributes, the result for min and max is always None.
{{ state_attr('sensor.average_temperature_atc1', 'min') }}
{{ state_attr('sensor.average_temperature_atc1', 'max') }}
{{ state_attr('sensor.average_temperature_atc1', 'count') }}
{{ state_attr('sensor.average_temperature_atc1', 'start') }}
{{ state_attr('sensor.average_temperature_atc1', 'end') }}
{{ state_attr('sensor.average_temperature_atc1', 'sources') }}
{{ state_attr('sensor.average_temperature_atc1', 'count_sources') }}

gives:

None
None
3
2022-01-03T20:52:00+01:00
2022-01-03T21:02:00+01:00
['sensor.ble_temperature_atc1']
1

What am I doing wrong?

Best wishes,
Balcony

Hi I a trying to use average sensor.

i have add it in my HA and put this in my config.yaml :

#Average
  - platform: average
    name: 'moyenne prod solaire 30mn'
    duration: 00:30:00
    entities:
      - sensor.envoy_122121066815_current_power_production

but I do not find the sensor in my sensor list!

I am doing something bad or ???
thanks you for your help

I’m sorry, but from your description I can’t tell why the sensor didn’t show up. The settings look correct. Look at your HA logs - the answer should be there.

Does anyone have a way to create a average based on the state of a different entity? A “averageIF”-sensor.
For example creating an average day/nighttime temperature, average home/away power consumption etc.