Alexa Integration Entity Filter

I am using the Alexa Smart Home Skill integration as well as the Alexa Device control custom integration.
Both are working flawlessly.

However, ASHS is announcing all the switches and sensors to Alexa that it discovers from the Echo devices. In other words, Alexa is sortof seeing itself in a loop.

I know that I can exclude entities by adding them to the exclude list.
However, do I need to add dozens of entities one by one, or can I do something like a wildcard.

exclude:
  - switch.*echo"
  - "Sensor.*echo*"

Unfortunately you have to list them one by one. Thereā€™s only 1 glob section that allows that syntax.

You can use template editor to make the config for you.

exclude:
{%- for s in states%}
{%- if 'echo' in s.entity_id %}
  - {{ s.entity_id }}
{%- endif %}
{%- endfor %}
2 Likes

You friend, are a GOD!

This was a great start for me, but my alexa integration returned devices that did not include the alexa / echo name. So I figured I should be able to filter by ā€œplatformā€ / ā€œintegrationā€.

I couldnā€™t find a way to do that in JINJA, but using the entity tracker file and some JSON magic, I was able to get all devices by ā€œplatformā€

cat .storage/core.entity_registry | jq -r '.data.entities[] | select(.platform == "alexa_media") | "- "+ .entity_id '

This will generate something like this

- alarm_control_panel.alexa_guard
- media_player.main_fire_tv
- media_player.everywhere
- media_player.echo_show_tv_room
1 Like

Found this old thread and hoped it would solve a very similar problem Iā€™m having. However the YAML parser is being particularly sensitive to whitespace and I can only get it pass as follows:

alexa:
  smart_home:
    filter:
      include_entities: >
        {% for s in states if s.attributes.expose -%}
        - {{ s.entity_id }}
        {% endfor %}

However I get the following error in the log:

Invalid config for [alexa]: Entity ID {% for s in states if s.attributes.expose -%} - {{ s.entity_id }} {% endfor %} is an invalid entity id for dictionary value @ data['alexa']['smart_home']['filter']['include_entities']. Got '{% for s in states if s.attributes.expose -%} - {{ s.entity_id }} {% endfor %}\n'. (See /config/configuration.yaml, line 31).

Other approaches like {{ states | selectattr('attributes.expose') | map(attribute='entity_id') | list | join(', ') }} donā€™t work either.

Any ideas?

EDIT: Does ā€œuse the template editorā€ mean generate the config and copy and paste it into the config? Is there no way at all to do it dynamically / programmatically?

Other creative ideas welcome as well.

@tgpaul did you manage to solve it? I have the same problem to filter entities for the Alexa integration.

No, I gave up on this, but I canā€™t recall if it was because it was a limitation of what could be enumerated or because attributes wouldnā€™t be set by the time the integration needed the device names. @petroā€™s post suggests that filtering is possible to some extent, but it likely didnā€™t meet my needs.

ooh too bad, thanks anyway, if I find a solution I will share it in here.
Cheers

Oh I think I remember now. I think I resolved that @petro literally meant to use the template editor to run the script and then copy/paste the result in the config. No dynamic solution possible without a change to the integration.

Correct, copy/paste is still the only solution