Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to list only unavailable entities and/or devices? #48

Open
OZ1SEJ opened this issue Feb 20, 2024 · 2 comments
Open

How to list only unavailable entities and/or devices? #48

OZ1SEJ opened this issue Feb 20, 2024 · 2 comments

Comments

@OZ1SEJ
Copy link

OZ1SEJ commented Feb 20, 2024

  1. Thank you SO MUCH for this - I've been looking for this for a long time :-)
  2. I'm beginning to customize it, and the first thing I noticed was that a lot of these unavailable entities all have to do with a few devices. How would I list the devices only, instead of all the entities?
  3. This also list all entities that have a state of unknown. Would it be possible to omit these, thus only listing the unavailable ones? I've tried to look for an "unknown" keyword, but I can't find any...
@jazzyisj
Copy link
Owner

jazzyisj commented Feb 21, 2024

  1. My pleasure.
  2. Not really. The attribute is a list of entity id's. I suppose one could write a template which tries to identifies any devices that is unavailable, list those devices but not it's entities, and then list any remaining entities that don't belong to a device. But that is well beyond the scope of this sensor. I'll leave this issue open for now and maybe if I get a little time I'll try to put something together for you. You might get a quicker response in the forum. Also see the example detailed notification automation it sorts entities by device and names the device.
  3. Make the same changes I made to the base template here to yours to only select entities with a state of unavailable.
            {% set ignore_seconds = 60 %}
            {% set ignored = state_attr('group.ignored_unavailable_entities', 'entity_id') %}
            {% set ignore_ts = (now().timestamp() - ignore_seconds)|as_datetime %}
            {% set entities = states
                | rejectattr('domain','in',['button', 'event', 'group', 'image', 'input_button', 'input_text', 'remote', 'tts', 'scene', 'stt'])
                | rejectattr('last_changed', 'ge', ignore_ts) 
                | selectattr('state','eq','unavailable') %}
            {% set entities =  entities | rejectattr('entity_id', 'in', ignored) if ignored != none else entities %}
            {{ entities | map(attribute='entity_id') | list | sort }}

@Mincka
Copy link

Mincka commented Feb 21, 2024

I came here today for point 3 and I find both question and answer! Thank you! 😍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants