Is this possible at all? Something like media_player.plex_* ? If so, could someone share how with me?
I then would use such a group with expand as the entities argument in a state trigger. Specifically I want to include it in the automation here - I have lots of tablets, TVs, laptops, phones, etc which are Plex media players. It’s not going to be at all easy to add them all manually to this automation (or, even to a group) . Simple notifications when Plex is playing - #20 by jamesking
Groups created this way are not restart safe and will not update without calling the service again, so you will need to set up an automation to handle those occurences.
select('search','.plex_')
^^^^^^
This is a regex pattern
Because it’s a regex pattern, the period has special meaning (it matches any single character) and will not be interpreted exclusively as a literal period. For this particular application (where you want to match a literal period exclusively) its special meaning should be escaped by prepending a backslash.
Thank you. you have explained it so well. These filters are so powerful. I really enjoy this - I can read the filters, understand what they are doing, but don’t know them well enough to design/think up solutions myself!
I am grateful to you for taking the time to help.
In the end I am not sure this is working how I want as I am trying to expand this group that I create in the entity_id of a state trigger of an automation; which doesn’t appear to work (!). (can see here if you want to know how wrong I have got it ) I think perhaps it’s not possible to do what I want to do.
But the automatic groups like this will be super useful in future!
Thank you for this thread.
I am trying to use this to create a dynamic group with wll the members connected to my wifi mesh devices.
service: group.set
data:
object_id: fritz_clients_rep_kueche
name: Geräte an Fritz Küche
icon: mdi:network-outline
entities: >
{{ states.device_tracker | selectattr('connected_to', 'match', 'fritz-Rep-1200ax-Kueche')
| map(attribute='friendly_name') | list }}
The group is created if I run the group.set, but the state of it is unknown even though some devices are connected to this very repeater.
Any suggestion what could be wrong in my code?
Of course - Stupid me.
The friendly name is not unique for identifying the entity.
Thank you!
But I still get unknown only - even if I check right before if there is at least one device connected:
I also tried 'eq' instead of 'match' and used the exact text with no luck.
EDIT: It works if I match object_id but not connected_to
In the example I posted in March 2022, the template uses selectattr to select object_id.
object_id is a property of an entity’s State Object.
attributes is another property of a State Object and, as explained in the documentation, it contains a dictionary. Each key in the dictionary is an “attribute”. For example, your sensor has source_type, ip, mac, etc. These are all keys in the dictionary contained within the attributes property.
So if you want to use selectattr() to get the value of a key in the attributes dictionary (such as connection_type), you reference it using attributes.connection_type.
Thank you for the explanation.
That totally makes sense.
I usually just use states of an entity, so I was not aware of this difference to attributes.
I guess I was irritated by selectattr and assumed I can „select“ also attributes.
Thanks again for your help.