OH and the use of webhook from node-sonos-http-api

Hi all,

i use the node-sonos-http-api to control my sonos devices and it works very well. In the Api you can define a webhook to get a information when a sonos device change its state. That is very usefull to update the Items/Sitemaps when the device is controled by a sonos app or directly on the device (e.g. change the volume).

Is there someone who has implemented a callback/webhook in OH or have a tip to do that?

Thanks to all

I think the REST API will work:

Ok i try …

in the file settings.json from the node-sonos-http-api i add the webhook:

     "webhook": "http://localhost:8080/CMD?Node_Sonos_Http_Api"

so i additional define an item:

String Node_Sonos_Http_Api

and a rule to get the update:

rule "Node Sonos Http Api"
	Item Node_Sonos_Http_Api received update
	logInfo("Node Sonos Http Api", "Status: " + Node_Sonos_Http_Api.state)

But the state is empty (Uninitialized/Instanc = Null).
Is there a possibility to “debug” what is received by the REST-API and how i can decode the value.

The Api send’s a JSON like this:

  "type": "transport-state",
  "data": { (snapshot of player) }

You need to supply the new state in the URL:


If Node is sending the new state as text in the body of the request:

Likewise, you can send a status update using the HTTP verb PUT to the same uri, passing the new state as a plain string argument in the body (encoding text/plain).

In order to send a command to an item, you would use the item uri (http://localhost:8080/rest/items/Temperature_FF_Office) and send an HTTP POST with the according command in the request body as text/plain.

So the URL is different, you have to use an HTTP PUT or POST (depending on whether you want the new state to be received as an update or a command), and the content type needs to be text/plain, not text/json.

Thank you for show me the right track!

My solution is:

The webhook and the rule as described before. So i have a trigger every time the sonos environment changed a state or the topology.

In the rule i call (e.g.):

// Bad
var result = sendHttpGetRequest(“http://localhost:5005/bad/state”)
// Result:{“currentTrack”:{“artist”:"",“title”:“swr-mp3-m-swr3”,“album”:"",“albumArtURI”:"",“duration”:0,“uri”:“x-rincon-mp3radio://swr-mp3-m-swr3.akacast.akamaistream.net/7/720/137136/v1/gnl.akacast.akamaistream.net/swr-mp3-m-swr3”,“radioShowMetaData”:"",“absoluteAlbumArtURI”:"",“streamInfo”:“Angel in blue jeans / Train”,“type”:“track”},“nextTrack”:{“artist”:"",“title”:"",“album”:"",“albumArtURI”:"",“duration”:0,“uri”:""},“volume”:12,“mute”:false,“trackNo”:1,“elapsedTime”:0,“elapsedTimeFormatted”:“00:00”,“zoneState”:“PLAYING”,“playerState”:“PLAYING”,“zonePlayMode”:{“shuffle”:false,“repeat”:false,“crossfade”:false}}

logInfo(“Node Sonos Http Api”, "Result: " + result)

var String uri = transform(“JSONPATH”, “$.currentTrack.uri”, result)

logInfo(“Node Sonos Http Api”, "Uri: " + uri)
// if changed update the coresponding item … same for all other result data.

that works (nearly) perfekt as a alternative for the org. sonos-binding. So i hope i have no more UPNP errors and memory craches.

If you get this working well, you might consider adding a page on the wiki under Application Integration demonstrating how to integrate with the Sonos in this way.

I personally think it is as important to document these sorts of integrations that do not require a binding as it is to document the bindings themselves.


is there any replacement for the “/CMD?”-part of the webhook cmd for OH2.

I didn´t get any automatic updates on the “SonosNode_HttpApi”-item. But after updating the item manually, the attached rules (e.g. updat uri etc.) are working well.

Tried the following webhook config in the settings.json of the node-sonos-api

"webhook": "http://openhabianpi:8080/rest/items/SonosNode_HttpApi"
"webhook": "http://openhabianpi:8080/classicui/CMD?SonosNode_HttpApi"


— edit —
Got it working now! - There was a missing comma in the settings.json. Thanks for your explanations!