Entity_id: "insert template here" Inside an Automation *Media_player.join*

Howdy HA Friends!

I’m trying to configure some whole home audio with media_player.join.
I have multiple squeezelites that work and when manually joined by actions they work great.

alias: LMS CUSTOM Garagesqueeze Sync ON
description: Sync player to the lms_sync_master when the toggle is turned ON
triggers:
  - trigger: state
    entity_id:
      - input_boolean.lms_player6_sync
    from: null
    to: "on"
    for:
      hours: 0
      minutes: 0
      seconds: 3
conditions: []
actions:
  - action: media_player.join
    metadata: {}
    data:
      group_members:
        - media_player.garage_squeezelite
    target:
      entity_id: media_player.guest_squeezelite
mode: single

This basic automation works and my garage will join guest, no problem.

On my dashboard I have an input_select.lms_master_sync I would like to use this as the Target : Entity_ID, so that the master is selectable rather than hard coded into the automation.

I know the input_select works, as I can see the state change in dev tools. But how can I replace that entity ID with a template? I’ve tried with some AI to give me options but none seem to work. I’m banging my head against this one!

actions:
  - action: media_player.join
    metadata: {}
    data:
      group_members:
        - media_player.guest_squeezelite
    target:
      entity_id: 'media_player.{{states.input_select.lms_sync_master.state}}'

This is what I last tried with no bueno.

Any help would be much appreciated!

It is reccomended to use the states() function when possible as follows:

      entity_id: "media_player.{{ states('input_select.lms_sync_master') }}"

However, in order for your template to work, it will need to return an actual entity ID.

What do the options values of the input select look like? If they aren’t object id slugs, you will need to alter the template to get the right values.

states
This is what I have in dev tools for the input_select.

I think what you’re saying makes sense about the id slug, perhaps this is just a “text” and thus not templating correctly?.

Those look fine, as long as your media players have entity IDs like media_player.guestsqueeze, media_player.hallsqueeze… but based on your initial post that might not be the case i.e. media_player.guest_squeezelite

If all your media player entity IDs follow the same pattern, I would probably just use the “area” names as the options in the Input Select… “Hall”, “Guest”, "Kitchen, “Lounge”, “Master”, “Garage”. Those are easy for other people to understand. Then your template would be:

actions:
  - action: media_player.join
    metadata: {}
    data:
      group_members:
        - media_player.guest_squeezelite
    target:
      entity_id: "media_player.{{states('input_select.lms_sync_master')|slugify}}_squeezelite"
1 Like

Didgeridrew, I owe you a beer!

Thank you a bunch! I like the way you have formatted that, goes to show having multiple similar names for multiple similar devices gets confusing.