Extracting Values from SONOS Message

410 views
Skip to first unread message

Simon Schmid

unread,
May 10, 2018, 9:47:58 AM5/10/18
to Node-RED
Hello, i'm pretty New to Node-red functions, but couldn't find a soulution for that.

But i'm pretty shure it's pretty basic stuff:

From the SONOS Node i get the object:

msg : Objectobject
_msgid: "abea4022.ca2cf"
topic: ""
payload: "01 De Zaubertrak"
track: object
title: "01 De Zaubertrak"
artist: "Globi"
album: "Globi bei den Kelten"
albumArtURI: null
position: 190
duration: 200
albumArtURL: null
uri: "x-file-cifs://melon.local/iTunes/iTunes/iTunes%20Media/Music/Globi/Globi%20bei%20den%20Kelten/01%2001%20De%20Zaubertrak.mp3"
queuePosition: 18
volume: 23
normalized_volume: 0.23
state: "playing"
muted: false


I want to extract values like Title, Artist, albumArtURL (bad example here) and Volume to Display it on the Dashboard.
I start simple with the Volume value, like this, but with no success:

var msg = msg.volume;
return msg;


I get the Debug Error: function : (error)"Function tried to send a message of type number"

Can you help me how to get from the above Object a function node with 4 msg outputs to display the values.

Mark Setrem

unread,
May 10, 2018, 9:58:15 AM5/10/18
to Node-RED
There are a couple of pages in the docs that should help you...

1) https://nodered.org/docs/user-guide/messages - explains how to work with messages 

2) https://nodered.org/docs/writing-functions - explains how to send multiple messages


The other thing that you need to do is work with objects rather than variables.
In general Node-RED uses msg.payload for the "important" piece of info.  So in your example you would do

msg.payload = msg.volume;
return msg;


steve rickus

unread,
May 10, 2018, 9:12:24 PM5/10/18
to Node-RED
Simon,
If all you need to do is extract the value of a field like msg.volume, it's simpler to use a change node to "Set:" msg.payload "to" msg.volume (or whatever field you want). Just make sure to use the "msg." pulldown option and type in the property name "volume" (don't type msg.payload into the "AZ" string option).

Simon Schmid

unread,
May 11, 2018, 2:28:21 AM5/11/18
to node...@googlegroups.com
Thank you Guys I had first sucess and for the valies in an integratet object it was msg.track.title. it's pretty cool!

--
http://nodered.org
 
Join us on Slack to continue the conversation: http://nodered.org/slack
---
You received this message because you are subscribed to the Google Groups "Node-RED" group.
To unsubscribe from this group and stop receiving emails from it, send an email to node-red+u...@googlegroups.com.
To post to this group, send email to node...@googlegroups.com.
Visit this group at https://groups.google.com/group/node-red.
To view this discussion on the web, visit https://groups.google.com/d/msgid/node-red/53c58c7c-a780-4182-9423-41d7f8bea666%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Joe Morris

unread,
May 16, 2018, 7:11:18 PM5/16/18
to Node-RED
Simon, Are you working with the new Sonos API?
Reply all
Reply to author
Forward
0 new messages