I’m new to Home Assistant and am after a bit of guidance. I’ve been reading through the wiki and trying to work this out but it’s eluding me.
Basically what I’m trying to create is for the living room light to switch off when I begin a Plex movie on either my living room TV (Android TV app) or living room ChromeCast. I then want the light to come back up to ~25% brightness when the movie finishes or is paused. Finally I only want this to happen after sunset (as why would I want my lights coming up during the day?).
I currently achieve this using Plex’s built-in webhook, which sends playback information in a JSON payload to a PHP script I’ve written, which does the relevant checks (client ID, media type, and time of day). If the checks pass the relevant command is then sent as a webhook to IFTTT, which then either switches off or on the light. It’s become apparent that this could all be replaced by Home Assistant, and would also be kept local (reducing points of failure and latency).
So far I’ve got everything recognised on HA, and can successfully use it’s webhooks in place of IFTTT to keep things local, however would be interested in replacing the Plex webhook and my PHP script with HA’s built-in functionality.
I’m able to bind an automation event to the relevant Plex clients state change, however I’m struggling with the conditions. How specifically do I extract and check the attribute data of a given device in HA? Ideally I’d need to check “media_content_type” from the relevant device to ensure the content being played back is a movie. I’ll also need to use this further when isolating ChromeCast streams, but I suspect doing so will be much simpler once I crack how to use attribute data as a condition.
From what I’ve read on the wiki a template condition of the following should work: value_template: "state_attr('media_player.plex_plex_for_android_tv_living_room_tv', 'media_content_type') == 'movie'"
But it doesn’t. Can anyone shed any light as to what I’m missing here?
Thanks for the idea. Switching the quotes had no effect though. No idea why it’d work for you and not for me. Does make me wonder if I’m going wrong elsewhere in the automation- as the template does seem to enumerate correctly in the dev tools -> template area.
I’m using the media player’s state changing to “playing” as the trigger. Don’t suppose you could share your automation yaml by any chance? So I could see the other approach.
I’m currently using a different player and different light for testing- as they’re easier to control directly from my PC. As it stands regardless of the “media_content_type” it’s still activating the light.
- id: Media_Plex_Dim_Movie_Play
alias: Media Plex Dim Movie Play
trigger:
- entity_id: sensor.plexmediatype
platform: state
to: Movies
condition:
- condition: state
entity_id: light.living_room
state: 'on'
action:
- data:
entity_id: script.lr_movie_dim
service: script.turn_on