#Negating the integration filter on a selector?
1 messages · Page 1 of 1 (latest)
I don't think it's possible. You could make the script handle it to set a persistent notification that a unsupported entity is selected.
Why not that one integration?
In this specific script I want to do TTS announcements on smart speakers, and specifically I want to use notify.alexa_media on Echos so it uses their native TTS, but tts.cloud_say on generic speakers, so I was hoping I could have one field that lets me select only Echos and one that lets me select media players that are not Echos.
Ahh, then I would just make a single field. But when you want to do the TTS, just filter between Alexa and non-alexa
hmm, how would I filter the array of entity IDs by which integration they're from?
{% set alexa_entities = input_entities | select('in', integration_entities('alexa_media')) | list %}
And the others:
{% set non_alexa_entities = input_entities | reject('in', integration_entities('alexa_media')) | list %}
nice, thanks
I feel like I’m probably missing something because that ended up way more complex than I expected, to be able to work with all the possible ways the entity selector can output things, but it works.
Looks nice. But isn't all the extra work just to make sure it's a list? And also filter non media players? For last you could also trust the UI and just let it make errors when people force in a non-media player
Ah, yeah, also to support devices, area's etc. Yeahhhhhh, that's a bit of a mess indeed
I just never messed with targets and just force entity id 😄
it's because you used the target selector not the entity selector
also, just cause I looked at it again, that template can be drastically simplified
sry, got sidetracked
anyways, simplified
expanded_targets: >
{# Create the namespace object we'll use to store all our working data #}
{% set data = namespace(expanded_targets=[]) %}
{% macro dummy(someValue, returns) %}
{% do returns(someValue) %}
{% endmacro %}
{# Declare our helper macros as functions, so they can return values #}
{% set dummy = dummy | as_function %}
{% set funcs = {"device_id": device_entities, "area_id": area_entities, "label_id": label_entities} %}
{% for key, value in target.items() %}
{% set entities = funcs.get(key, dummy) %}
{% set items = [value] if value is not list else value %}
{% set data.expanded_targets = data.expanded_targets + entities(value) | select("match", "media_player") | list %}
{% endfor %}
{{ data.expanded_targets | unique | list }}
You were doing a couple things that weren't necessary:
- No need to create a macro when you use it once unless you need a function.
- use a dictionary when possible if you're matching keys and provide a default for everything else
- You're using expand on a list of entities to get the entity_id, when it's already a list of entity_ids. That's effectively slowing your template down considerably. Just use the list of entities that you already have.