Rules for Sonos PLAY1 being ignored - Save/restore/volume

Hi, sorry if this is the wrong place to post this question, but after playing around with this issue (and getting more and more confused) i hope someone here can help me figuring out what’s going one.

First things first, i’m totally new playing with Openhab, so it’s entirely possible that i simple misunderstood something.

So, what i’m trying to do right now, is using my sonos as a doorbell, i’m using the buildin soundfile for this. Currently it looks as follows.

My items file - please note, the reason for both the notification sound and sonos volume being there, was for testing purposes. My guess in is, that in a perfect world, i only need Notification volume.

//Doorbell
Switch Sonos_play1_Save             "Save playlist"                         (gSonosPlay1)           {channel="sonos:PLAY1:RINCON_949F3E0338B401400:save"}
Switch Sonos_play1_Restore          "Restore playlist"                      (gSonosPlay1)           {channel="sonos:PLAY1:RINCON_949F3E0338B401400:restore"}
String Sonos_play1_Notification		"Notification Sound"	<songtitle>				             	{channel="sonos:PLAY1:RINCON_949F3E0338B401400:notificationsound"}
Dimmer Sonos_play1_NotificationVol	"Notification Volume"	<volume>				             	{channel="sonos:PLAY1:RINCON_949F3E0338B401400:notificationvolume"}
Dimmer Sonos_play1_Volume           "Sonos Volme"           <volume>                                {channel="sonos:PLAY1:RINCON_949F3E0338B401400:volume"}

My rule looks as follows. When in the current state it basically works, but with issues.

  1. The notification volume is not turned up
  2. If power has been off the speaker, it behaves irrationally (eg. reconnected the speaker, started some music which worked, pressing the doorbell button causes it to make the doorbell noice, but it doesen’t restore the music afterwards, it does find the correct title, but it doesen’t go to state “play” even if that was the state before, just as it doesen’t recall how far it was in the song.
rule "Doorbell on Sonos"
when
    Channel "deconz:switch:f9d485da:00158d000424ce32010012:buttonevent" triggered 1002
then
    sendCommand(Sonos_play1_Save, "ON") //saves what is currently playing    
    sendCommand(Sonos_play1_NotificationVol, 50) //sets the notification volume
   	sendCommand(Sonos_play1_Notification, "http://192.168.2.178:8080/static/doorbell.mp3")  //the sound file to play
    sendCommand(Sonos_play1_Restore, "ON") // restores the previously playing music
end

So, to make this work, i have tried the following (among others, but these i can remember off hand)

  1. Save the current volume level as a variable, and then use in a send command (failed totally, prop. due to me not knowing how to use variables in openhab, expected it to be like powershell or C#)
rule "Doorbell on Sonos"
when
    Channel "deconz:switch:f9d485da:00158d000424ce32010012:buttonevent" triggered 1002
then
    var Number savedvolume = Sonos_play1_Volume.state as Number
    sendCommand(Sonos_play1_Save, "ON") //saves what is currently playing    
    //sendCommand(Sonos_play1_NotificationVol, 50) //sets the notification volume
   	sendCommand(Sonos_play1_Notification, "http://192.168.2.178:8080/static/doorbell.mp3")  //the sound file to play
    sencCommand(Sonos_play1_volume, savedvolume)
    sendCommand(Sonos_play1_Restore, "ON") // restores the previously playing music
end
  1. tried manually adjusting the volume between the snapshots, which in terms worked, it turned the volume up, but when restoring, it doesen’t turn it down again.
rule "Doorbell on Sonos"
when
    Channel "deconz:switch:f9d485da:00158d000424ce32010012:buttonevent" triggered 1002
then
    sendCommand(Sonos_play1_Save, "ON") //saves what is currently playing    
    sendCommand(Sonos_play1_Volume, 40) //sets the notification volume
   	sendCommand(Sonos_play1_Notification, "http://192.168.2.178:8080/static/doorbell.mp3")  //the sound file to play
    sencCommand(Sonos_play1_volume, savedvolume)
end

I’m starting to run out of ideas, so everything would be appreciated.

See previousState info in doc’s here:

1 Like

Hi H102

Thanks for the reply.

Will try using that for the volume part, that might work :slight_smile: