following up on Sensor - Unavailable/Offline Detection which I dont want to hijack any further with this ‘detail’ please have a look how I can ‘filter’ out entities in a template using a glob mask
this is what I have now:
{% set ignore_list = ['light.driveway','light.garden_backyard','light.garden_terrace',
'light.porch_outdoors'] if
is_state('binary_sensor.outside_daylight_sensor','on') else [] %}
{% set unavailable = states|selectattr('state','eq','unavailable')
|rejectattr('entity_id','in',state_attr('group.entity_blacklist','entity_id'))
|rejectattr('entity_id','in',ignore_list)
|rejectattr('domain','eq','media_player')
|map(attribute='entity_id')
|list %}
{{ unavailable|count }}
And I need to prevent the group of sensors made by my SolarEdge sensor of being included.
I can add these individually in my blacklist group or even in the verbose ignore_list, but would hope to use some filter in the template.
as said in the other thread, along the lines of
|rejectattr(‘object_id’,‘startswith’,‘solaredge’)
now I know this isn’t valid, but hope you can see what I am looking for.
always prefer the state_attr() myself for known reasons, and kind of like the further development of the bottom version, since it emphasizes the relation to the mother sensor visually for me.
thought about being safe, but must admit, on the level of the mother sensor:
if sensor.solar_edge_overview exists, all the other sensors exist.
And, as a matter of fact, the mother sensor happens to get thrown out now and then, the rest sensor doesnt always connect. If so, all these sensors show Unknown…
so, shouldn’t I test on the existence of the mother sensor?
{% if 'sensor.solaredge_overview' %}
{% set overview = state_attr('sensor.solaredge_overview','overview') %}
{{(overview.lifeTimeData.energy|float/1000)|round(2)}}
{% else %} Unavailable #(or offline...)
{% endif %}
I was wrong about this one. It works for selecting a set of similarly named entities but not for rejecting them.
It can be done in two steps:
{% set x = states
| selectattr('object_id','gt','solaredge_')
| selectattr('object_id','lt','solaredge_x')
| map(attribute='entity_id')
| list %}
{{ states | rejectattr('entity_id', 'in', x) | list }}