Using Spotify through Node Red

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?

1 Like

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.

2 Likes

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.

4 Likes

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.

https://i.imgur.com/61aT6DB.png

2021-01-09

I also have that problem in Spotify authorization. do you have already a solution?

I had to use this in my inject node

image

So my function node in my flow for setting shuffle looks like this
image

I had the same I had to replace the https:// in to http:// in the url

Mine seems to work with both [ “true” ] and [ true ]

I’m looking for a way to “search” music.
I have already tried some variants, but unfortunately did not bring any success.
At the moment I’m trying to solve this with an “input_text”. But I also don’t know if this is the right way?!?

Interesting in getting this working to search for a song and play it. Unfortunately, I’ve no idea where to start. I’ve authenticated and I can play and pause on a selected device but that’s about it

hey,
I have a few questions about Spotify…
is it possible for me to tell Spotify to play a specific playlist through a flow?
I just can’t find the right node

Force reload the page by clicking the URL and hit “enter”. This helped me several times

Click the URL and hit enter in your browser. This solved this issue several times for me

Hello. I’m testing this spotify on my nodered but I’ve a little problem.
I’m able to send my playlist id and then play with shuffle, but if I try to choose as device my iphone, it don’t work.
It works only and only if I already have Spotify open on my iphone. Is there no way to make it always work?

Could you please share that chunck of code please?

the first node is my flic Button (injection)…then turn on bathroom lights, and first function select my device (iphone):

msg.params = [
    ['xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx'], /* DeviceIds Array (but it can only handle one device id) */
    { play: true }, /* Options Object */
]
return msg;

then Transfer
and function play with this code

msg.params =
    [{ context_uri: "spotify:playlist:0mnzWKMowbO9iLJTQ2oHkf"}],
    { play: true };
return msg;

for select my playlist.
the only problem is my Iphone, if is in standby, or without Spotify app open, doesn’t work

1 Like

dutch_guy Thank you very much the select URL and hit enter worked. I’ve been battling with this for days. Kind regards, Jason

Hi all,

long long long time ago I used this. And since there is a bug in the HA spotify integration for me I am ending up here again.

I had no success anymore with the node red nodes for spotify. i got:
image

But nothing happens in my spotify.

then I deleted the Oauth2 node:
image

And I struggled about 1 hour to get it back again… url decoding, forwarding ports, reverse proxies… what a hell and a mess. But it in the end successfully authenticated again.

But now it still does not work… I get:

but nothing happens anymore in Spotify.

Is anyone of you still using above successfully?

Awesome! Thanks - that did the trick :smiley:

Not sure if this helps you guys or not, but thought I would mention it.
The SpotifyPlus Integration custom component adds extended support for Home Assistant and Spotify premium account users.

Features

  • Provides 97 custom services to support 99% of the Spotify Web API functionality.
  • Provides additional services beyond Spotify Web API - e.g. PlayerMediaPlayTrackFavorites, etc.
  • Search Spotify catalog for all media types (tracks, playlists, albums, artists, shows, audiobooks, episodes, categories, etc).
  • Supports the Spotify Connect Protocol, including Sonos support.
  • Supports SpotifyConnect AddOn, spotifyd service, and librespot devices.

Requirements

  • A Spotify Premium account is required.
  • Home Assistant 2024.10+ release.

Limitations

  • Limited control of Google Chromecast devices. Chromecast devices are currently not fully supported by the SpotifyPlus integration. You can perform player functions (e.g. pause, resume, next track, etc) if the device is the currently active player, but you can’t wake up a device or initiate play of tracks / context.

More Information

Hope it helps!