I am all new to Node-RED and have been struggling quite a bit to figure this out.
I have created a flow for my Xiaomi cube to control media player audio on one of my SONOS speakers. All basic functions are working great, but I have a wish to expand with the following functionalities…:
Make of one the cube actions switch between my SONOS favorites (either automatically by pulling all favorites from the media player entity in HA or just by switching between a list of favorites defined by myself… whatever works.
The current flow already support activating a predefined favorite using a call service node (see screenshot), but I cannot figure out how to make node-red switch between a list of favorites activated by the same cube action type.
Ultimately I would like a TTS announcement just prior to start playing the media in the speakers (this is probably the most tricky part).
Just tried and yes, the check state node actually reveals the full list of available favorites (or the “source-list”) in the attributes… see screenshot.
So the attribute “source-list” holds my current 4 favorites… Any idea how to use this?
That’s good but I did not see in the attributes the current playing playlist. If you select one and play one does it come as an attribute the current playlist ?
But the flow is not fool proof, as you need to add a bunch of other checks, what would happen if you remove the current playing playlist, or one gets added, you need to keep checking. Don’t forget to fill the entity id.
I don’t know what integration you’re using (I use zigbee2mqtt) but when I do a flip90 or flip180 it tells me what side it landed on.
I’m not familiar with Sonos but you could just assign each side to a playlist, so flipping the cube around switches between them.
I use rotate_left and rotate_right for volume up/down (makes more sense, like a volume knob). Slide or move to skip current track, flip90 for play/pause.
Regarding the checks you are mentioning. Why wouldn’t it matter if a new playlist is added? Will the code not just always flow between the playlist available to HA?
Thank you for your inputs. However this is not the solution I am searching for. I already have a static playlist assigned to one of the cube functions, but what I really like is for the automation to automatically switch between all playlists available (basically making it more dynamic and less complex to use).
The code made by subzero79 does the trick in a very elegant way.