One of the problems is that the keyfob only sends events when the item state changes.
This would mean to switch on/off a lamp you would have to use two buttons because each of the button is linked to a different number. Hence, only when you click two different buttons a change event is sent as the state changes from 1.0 to 2.0 or from 2.0 to 1.0. If you press the same button twice you won’t receive any event in the rule (1.0 to 1.0 is not a change).
The following rule would therefore only work if you pressed a different button in between
rule "remote"
when
// Selection_Keyfob is the item that receives the id of the button
Item Selection_Keyfob changed
then
logInfo("remote","State {}",Selection_Keyfob.state)
if (Selection_Keyfob.state == 1.0) {
if(Power_Plug_Socket_1.state == OFF)
sendCommand(Power_Plug_Socket_1, ON)
else
sendCommand(Power_Plug_Socket_1, OFF)
}
Selection_Keyfob.postUpdate(0)
end
The simple trick is to add the following line to the end of the rule (before the end) as it forces the state in openhab back to 0.
Selection_Keyfob.postUpdate(0)
This sets back the state and the next button click on the keyfob is detected as a change (1.0 to 0, 0 to 1.0…).
Hope that helps someone like me some buttons…