Alerting based on status for specific devices

Hi all
I’m looking to create a script that will send me a daily report of devices that are currently switched off or unavailable. I want to be specific about the devices/entities and exclude ones with specific labels or attributes. I’ve done a bit of research in the forum and got so far but haven’t quite got there yet.

I’m stuck with how to exclude entities with a specific label.

Here’s what I’ve got so far

{{ states
| selectattr('state','in', ['unknown', 'unavailable'])
| rejectattr('domain', 'in', ['person','tts','device_tracker','conversation'])
| rejectattr('attributes.device_class', 'in', ['identify','timestamp'])
| rejectattr('entity_id','match','switch.echo_*_switch')
| reject('in',label_entities("Unavailable_Possible"))
| rejectattr('entity_id', 'in', [label_entities("Unavailable_Possible")])
| map(attribute='entity_id')
| list 
}}

The following don’t appear to be working at all, I tried reject and rejectattr to no avail:


| rejectattr('entity_id','match','switch.echo_*_switch')
| reject('in',label_entities("Unavailable_Possible"))
| rejectattr('entity_id', 'in', [label_entities("Unavailable_Possible")])

I would appreciate the assistance.

Thank you in advance

I use this to track when entities go unavailable. Then I have an automation to notify me if unavailable entities are != 0.

unavailable-entities-sensor/README.md at e003e809e45404ee0a9af7aaaa3e698f216952bb · jazzyisj/unavailable-entities-sensor · GitHub.

Edit: meant entities, not devices.

notwithstanding @MaxK 's suggestion and focusing just on your template…

{{ states
| selectattr('state','in', ['unknown', 'unavailable'])
| rejectattr('domain', 'in', ['person','tts','device_tracker','conversation'])
| rejectattr('attributes.device_class', 'in', ['identify','timestamp'])
| rejectattr('entity_id','search','switch\.echo_.*_switch)
| rejectattr('entity_id', 'in', label_entities("Unavailable_Possible"))
| map(attribute='entity_id')
| list 
}}

use search, not match
don’t put [ ] around label_entities. label entities already returns a list.

EDIT: updated for search regex pattern.

Thank you.

That worked great. However, the line below still doesn’t work with the wildcard symbol. Any ideas?

| rejectattr('entity_id','search','switch.echo_*_switch')

Thanks. I will check this out :slight_smile:

try:

| rejectattr('entity_id','search','switch\.echo_.*_switch')

search uses regex

Thank you. That worked perfectly