Template filtering of entities via the new labels feature - howto?

You use the in test if you’re doing that way… hence the link to Tests

The exact filter will depend on where you place it.

{{ states.sensor
| selectattr('entity_id', 'in', label_entities('monitored')) 
| selectattr('last_changed', 'lt', now()-timedelta(seconds=3600)) 
| map(attribute='entity_id') 
| list }}

or

{{ states.sensor
| selectattr('last_changed', 'lt', now()-timedelta(seconds=3600)) 
| map(attribute='entity_id')
| select('in', label_entities('monitored')) 
| list }}
1 Like