you can find a flow example on google but for the moment i don’t use it …
Hi, I am further. Can play, pause, can next, skip etc. And I can do a “transferMyPlayback” to another device (alexa) via the device id.
Only thing not wokring for me i how to find and how to select waht playlist to play there…
Like this:
What should I put in the function node and how do I get a playlist id?
This does not work:
msg.params = [ {playlistId: "37i9dQZF1DWXmlLSKkfdAk"} ]; return msg;
and a lot of others also not
gives me:
{"_msgid":"2b1aaff.8d8e15","topic":"","payload":true,"params":[{"playlistId":"37i9dQZF1DWXmlLSKkfdAk"}],"error":"WebapiError: Bad Request"}
I’m having trouble finding examples, or getting the function node to supply the correct information for just simple things like specifying a playlist too.
Would you mind posting how you managed to do play pause, etc. and transfer my playback, please?
Edit: OK, I found another post with more examples: Spotify node-red interface
You an get the deviceids by sending a string of ‘true’ to get my devices, then looking at the debug console.
Then as above, use a function node with:
msg.params = [
['85202189a6blablsca22818c7383'],
{ play: true }
];
return msg;
msg.params = [ "3XubkIrRsDkykhyRsr8" ]; return msg;
in the function node for ‘getPlaylist’ returns my playlist in an array, but doesn’t play that playlist.
The same works for getPlaylistTracks
You can find the Spotifyid of the playlist by clicking on the 3 dots next to your playlist, then share, then copy spotify URI
Edit: Ok, you need to use play, rather than getPlaylist, and put this in the function node replacing your playlist uri
msg.params = [ {context_uri: "spotify:playlist:3XubktkkgujSVzMRsr8"} ]; return msg;
For setShuffle you need:
msg.params = [ "true" ]; return msg;
where true is to turn on shuffle. That’s probably enough edits for one post today. Hope it helps.
Thing is the device ids randomly change now and then and I do not know why…
That’s alarming, and certainly puts a spanner in the works of automation. What sort of device is changing device ID? So far I’ve only used my computer, and a bunch of Alexas, but they haven’t changed so far… touch wood, but then again I’ve only just started using it.
The getmydevices node might be able to help with automation, but it will take someone with more nous than me to pass variables. Another option might be able to use Home Assistant itself, with Spotcast…despite the name, it isn’t just a chromecast thing, but can broadcast to Alexas, computers, et cetera
For me only alexas change… and no answer so far…
Thanks for this. It solved my problems with invalid URI but now I have another issue. After agreeing to the permissions all I get is “401: Unauthorized.” Anyone have an idea why?
My Spotify integration within HA is working without any issues, I just can’t seem to get this to work in Node Red.
What have you done yourself?
for the moment same problem impossible for me to play and send playlist… could you share your flow please?
I have it working, but one thing I found (maybe it has bin mentioned) is that you have to have an active connection to the chromecast or speaker, for instance through a phone or pc, only the you can use it, the player goes idl ones not connected and it will not work
do you have a flow to share?
For Chromecast there are still some issues with invoking spotify from a non android device. Check the Spotcast custom component for a workaround.
it works with spotcast
but i want to use it without home assistant
Hi- @sender what do you mean by remove the oauth? From where and how, I’m facing the same issues. Would appreciate the help of you could outline the steps. Thanks!
I have done as you described but I get the error
{"_msgid":"fcbdb5bb.ed3928","topic":"","params":[{"deviceIds":["77c3c0a12cf8ef9ddca2dae79bdee811cc446f8d"],"play":"true"}],"err":"TypeError: Cannot read property 'play' of undefined"}
This is the code of my function node
msg.params = [ {deviceIds: ["77c3c0a12cf8ef9ddca2dae79bdee811cc446f8d"], play: 'true'} ]; return msg;
Any suggestions?
Found the wright way to write the code for the the code of the function node here.
Now my code looks like:
msg.params = [
['2006d991d90ff991fb772ccc649f8dfcf316ac51'], /* DeviceIds Array (but it can only handle one device id) */
{ play: true } /* Options Object */
];
return msg;
Node red flow
[{"id":"9fcff8a1.e11c18","type":"debug","z":"1ec70ae1.ce8cc5","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","x":890,"y":460,"wires":[]},{"id":"6e3b8927.c4256","type":"spotify","z":"1ec70ae1.ce8cc5","name":"","auth":"daae9818.5d9dc8","api":"transferMyPlayback","x":720,"y":460,"wires":[["9fcff8a1.e11c18"]]},{"id":"c3fde82d.b7bc38","type":"function","z":"1ec70ae1.ce8cc5","name":"Naar woonlamer","func":"\n\nmsg.params = [\n ['2006d991d90ff991fb772ccc649f8dfcf316ac51'], /* DeviceIds Array (but it can only handle one device id) */\n { play: true } /* Options Object */\n];\nreturn msg;\n","outputs":1,"noerr":0,"initialize":"","finalize":"","x":490,"y":460,"wires":[["6e3b8927.c4256"]]},{"id":"45085da9.3094f4","type":"inject","z":"1ec70ae1.ce8cc5","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"true","payloadType":"bool","x":320,"y":460,"wires":[["c3fde82d.b7bc38"]]},{"id":"daae9818.5d9dc8","type":"spotify-auth","name":"Spotify Sander","scope":"user-read-playback-position\nuser-read-playback-state\nuser-modify-playback-state\nuser-read-currently-playing\napp-remote-control\nstreaming"}]
Maybe this will help someone.
I also struggled to get Spotify authorized in Node Red. After following all steps I got a ‘401: Unauthorized’ message.
This seems to be the solution: When you see ‘401: Unauthorized’, select the URL in your address bar and hit Enter. Then you should see a ‘spotify.authorized’ message. Refresh won’t work.
I hope this helps other people. It took me some time to find this solution.
I’ve edited this because it used to work with a different format with state:“true”,but now it just wants “true”.
You can also just use an inject node with a msg.params = JSON
[ “true” ]
Rather than using an inject node of true, and then a function node with the parameters.
I also have that problem in Spotify authorization. do you have already a solution?