Average Sensor

This component is actually very useful, but it slows down my system and render it unuseable. I was almost not able to delete the component.

I did only setup one average sensor with 1 day period on a entity that updates data every second. How often do it calculate the state of this sensor? Should be a variable to specify update frequency to reduce processor use.

The idea is very good and I really find it useful, bud as it is now I cannot use it.

Now the logic of work is as follows:

  • If the duration parameter is specified, updating the sensor value occurs regularly, but no more than once every 20 seconds;
  • If this parameter is not specified, the sensor value is updated every time any of the sensors is updated, where the source values ​​come from.

To reduce processor load, reducing the refresh rate of source sensors will also help.

UPD. I double-checked. There is an inaccuracy in the quoted description: this is not about the duration parameter, but about any indication of the time period.

Hi and thank you for your work and for replying so quickly :slight_smile:

That was how I understood the description as well. Reducing refresh rate on my sensor is not an option and should not be necessary as it should be handled by the component and not by altering the source.

Maybe you could look at adding a variable for calculation frequency? It would make it much more controllable and less “risky”. As I said I like this component and find it useful, but too unpredictable.

I’ll try, but now I’m not sure it’s able.

Added the sensor to make an average of the external temperature from 4 different weather providers:

sensor:
  - platform: average
    name: 'Average Temperature'
    entities:
      - weather.openweathermap
      - weather.dark_sky
      - weather.weatherbit_lugo
      - weather.casa

I got the sensor up with 4 sources but 0 available.
here are the logs:

2020-06-09 21:08:00 ERROR (MainThread) [custom_components.average.sensor] Could not convert value "rainy" to float
2020-06-09 21:08:00 ERROR (MainThread) [custom_components.average.sensor] Could not convert value "cloudy" to float
2020-06-09 21:08:02 ERROR (MainThread) [custom_components.average.sensor] Could not convert value "rainy" to float
2020-06-09 21:08:02 ERROR (MainThread) [custom_components.average.sensor] Could not convert value "cloudy" to float

That’s because you would need to first extract the temperature attribute from each entity

from the main repo example:

Compare with the min-max sensor:
This sensor in the mean mode produces exactly the same average value from several sensors. But, unlike our sensor, it cannot receive the current temperature data from a weather, climate and water heater entities.

# Example configuration.yaml entry
sensor:
  - platform: average
    name: 'Average Temperature'
    entities:
      - weather.gismeteo
      - sensor.owm_temperature
      - sensor.dark_sky_temperature

If you create template sensors to retrieve the temperatures from each weather entity you could then average those

Clearly you haven’t read it properly.
I will rephrase it for you so maybe you can understand better what is written:
Unlike our sensor ( the average, the one i want to configure) the min max sensor cannot read directly from weather entity. The min max sensor is the one that cannot read the weather not the average. In fact in the examples there is clearly a weather entity…

How about simply trying my suggestion? …since what is written obviously doesn’t work. OR, report it as a bug on the GitHub page

Looks like this stopped working with with HA 0.113.0 release

No it hasn’t. There is an error in the logs but the sensor still is working.
eg:



image

I beg your pardon. Now I have a lot of work in my main place and I do not have time to deal with support in time. I will gradually fix everything.

1 Like

It’s actually still working fine = it is an error so it shouldn’t but it does…

can this sensor be used in conjunction with conditions?

i.e. only take measurements if a binary sensor is on and the time to read is from 22h00 for 2 hours?

like an AND condition in automations…

Maybe…
you can definitely set a range of time to average for and the time will accept a template. You could probably make it work I think…

Fixed in v1.6.6

Maybe define a template sensor that only has values when all the other conditions are met?
Then do the average for that new sensor.

Hey
i get errors on this template, should this work or is it not possible?

2021-01-07 20:12:07 ERROR (MainThread) [homeassistant.helpers.entity] Update for sensor.average_adguard_current_week_queries_blocked fails

  - platform: average
    name: 'Average - AdGuard Current Week Queries Blocked'
    start: '{{ as_timestamp( now().replace(hour=0).replace(minute=0).replace(second=0) ) - now().weekday() * 86400 }}'
    end: '{{ now() }}'
    entities:
      - sensor.adguard_dns_queries

Can someone explain this behaviour? Currently I have this code:

- platform: average
  name: "Average temperature"
  end: '{{ now().replace(hour=23).replace(minute=59).replace(second=0) }}'
  duration:
    hours: 24
  entities:
    - weather.home


On the left side (where the graph shows horizontal lines) you see my old settings with this in the code:

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

On the right side are the settings applied shown above.
Why does the behaviour change? What I would like to achieve is the average temperature at 23:59 of the previous 24 hours.