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

Can't exclude all entities linked to an area or device #3

Open
gmlupatelli opened this issue Aug 25, 2021 · 1 comment
Open

Can't exclude all entities linked to an area or device #3

gmlupatelli opened this issue Aug 25, 2021 · 1 comment
Labels
bug Something isn't working Low Battery Notification Issue related to the Low Battery Notification Unavailable Entities Notification Issue related to the Unavailable Entities Notification

Comments

@gmlupatelli
Copy link
Owner

Can't exclude all the entities linked to an area or device when executing automation from the following blueprints: unavailable_entities_notification and low_battery_notification.

As a workaround, I can expand the areas and the devices into entities inside the target selector.

@gmlupatelli gmlupatelli added bug Something isn't working Low Battery Notification Issue related to the Low Battery Notification Unavailable Entities Notification Issue related to the Unavailable Entities Notification labels Aug 25, 2021
@jgoguen
Copy link

jgoguen commented May 25, 2023

This is what I've done in another blueprint to expand a target selector to a list of entities. The only thing here is it doesn't attempt to deduplicate entries, so if you have a device in the bedroom with two lights and you add the two lights as entities, the bedroom as an area, and the device as a device, you'l end up with the two light entities each added three times. But deduplication shouldn't be hard to add.

At the end of this, all_entities is a list of entity IDs.

variables:
  target: !input target
  all_entities: |
    {% set res = namespace(r=[]) %}
    {% if target.entity_id is defined %}
      {% set ents = [target.entity_id] if target.entity_id is string else target.entity_id %}
      {% set res.r = res.r + ents %}
    {% endif %}
    {% if target.device_id is defined %}
      {% set devices = [target.device_id] if target.device_id is string else target.device_id %}
      {% for dev_id in devices %}
        {% set ents = device_entities(dev_id) %}
        {% set res.r = res.r + ents %}
      {% endfor %}
    {% endif %}
    {% if target.area_id is defined %}
      {% set areas = [target.area_id] if target.area_id is string else target.area_id %}
      {% for t in areas %}
        {% set area_ents = area_entities(t) %}
        {%
          set res.r = res.r + states.sensor
            | rejectattr('state', 'in', ['unavailable', 'unknown', None])
            | selectattr('entity_id', 'in', area_ents)
            | map(attribute='entity_id')
            | list
        %}
      {% endfor %}
    {% endif %}
    {{ res.r }}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working Low Battery Notification Issue related to the Low Battery Notification Unavailable Entities Notification Issue related to the Unavailable Entities Notification
Projects
None yet
Development

No branches or pull requests

2 participants