I have a stereo receiver media_player.gym_receiver
that I want to either play audio from the TV (source=TV Audio) or play music through a Chromecast device (Source=Media Player). I want the chromecast device to dictate the source. If the Chromecast device is “playing” I want the source to be Media Center. Otherwise, I want the source to be on TV Audio.
I’ve tried this code but it doesn’t work.
alias: Gym Audio - Switch source based on what's playing
description: ""
trigger:
- platform: state
entity_id:
- switch.gym_speakers
condition: []
action:
- service: media_player.select_source
data:
source: {{'Media Player' if trigger.to_state.state == 'Playing' else 'TV Audio' }}
target:
entity_id: media_player.gym_receiver
mode: single
Any idea how to make this work?