#In a blueprint i need to filter entities of a device, but how?

1 messages Β· Page 1 of 1 (latest)

pliant ember
#

I have a blueprint which selects a device, this works, but i need to filter the various entities inside the device as triggers for my automation and can't figure out how...

Tried to work it out in variables, but this didn't work.

variables: audiocontroller: !input ac_device volume_knob: >- {% for entity in device_entities(audiocontroller) -%} {%- if entity|regex_search("volume_knob") -%} {{- entity.entity_id -}} {%- endif -%} {%- endfor -%}

#

The device got 3 buttons, and a rotary decoder.

hexed pollen
#

Try just using
{{device_entities(audiocontroller) | select('search', 'volume_knob') | list | first}}

#

You can't generate a yaml list from a template and have it work

pliant ember
#

same issue... it's almost like the list of entities is empty, but the device is having those sensors...

#

and can't find (the right) documentation about blueprints. 😦 so it's a bit of a struggle to me.

hexed pollen
#

It's a single line template so needs double quotes around it

pliant ember
#

nope...

#

This is the code. maybe that will help πŸ˜‰

#

i import the device, device is giving 4 sensors

#

(if i get it for 1, i get it for all)

#

But as you can have multiple devices, the sensor names get a _1/2/3/4 appended

#

so i need to search i suppose

hexed pollen
#

What are the entity names for those?

pliant ember
#

default binary_sensor.play_pause, sensor.volume_knob, binary_sensor.next binary_sensor.previous

#

But having multiple devices, gives you this.

#

The device is to control audio volume for sonos speakers (or other media players) and as they are mounted to the wall, the controls on the speakers are unreachable. it works, despite my blueprint. (Also got a nfc reader inside to select playlists)

hexed pollen
#

Fair enough. Try using that template in developer tools

#

You'll be able to debug it easier there

pliant ember
#

in the dev template, it gives me [] if i do '{{ device_entities(xxxxx-my-device-id) }}'

hexed pollen
#

Are you sure you're using the right device id?
Try device_id('one of the entities')

pliant ember
#

nice, '' did the trick πŸ™ˆ

pliant ember
#

so got it in a trigger var now, only need to link it to the entity_id as i got the name now.

hexed pollen
#

Aren't you returning the entity_id from that filtered list?

pliant ember
#

no, i got the name

hexed pollen
#

The device name?

pliant ember
#

entity name

#

guess selectattr can give the id as well?

hexed pollen
#

sensor.volume_knob is the id

pliant ember
hexed pollen
#

All the things returned by device_entities are ids

#

Why have you stripped the "sensor." from the start of that?

pliant ember
#

trigger_variables:
audiocontroller_id: !input ac_device
audiocontroller_entities: '{{ device_entities(audiocontroller_id) }}'

volume_knob: >
{{
audiocontroller_entities | selectattr(None, "search", "sensor.volume_knob*") | list | last
}}

#

trigger:

  • platform: state
    entity_id: '{{ volume_knob }}'
    id: Volume
#

this is what i got now...

#

the trigger var seems to be filled

#

but the trigger says no

hexed pollen
#

Not selectattr... Just select

pliant ember
hexed pollen
#

Also your regex shouldn't have a * at the end

#

That's just making the "b" optional to multiple so it will accept volume_knobbbbb and volume_kno

pliant ember
#

okay, if i put it in the dev tool, it still gives me a name, not an id.

#

with the select, no *

hexed pollen
#

That's the id

pliant ember
#

but why does it still give the error than?

hexed pollen
#

Entity ids are not gibberish uuid strings

pliant ember
#

i expected a is like the device id

hexed pollen
#

Because apparently that doesn't like having a template in

hexed pollen
# pliant ember

Here you can see it hasn't rendered the template you've put in

pliant ember
#

seems it is in there πŸ˜–

hexed pollen
#

So it's working now?

pliant ember
#

no...

#

Still this one

hexed pollen
#

I don't know if you can use templates there, I think it unlikely

#

You might have to make a template trigger

pliant ember
#

looked at the nspanel blueprint, they do it the same.

#

hmm, not in the trigger part....

#

it once worked, about 2 years ago 😦 not sure when it got broken.

#

but var or trigger_var both won't work now

#

can make it a trigger on the device. no entity id.... with a extra step to get the right button

#

but conditions can't set ID's 😦

pliant ember
#

seems all i can do, is let the user select every entity instead of just 1 device 😦

#

In a blueprint i need to filter entities of a device, but how?

hexed pollen
#

Use a template trigger rather than a state one. That would be able to use your dynamic entity_id

pliant ember
#

will look into it tomorrow... thanks for your help!

#

need to see how i can make the template trigger react on a change in volume

hexed pollen
#

Tricky

pliant ember
#

yeah, converting a automation to a blueprint is actually rewriting everything 😦

flint geyser
#

For most things, device_id's can't use templates. A couple of exceptions, but you are best off using entity_id's only.

pliant ember
#

so people need to select 4 entities instead of 1 device? that doesn't make any sense. Home automation is about making things easier πŸ˜‰

#

and variables would help, but seems not available in trigger, even the trigger variables...

pliant ember
#

the difference between automations and blueprints maybe? as i want to keep it simple for users. if you have multiple of the same devices and need to remember entity id's instead of device names (which can be set to a logical name)

#

and in the trigger, entity id would be enough, but that's the issue here, we can't get them from the input device as state trigger