Thanks Paul,
I got it to work now. My initial problem was, that the file barking.mp3 which is delivered with openHAB in openhab-conf/Sounds is coded with a sampling rate which is not supported by sonos
However, even when trying your URL for the doorbell (http://192.168.1.20:8080/static/doorbell.mp3) it did not work for me.
What worked out was the doorbell.mp3 file delivered with openhab, as sonos if fine with that file. So I copied it to openhab-conf/html and then it worked.
I did a setup from scratch with your code as the basis (but w/o the timers) as
var Timer doorbellTimer = null
shows an EOL error for me.
I like the save / restore portion which I learned from your code about. Thanks
So what I did now (and maybe oversized) is, that I used the dash button trigger event to trigger a (“virtual” Switch Item which then is linked to a similar rule as yours.
If anyone tries to do the same with a dash button (and if you find a way to do it smarter with less code please let me know), here it is:
Here we go with the items:
// Items for my Bathroom (bad in german language)
Player og_bad_sonos_ctrl "Control [%s]" (Sonos) { channel="sonos:PLAY1:RINCON_949F3Exxxxxxx1400:control" }
Dimmer og_bad_sonos_volume "Volume [%.1f %%]" <soundvolume> (Sonos) { channel="sonos:PLAY1:RINCON_949F3Exxxxxxx1400:volume" }
Switch og_bad_sonos_mute "Mute" <soundvolume_mute> (Sonos) { channel="sonos:PLAY1:RINCON_949F3Exxxxxxx1400:mute" }
Switch og_bad_sonos_led "LED" <switch> (Sonos) { channel="sonos:PLAY1:RINCON_949F3Exxxxxxx1400:led" }
String og_bad_sonos_CurrentTrack "Now Playing [%s]" <text> (Sonos) { channel="sonos:PLAY1:RINCON_949F3Exxxxxxx1400:currenttrack" }
String og_bad_sonos_state "Status [%s]" <text> (Sonos) { channel="sonos:PLAY1:RINCON_949F3Exxxxxxx1400:state" }
String og_bad_sonos_Notification "Notification Sound" <songtitle> (Sonos) { channel="sonos:PLAY1:RINCON_949F3Exxxxxxx1400:notificationsound" }
Dimmer og_bad_sonos_NotificationVol "Notification Volume" <volume> (Sonos) { channel="sonos:PLAY1:RINCON_949F3Exxxxxxx1400:notificationvolume" }
Switch og_bad_sonos_Save "Save Playlist" (Sonos) { channel="sonos:PLAY1:RINCON_949F3Exxxxxxx1400:save" }
Switch og_bad_sonos_Restore "Restore Playlist" (Sonos) { channel="sonos:PLAY1:RINCON_949F3Exxxxxxx1400:restore" }
// virtual Switch Item for Amazon Alexa to switch sonos to PLAY/PAUSE via respective rule
Switch og_bad_sonos_PlayOrPauseRadio "Sonos im Bad" [ "Switchable" ]
// virtual Switch Item for Amazon Dash button to play from file
Switch og_bad_sonos_panic "Panic Switch Item" [ "Switchable" ]
And the rules:
// Play or pause bathroom speakers, toggle with Dash 1 Button
rule "Dash 1 pressed to trigger sonos bad"
when
Channel "amazondashbutton:dashbutton:ac-63-be-zz-yy-xx:press" triggered
then
if (og_bad_sonos_ctrl.state.toString == "PLAY") {
og_bad_sonos_ctrl.sendCommand(PAUSE)
}
else if (og_bad_sonos_ctrl.state.toString == "PAUSE") {
og_bad_sonos_ctrl.sendCommand(PLAY)
}
end
// Toggle virtual switch item to ON / OFF Dash 2 Button - Part 1
rule "Panic dash button"
when
Channel "amazondashbutton:dashbutton:ac-63-be-xx-yy-zz:press" triggered
then
if (og_bad_sonos_panic.state.toString == "ON") {
og_bad_sonos_panic.sendCommand(OFF)
} else {
og_bad_sonos_panic.sendCommand(ON)
}
end
// Toggle virtual switch item to ON / OFF Dash 2 Button - Part 2
rule "Panic received update"
when
Item og_bad_sonos_panic received update
then
logInfo("Panic button pressed", "Someone needs help at the door")
sendCommand(og_bad_sonos_Save, "ON") //saves what is currently playing
sendCommand(og_bad_sonos_NotificationVol, "50") //sets the notification volume
sendCommand(og_bad_sonos_Notification, "http://10.82.1.yyy:8080/static/doorbell.mp3") //the sound file to play
sendCommand(og_bad_sonos_Restore, "ON") // restores the previously playing music
end
// Play or pause bathroom speakers, with Alexa
rule "play or pause bathroom speakers"
when
Item og_bad_sonos_PlayOrPauseRadio received update
then
if (og_bad_sonos_PlayOrPauseRadio.state==ON) {
sendCommand(og_bad_sonos_ctrl, PLAY)
} else {
sendCommand(og_bad_sonos_ctrl, PAUSE)
}
end
I am quite sure that I might not need both rules for the Panic button and somehow can live with the trigger channel from the dash button, but at least this works now.
Uwe