Hey all I’m trying to have my lights turn on and off depending on only if Plex is playing on a specific Chromecast. I have it working without the Plex condition just fine e.g…
# When Plex plays to "CR Chromecast" turn off Computer Room lights
- alias: "Media starts, lights off"
trigger:
- platform: state
entity_id: media_player.cr_chromecast
to: 'playing'
from: 'idle'
action:
service: scene.turn_on
entity_id: scene.media_play
I imagine the condition would go something like the following (in English):
# When Plex plays to "CR Chromecast" turn off Computer Room lights
- alias: "Media starts, lights off"
trigger:
- platform: state
entity_id: media_player.cr_chromecast
to: 'playing'
from: 'idle'
condition:
"stream source equals plex"
action:
service: scene.turn_on
entity_id: scene.media_play
I am unsure of what the correct syntax would be. Is there some documentation to point me to, I couldn’t find any or has someone accomplished this before? I’d don’t want my computer room lights to not turn off if I’m simply throwing a quick YouTube video, or casting music. I am pretty sure I have Plex connected correctly as “sensor.plex” is showing up as an entity_id that gives the number of current streams. Any help would be appreciated!
I just did something similar with the plex media player component. Trigger was the plex media player on the xbox, conditions were that the xbox was on and the lights were on. The action was to change the brightness of the lights right down during playing, lighter during paused and full lights during idle.
I must not have the plex component working then. I never see a media_player.plex or media_player.plex_server_name in my entity list. I’ll need to dig since I don’t see any errors in home_assistant.log.
Thanks for the help everyone. I was able to get this working. Here is the example script in case any one in the future comes across it. I followed Bob_NL’x example, but for some reason my condition needed the quotes around Plex. Tested against other casting apps besides Plex and they did not trigger the automation rule.
# When Plex plays to "CR Chromecast" turn off Computer Room lights
- alias: "Media starts, lights off"
trigger:
- platform: state
entity_id: media_player.cr_chromecast
to: 'playing'
condition:
condition: template
value_template: '{{ states.media_player.cr_chromecast.attributes.app_name == "Plex" }}'
action:
service: scene.turn_on
entity_id: scene.media_play