Node Red play Spotify Playlist

Hi,

I try to setup an automation to play a specific Spotify playlist using the node-red-contrib-sonos-plus. I got it to work to play a specific radio station but not a Spotify playlist.

I use

group.queue.urispotify

mentioned in the documentation

[{"id":"3773986d1030e9a6","type":"sonos-universal","z":"b075e3b6096f9e8a","confignode":"20ab548b62696c0b","command":"group.queue.urispotify","state":"spotify:user:spotify:playlist:37i9dQZF1DXconM2hS1KVZ","stateType":"str","avoidCheckPlayerAvailability":false,"name":"","x":580,"y":140,"wires":[[]]},{"id":"20ab548b62696c0b","type":"sonos-config","name":"Sonos Wohnzimmer","serialnum":"94-9F-3E-C0-E6-6D:F","ipaddress":"192.168.178.34"}]

Thanks for your help.

1 Like

Can this be triggered with a service in HA? I’d say try it there to see if you can get it to work. If it’s not working in HA, it won’t work in NR.

It’s actually pretty easy to set it up to play a specific Spotify Playlist in HA. There is an onboard Service for Spotify but I want to have all my automations in Node RED.

Could you create an automation in HA and then post the yaml. It will be easier to understand the service call structure and how to convert it to nodered.

Edit: short of a typo I don’t see many options to change in the sonos node. I would set this up in a regular HA call service and see if it works that way. If does, you should probably open an issue on git for the sonos node.

Here is the yaml:

alias: Schlafzimmer - Spotify morgens einschalten nach Uhrzeit
description: ""
trigger:
  - platform: time
    at: input_datetime.wecker_zum_aufstehen
condition:
  - condition: state
    entity_id: input_select.status_dennis
    state: Im Bett
    enabled: true
action:
  - service: media_player.volume_set
    data:
      volume_level: 0.01
    target:
      entity_id: media_player.sonos_lautsprecher_schlafzimmer
  - service: media_player.play_media
    target:
      entity_id: media_player.sonos_lautsprecher_schlafzimmer
    data:
      media_content_id: >-
        spotify://f0ae3f3930f8b456c99f4dc82151e197/spotify:playlist:2TwygCUmV9hogNFqZZ4to2
      media_content_type: spotify://playlist
    metadata:
      title: "Wake Up Happy ☀️ Good Morning "
      thumbnail: https://i.scdn.co/image/ab67706c0000da84fbe1e1fcedbc2158f211b72f
      media_class: playlist
      children_media_class: track
      navigateIds:
        - {}
        - media_content_type: spotify://library
          media_content_id: spotify://f0ae3f3930f8b456c99f4dc82151e197
        - media_content_type: spotify://current_user_playlists
          media_content_id: spotify://f0ae3f3930f8b456c99f4dc82151e197/current_user_playlists
        - media_content_type: spotify://playlist
          media_content_id: >-
            spotify://f0ae3f3930f8b456c99f4dc82151e197/spotify:playlist:2TwygCUmV9hogNFqZZ4to2
  - service: media_player.shuffle_set
    data:
      shuffle: false
    target:
      entity_id: media_player.sonos_lautsprecher_schlafzimmer
  - service: media_player.media_next_track
    data: {}
    target:
      entity_id: media_player.sonos_lautsprecher_schlafzimmer
mode: single

I was just looking for a simple play a playlist, you know how they say baby steps.

From what I can gather from the docs this would be the data necessary for a play list service call.

{
   "media_content_id":"spotify://f0ae3f3930f8b456c99f4dc82151e197/spotify:playlist:2TwygCUmV9hogNFqZZ4to2",
   "media_content_type":"spotify://playlist",
   "enqueue": true
}

Although this I dont see the double path format you are using here.

spotify://f0ae3f3930f8b456c99f4dc82151e197/spotify:playlist:2TwygCUmV9hogNFqZZ4to2

It shows

"media_content_id":"spotify:playlist:2TwygCUmV9hogNFqZZ4to2"

btw I noticed the sonos node was updated 13 hours ago, are you using the most up to date version?

Edit you could try the single path for the playlist in the sonos node as well.

Thanks for your effort. I updated the sonos node and tried different commands as payload but couldn’t get it to work yet. :confused:

Can you call the playlist with a regular call service node?

I finally got it to work. :muscle: I had to add the playlist to my sonos favorites and change some commands.

[{"id":"55a48b98b63fd816","type":"tab","label":"Flow 2","disabled":false,"info":"","env":[]},{"id":"ba1154d844dfe40b","type":"sonos-universal","z":"55a48b98b63fd816","confignode":"8c8a29e41e894551","command":"player.set.volume","state":"3","stateType":"str","avoidCheckPlayerAvailability":false,"name":"","x":450,"y":140,"wires":[["162b294b3abc1386"]]},{"id":"c30e9e9488503787","type":"inject","z":"55a48b98b63fd816","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":160,"y":140,"wires":[["ba1154d844dfe40b"]]},{"id":"0573d9e723991a0f","type":"sonos-manage-mysonos","z":"55a48b98b63fd816","confignode":"8c8a29e41e894551","command":"mysonos.queue.item","state":"Wake Up Happy","stateType":"str","avoidCheckPlayerAvailability":false,"name":"","x":860,"y":140,"wires":[["c83dfc6869137402"]]},{"id":"162b294b3abc1386","type":"sonos-universal","z":"55a48b98b63fd816","confignode":"8c8a29e41e894551","command":"group.clear.queue","state":"","stateType":"str","avoidCheckPlayerAvailability":false,"name":"","x":650,"y":140,"wires":[["0573d9e723991a0f"]]},{"id":"c83dfc6869137402","type":"sonos-universal","z":"55a48b98b63fd816","confignode":"8c8a29e41e894551","command":"group.play.queue","state":"","stateType":"str","avoidCheckPlayerAvailability":false,"name":"","x":1090,"y":140,"wires":[[]]},{"id":"8c8a29e41e894551","type":"sonos-config","name":"Sonos Schlafzimmer","serialnum":"78-28-CA-B7-21-5C:0","ipaddress":"192.168.178.31"}]

Thanks for your help anyways. :smiling_face: