Hi,
i want to join my sonos speaker to one actual running speaker when I enter a room by the occupancy sensor. I could not get the target template working to get the entity_id…
The automation throw the error:
Error rendering service target template: UndefinedError: ‘media_player’ is undefined
Any chance to get some help here?
trigger:
- platform: state
entity_id:
- binary_sensor.ankleidesensor_occupancy
condition:
- condition: state
entity_id: media_player.sonos
state: "on"
action:
- service: media_player.join
data:
group_members:
- media_player.{{ area_name(trigger.entity_id) }}
target:
entity_id: |
{% if media_player.wohnzimmer == 'playing' %}
media_player.wohnzimmer
{% elif media_player.toilettenbox == 'playing' %}
media_player.toilettenbox
{% elif media_player.kueche == 'playing' %}
media_player.kueche
{% elif media_player.bad == 'playing' %}
media_player.bad
{% elif media_player.ankleide == 'playing' %}
media_player.ankleide
{% elif media_player.schlafzimmer == 'playing' %}
media_player.schlafzimmer
{% endif%}
alias: Join Room