Hi everyone, I’m trying to set up an automation that switches on the Christmas lights around the house when a certain playlist is playing on Spotify. So far, I have the automation working so that the lights come on when Spotify begins playing anything. So, I think I just need a condition to specify a particular playlist?
Or, can I integrate it into the trigger itself? Thoughts? Here is what I have so far …
I’ve tried a couple of things with a condition template, but that caused the Automation to not fire at all.
alias: Christmas Lights On With Music
description: ''
trigger:
- platform: device
device_id: 931702cec66d567619611392ca2d142f
domain: media_player
entity_id: media_player.spotify_username
type: playing
condition: null
action:
- type: turn_on
device_id: 8ac31f89b6cf3d15681197a4057f240c
entity_id: switch.smart_plug_3_1
domain: switch
mode: single
Also, if anyone could help with making a list, that’d be great. So then I can have a bunch of playlists that fire the automation, instead of a bunch of automations …
Play the playlist on Spotify and then go in to the states tab in developer tools and look at the attributes column. See if there is anything in there that indicates something like a playlist_id ?
Is not valid at all.
How is Home Assistant supposed to know what it is looking for? Template means Template, you are essentially looking for an attribute on the media player entity.
If the template was valid, you aren’t even telling the automation what entity it needs to be looking at to see if there is a match.
value_template: >-
{{ "https://open.spotify.com/track/1aL92Falb9JQaD8xlLuDKA?si=QQamkV0pSW6qAb06gdODDw" in state_attr('media_player.spotify_brianna_mckenzie_au','media_content_id') and state_attr('media_player.spotify_brianna_mckenzie_au','media_content_type') == 'playlist' }}
Is a valid template for what you are looking for.
But I doubt it will work, because a Google for 1aL92Falb9JQaD8xlLuDKA returns “Count on Christmas” so the condition would only ever match when you were playing the Playlist AND the song was Count on Christmas. It’s also not clear what the ?si parameter is - if that changes each time you start the playlist, and a Google suggests that it probably will, then it will never match. You need to be looking for something that indicates the PlaylistID and stays they same no matter what track from the playlist is currently playing.
I play a playlist spotify has made for me called Daily Mix 1. In dev tools there is an attribute media_playlist: Daily Mix 1
However I see a problem. If you are playing ordinary music, then switch to a Christmas Playlist then the state will not change from idle to playing. Or will it?
I can’t get spotifiy working for long enough to try!
Just set the trigger to the media_player but don’t have a to or from state, so it will trigger on all states. Or better yet, have the trigger skip checking the state of the media player, and instead have it trigger on any change to the media_playlist attribute.