thomasloven / lovelace-auto-entities

🔹Automatically populate the entities-list of lovelace cards
MIT License
1.19k stars 111 forks source link

Possible to filter based on start of attribute and/or first listed attribute in an array? #373

Open lazyboy0172 opened 11 months ago

lazyboy0172 commented 11 months ago

I'm slightly going mad trying to get to a place where I can use custom:mini-media-player with sonos speakers and auto-entities Only when the speaker is the leader of the group.

This can be determined if the entity is the first in the list of entities on the attribute 'group_members'. I've accomplished this in a template, but auto-entities currently doesn't allow a custom type for templates. So my next attempt was to list my individual sonos speakers as separate include clauses, with the qualifier that group_members must start with their entity_id. Longer yaml, but I don't have All that many speakers, so I can live with it for now. However, I'm not having any success when trying to determine if the entity is the first in the group.

for example, my first attempt at this produced no results:

so I opened it up a bit to: group_members: /media_player.basement/ which also produced nothing.

I was able to get results via stringification, testing: group_members: $$/media_player.basement/ which successfully gave me the speaker. Unfortunately this just finds that string anywhere in the attribute, so even if it's not listed first and thus is not the leader of the group it will still pass the condition.

So, I moved on to: group_members: $$/^media_player.basement/ which again brought me no results, despite media_player.basement being the first listed item on the group_members attribute in developer tools and knowing that that particular speaker is the leader in the sonos app (and it working correctly in my template condition)

So I'm not sure if I'm just completely ignorant (well, I know I am, but anyway..) and perhaps the ^ is not the proper qualifier to get the start of this particular string/array? or maybe what I'm trying just isn't possible here due to something with stringification that I'm also ignorant on? After fighting with it for a few hours tonight I've decided to give up and reach out for help here. Hopefully someone much more knowledgeable in regex, auto-entities, or if they have a similar setup they can help me. I feel like I'm very close to getting what I want as an end result in 2 different ways between the template or this filter but have so far been thwarted both times.