Sensor for unavailable entities based on the group - problem with the template

I’m trying to create a sensor which will count the entities with status: ‘unavailable’,‘unknown’,‘none’

Below is a group of the devices to track:

  name: Track - All
      - switch.living_2  

Template which I will use to create a sensor:

{{ states|selectattr('state','in',['unavailable','unknown','none'])
            |rejectattr('entity_id','in',state_attr('group.track_all', 'entity_id'))
            |rejectattr('domain','eq','group')|list|count }}

The problem is that in above example we takes all entities and exclude. Can I do something opposit, means to check only devices from the group ‘track_all’?

{{ expand('group.track_all')|selectattr('state','in',['unavailable','unknown','none'])|list|count }}
1 Like

@123 Thank you for super quick fix :slight_smile:

1 Like

@123 BTW where I can find some documentation reg. to this syntax?

The general reference for Jinja2 can be found here:

However, it is not written specifically for Home Assistant users so some parts aren’t easy to understand and other parts are not supported by Home Assistant.

I think this section in Home Assistant’s documentation is probably the best for explaining Jinja2 templating:

Plus this one:

1 Like

Looking for something similar, but prefer to have it list by Area, or actually an array of areas. I put my sensors into areas like rooms. the entities that are more informational, like the bazilion Alexa entities I dont care about, and i dont put them in an area.