i use openhab2 for my sonos and Sonoff Devices. In our Floor i have a touchscreen for the Habpanel and our Smartphones uses the Openhab app.
Now i want to create a Button, who send some commands on my sonos in the bedroom.
Our daughter sleeps well with a song. Every Day we have to set up the sonos with the playlist in favorites, change the Volume and remove it from groups.
Its very uncomfortable, so i want it.
is it possible?
I wrote a little rule, but i dont know, how i may trigger the rule with a button on habpanel oder openhab app.
Rule
rule "Sleep"
when
Item TestSleep received command ON
then
sendCommand (sonos:PLAY5:RINCON_949F3E554A3A01400:remove, ALL)
sendCommand (sonos:PLAY5:RINCON_949F3E554A3A01400:volume, 25)
sendCommand (sonos:PLAY5:RINCON_949F3E554A3A01400:repeat, ONE)
sendCommand (sonos:PLAY5:RINCON_949F3E554A3A01400:favorite, "Emina Schlafplaylist")
end
Rule
rule “Sleep”
when
Item Sleep_Switch changed from OFF to ON
then
sendCommand (sonos:PLAY5:RINCON_949F3E554A3A01400:remove, ALL)
sendCommand (sonos:PLAY5:RINCON_949F3E554A3A01400:volume, 25)
sendCommand (sonos:PLAY5:RINCON_949F3E554A3A01400:repeat, ONE)
sendCommand (sonos:PLAY5:RINCON_949F3E554A3A01400:favorite, “Emina Schlafplaylist”)
end
Item Switch Sleep_Switch "Schlafenszeit"
If i click in Openhab Habpanel:
Logs:
2019-07-04 19:55:38.148 [vent.ItemStateChangedEvent] - Sleep_Switch changed from ON to OFF
2019-07-04 19:55:38.969 [ome.event.ItemCommandEvent] - Item ‘Sleep_Switch’ received command ON
2019-07-04 19:55:38.970 [vent.ItemStateChangedEvent] - Sleep_Switch changed from OFF to ON
allthough I’m not an expert on the sonos-rules I think you are using the channel and not the item-name. I’d suggest to comment-out all the lines and then remove the comment 1-by-1. This way you can find what’s causing the issue.
You can add logging which might help too.
rule “Sleep”
when
Item Sleep_Switch changed from OFF to ON
then
logInfo("debug rule", "step-1")
sendCommand (sonos:PLAY5:RINCON_949F3E554A3A01400:remove, ALL)
logInfo("debug rule","step-2")
//sendCommand (sonos:PLAY5:RINCON_949F3E554A3A01400:volume, 25)
//sendCommand (sonos:PLAY5:RINCON_949F3E554A3A01400:repeat, ONE)
//sendCommand (sonos:PLAY5:RINCON_949F3E554A3A01400:favorite, “Emina Schlafplaylist”)
end
rule “Schlafenszeit”
when
Item Sleep_Switch changed from OFF to ON
then
sendCommand (SON_rep, ONE)
sendCommand (SON_vol, 10)
sendCommands (SON_fav, “Emina Schlafplaylist”)
end
at the moment i remove the “remove”. Iam not sure, how it works correct.
all models are loaded (openhab2.log).
if i click now i get this:
2019-07-04 21:04:26.193 [ERROR] [ntime.internal.engine.RuleEngineImpl] - Rule ‘Schlafenszeit’: An error occurred during the script execution: Could not invoke method: org.eclipse.smarthome.model.script.actions.BusEvent.sendCommand(org.eclipse.smarthome.core.items.Item,org.eclipse.smarthome.core.types.Command) on instance: null
2019-07-04 21:15:13.330 [ERROR] [ntime.internal.engine.RuleEngineImpl] - Rule ‘Schlafenszeit’: An error occurred during the script execution: Could not invoke method: org.eclipse.smarthome.model.script.actions.BusEvent.sendCommand(org.eclipse.smarthome.core.items.Item,org.eclipse.smarthome.core.types.Command) on instance: null
Rule
rule “Schlafenszeit”
when
Item Sleep_Switch changed from OFF to ON
then
sonos_PLAY5_RINCON_949F3E554A3A01400_repeat.sendCommand(ONE)
end
i tried with SON_fav and my created items above too. Same problem again.
I tried to use the automatic generated strings of openhab2. In Habpanel i can see all strings.
I created own items to test this rule.
i forgot the “” in (“ONE”).
now it works! Thank you.
UPDATE:
It works great.
Items:
Switch Sleep_Switch “Schlafenszeit”
Rules:
Sleep 1
rule “Schlafenszeit 1”
when
Item Sleep_Switch changed from OFF to ON
then
sonos_PLAY5_RINCON_949F3E554A3A01400_volume.sendCommand(“10”)
sonos_PLAY5_RINCON_949F3E554A3A01400_remove.sendCommand(“RINCON_949F3E554A3A01400”) //Bad1
sonos_PLAY5_RINCON_949F3E554A3A01400_remove.sendCommand(“RINCON_949F3E21212201400”) //Wohnzimmer
sonos_PLAY5_RINCON_949F3E554A3A01400_remove.sendCommand(“RINCON_949F3E7C1A3601400”) //Küche
sonos_PLAY5_RINCON_949F3E554A3A01400_remove.sendCommand(“RINCON_7828CAF0E85001400”) //Flur
//sonos_PLAY5_RINCON_949F3E554A3A01400_remove.sendCommand(“RINCON_949F3E554A3A01400”)
sonos_PLAY5_RINCON_949F3E554A3A01400_favorite.sendCommand(“Schlaf mein Prinz schlaf ein - Mozarts Wiegenlied.mp3”)
end
Sleep 2
rule “Schlafenszeit 2”
when
Item Sleep_Switch changed from ON to OFF
then
sonos_PLAY5_RINCON_949F3E554A3A01400_playqueue.sendCommand(“ON”)
sonos_PLAY5_RINCON_949F3E554A3A01400_volume.sendCommand(“10”)
sonos_PLAY5_RINCON_949F3E554A3A01400_repeat.sendCommand(“OFF”)
sonos_PLAY5_RINCON_949F3E554A3A01400_sleeptimer.sendCommand(“3600”)
end
Now i only have one problem and i dont know, how i may solve it.
Sleep 1 play only the Favorite endless (without repeat one).
if i click the button again, i want to play my queue again with Sleep 2.
Often we listen audiobooks. The Problem is: the audiobook starts from begin. it dont save the position, where we stopped.
is it possible to save the state? i can choose the tracknumber, but i dont have the state to grab the number.