Quantcast
Channel: Configuration - Home Assistant Community
Viewing all articles
Browse latest Browse all 95541

Average temprerature across rooms - What is the best way?

$
0
0

@klogg wrote:

I currently have a template sensor to average the temperature across a group of rooms but I am not convinced this is the best (most efficient) approach.

Has anyone else done this and if so how do you do it?

Here is mine. It ignores readings less than 2 minutes old and also readings more than 10 minutes old as my temperature sensors can update several times a minute and also have been known to go offline :slight_smile:

   average_downstairs_temperature:
    friendly_name: Average Downstairs Temperature
    entity_id:
      - sensor.hall_temperature
      - sensor.kitchen_temperature
      - sensor.sitting_room_temperature
      - sensor.back_bedroom_temperature
    value_template: >
      {% set entities = ['sensor.hall_temperature',
                         'sensor.kitchen_temperature',
                         'sensor.sitting_room_temperature',
                         'sensor.back_bedroom_temperature'] %}
      {% set time = as_timestamp(now()) %}
      {% set ignore_recent = 120 %}
      {% set ignore_old = 600 %}
      {% set ns = namespace(count=0, value=0) %}
      {% for e in entities %}
        {% set domain, object_id = e.split('.') %}
        {% set s = states[domain][object_id] %}
        {% if s.state is defined and
              s.state is not none and
              s != 'unknown' and
              s != 'unavailable' and
              s != '' and
              ((time - as_timestamp(s.last_updated)) < ignore_recent or
               (time - as_timestamp(s.last_updated)) > ignore_old) %}
          {% set ns.count = ns.count + 1 %}
          {% set ns.value = ns.value + s.state | float %}
        {% endif %}
      {% endfor %}
      {% if ns.count == 0 %}
        'unavailable'
      {% else %}
        {{ (ns.value / ns.count) | round (1) }}
      {% endif %}
    unit_of_measurement: °C

Posts: 6

Participants: 4

Read full topic


Viewing all articles
Browse latest Browse all 95541

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>