I have multiple temperature sensors in each room/area and I would like to display (and use in other automations/mqtt) average temperature per area. Currently I’m using Helpers in UI (combine multiple sensors option) to get an average and to have history of it however this is not scalable (adding/removing sensor and/or is a lot of clicks for such simple thing). Is there a possibility to dynamically get average temperature of area as separate entity without using Helper? I found that I can use template with state something like this as a state:
This is how I would do it. Although I’d change variables to be a single line
variables: {area: bedroom}
You can even use the template editor to write the config for you.
template:
- sensor:
- default_entity_id: sensor.bedroom_average_temperature
variables:
area: bedroom
<<: &config
name: "{{ area | default | replace('_', ' ') | title }} Average Temperature"
unit_of_measurement: "°C"
state: "{{ area_entities(area) | select('is_state_attr', 'device_class', 'temperature') | map('states') | select('is_number') | map('float') | average }}"
{%- set remaining_areas = ['kitchen', 'living_room'] %}
{%- for area in remaining_areas %}
- default_entity_id: sensor.{{ area }}_average_temperature
variables: {area: {{ area }}}
<<: *config
{%- endfor %}
Then just copy/paste the results into your configuration with this code commented out if you ever need to make future changes.