I have a speaker which is controlled via mpd binding from openhab
Now i’m trying to implement a rule for a simple away mode (nobody home) let’s call it IMHOME_SWITCH and would like to stop the mpd playback when it is flipped off.
But after my return and the AWAY_SWITCH flipped back to on i would like the mpd_binding to go to the previous state. So i wonder what’s the best logic to implement this.
Configure persistence and configure it to save at least your MPD_Item:
rule "Restore MPD"
when
Item AWAY_SWITCH received command ON
then
MPD_Item.sendCommand(MPD_Item.previousState(true))
end
1 Like
Thanks! Exactly what i was looking for!
Well tried to follow without success
In logs
Error during the execution of rule ‘We are home’: Could not invoke method: org.openhab.model.script.actions.BusEvent.sendCommand(org.openhab.core.items.Item,java.lang.String) on instance: null
`
rule "We are away"
when Item iam_home changed from ON to OFF
then
sendCommand(Mpd_berry_StartStop,OFF)
end
rule "We are home"
when Item iam_home changed from OFF to ON
then
Mpd_berry_StartStop.sendCommand(Mpd_berry_StartStop.previousState(true))
end
`
In openhab designer i get this warning
Incompatible types. Expected org.openhab.core.types.Command but
was org.openhab.core.persistence.HistoricItem
Try Mpd_berry_StartStop.previousState(true).state