When you can mash / plead / beat the templating engine into doing what you want in #HomeAssistant it is incredibly powerful.
Good freaking grief it took far too much effort to make an average of a dynamic set of sensors (Air Quality sensors inside my house).
=> More informations about this toot | More toots from warthog9@social.afront.org
@warthog9 I recently struggled with this as well, trying to create a sensor that was an average of all temperature sensors. Here's what I came up with: https://gist.github.com/tkroo/dcf9822052fd4900c14fae4712e382f4
=> More informations about this toot | More toots from tkroo@fosstodon.org
@tkroo Interesting, you might have a couple of things I can steal to simplify mine but let me paste what I've got here, in all it's extra debug glory
customize:
sensor.aqi_pm25_indoor:
aqi_sum:
aqi_count:
template:
- name: "Indoor AQI (pm2.5)"
unique_id: sensor.aqi_pm25_indoor
state: >
{% set ignored_aqi_entities = state_attr('group.ignored_aqi_entities', 'entity_id') %}
{% set entities_aqi_list = states
| rejectattr('state','in',['unknown','unavailable']) | rejectattr('entity_id','search','device_tracker')
| rejectattr('entity_id','search','wimp')
| rejectattr('entity_id','search','sensor.aqi.pm25.indoor')
| rejectattr('entity_id','search','sensor.aqi_pm25_indoor')
| rejectattr('entity_id','search','rx')
| rejectattr('entity_id','search','tx')
| selectattr('entity_id', 'search', 'aqi')
%}
{% set entities_aqi_list = entities_aqi_list
| rejectattr('entity_id', 'in', ignored_aqi_entities)
if ignored != none
else entities_aqi_list %}
{% set ns = namespace( aqi_count = 0, aqi_total = 0 ) %}
{% for entity in entities_aqi_list | map(attribute='entity_id') %}
{% set ns.aqi_total = ( states(entity) | float ) + ns.aqi_total %}
{% set ns.aqi_count = ns.aqi_count + 1 %}
{% endfor %}
{{ ( ns.aqi_total / ns.aqi_count ) | round(0) }}
attributes:
unit_of_measurement: AQI
device_class: aqi
[#] OPTIONAL - Add entities you want to ignore to this group. Delete if not using group.
group:
ignored_aqi_entities:
entities:
- sensor.calculated_aqi_5 # outside sensor
- sensor.indoor_aqi_pm2_5
=> More informations about this toot | More toots from warthog9@social.afront.org
@warthog9 Thanks for sharing. I like the how you set up an ignore group. I'll be stealing that :) Also, I see that your reject filters are before selects and that made me wonder if the order is important when the yaml/jinja is interpreted. It seems likely more efficient to put reject conditions at the start. So I think I'll adopt that as well. Cheers.
=> More informations about this toot | More toots from tkroo@fosstodon.org
text/gemini
This content has been proxied by September (ba2dc).