Skip to content
Average Sensor for Home Assistant
Python Shell
Branch: master
Clone or download
Type Name Latest commit message Commit time
Failed to load latest commit information.
.github Update environment Jan 2, 2020
custom_components/average Ignore non numeric values (#7) Jan 2, 2020
.pre-commit-config.yaml Update environment Jan 2, 2020 First version Aug 25, 2019 Added "precision" option Aug 25, 2019 README typography fix. Sep 25, 2019 Update environment Jan 2, 2020
example.png First version Aug 25, 2019
hacs.json Added updates tracking Aug 25, 2019
requirements.txt Update environment Jan 2, 2020
tracker.json Ignore non numeric values (#7) Jan 2, 2020 Update environment Jan 2, 2020

Please ⭐️ this repo if you find it useful

Average Sensor for Home Assistant

GitHub Release GitHub Activity License

hacs Project Maintenance

GitHub pull requests Bugs

Community Forum

This sensor allows you to calculate the average state for one or more sensors over a specified period. Or just the average current state for one or more sensors, if you do not need historical data.

Initially it was written special for calculating of average temperature, but now it can calculate average of any numerical data.


What makes this sensor different from others built into HA:

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.

Compare with statistics sensor:
This sensor copes with the averaging of data over a certain period of time. However… 1) it cannot work with several sources at once (and can't receive temperature from weather, climate and water heater entities, like min-max sensor), 2) when calculating the average, it does not take into account how much time the temperature value was kept, 3) it has a limit on the number of values ​​it averages - if by chance there are more values, they will be dropped.

You can find a real example of using this component in my Home Assistant configuration.

I also suggest you visit the support topic on the community forum.

Breaking changes

  • Since version 1.3.0 the default sensor name is “Average” instead of “Average Temperature”


  1. Using the tool of choice open the directory (folder) for your HA configuration (where you find configuration.yaml).

  2. If you do not have a custom_components directory (folder) there, you need to create it.

  3. In the custom_components directory (folder) create a new folder called average.

  4. Download all the files from the custom_components/average/ directory (folder) in this repository.

  5. Place the files you downloaded in the new directory (folder) you created.

  6. Restart Home Assistant

  7. Add average sensor to your configuration.yaml file:

    To measure the average current temperature from multiple sources:

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

    To measure average temperature for some period:

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

    or you can combine this variants for some reason.

* * *

I put a lot of work into making this repo and component available and updated to inspire and help others! I will be glad to receive thanks from you — it will give me new strength and add enthusiasm:

Patreon PayPal
or support via Bitcoin or Etherium:

Configuration Variables

(list) (Required)
A list of temperature sensor entity IDs.

You can use weather provider, climate and water heater entities as a data source. For that entities sensor use values of current temperature.

(string) (Optional)
Name to use in the frontend.
Default value: "Average"

(template) (Optional)
When to start the measure (timestamp or datetime).

(template) (Optional)
When to stop the measure (timestamp or datetime).

(time) (Optional)
Duration of the measure.

(number) (Optional)
The number of decimals to use when rounding the sensor state.
Default value: 2

Time periods

The average integration will execute a measure within a precise time period. You should provide none, only duration (when period ends at now) or exactly 2 of the following:

  • When the period starts (start variable)
  • When the period ends (end variable)
  • How long is the period (duration variable)

As start and end variables can be either datetimes or timestamps, you can configure almost any period you want.


The duration variable is used when the time period is fixed. Different syntaxes for the duration are supported, as shown below.

# 15 seconds
duration: 15
# 6 hours
duration: 06:00
# 1 minute, 30 seconds
duration: 00:01:30
# 2 hours and 30 minutes
  # supports seconds, minutes, hours, days
  hours: 2
  minutes: 30


Here are some examples of periods you could work with, and what to write in your configuration.yaml:

Last 5 minutes: ends right now, last 5 minutes.

  minutes: 5

Today: starts at 00:00 of the current day and ends right now.

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

Yesterday: ends today at 00:00, lasts 24 hours.

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

This morning (06:00–11:00): starts today at 6, lasts 5 hours.

start: '{{ now().replace(hour=6).replace(minute=0).replace(second=0) }}'
  hours: 5

Current week: starts last Monday at 00:00, ends right now.

Here, last Monday is today as a timestamp, minus 86400 times the current weekday (86400 is the number of seconds in one day, the weekday is 0 on Monday, 6 on Sunday).

start: '{{ as_timestamp( now().replace(hour=0).replace(minute=0).replace(second=0) ) - now().weekday() * 86400 }}'
end: '{{ now() }}'

Last 30 days: ends today at 00:00, lasts 30 days. Easy one.

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

All your history starts at timestamp = 0, and ends right now.

start: '{{ 0 }}'
end: '{{ now() }}'

The /dev-template page of your home-assistant UI can help you check if the values for start, end or duration are correct. If you want to check if your period is right, just click on your component, the start and end attributes will show the start and end of the period, nicely formatted.

Track updates

You can automatically track new versions of this component and update it by custom-updater (deprecated) or HACS.

For custom-updater to initiate tracking add this lines to you configuration.yaml file:

# Example configuration.yaml entry
    - components
You can’t perform that action at this time.