If you are talking about how the binding is handling it, I’d react on either command (OnOffType.ON or OnOffType.OFF) in the handleCommand routine the same way!
Okay so when you get the SWITCHER_TOGGLE command you trigger your channel toggle_button and this triggers your rule that toggles the state of your switch channel?
Thanks for your answers and help.
I do not understand why you can’t react on the received command within the binding. Even without “knowing” the state, a toggle just changes the state from ON to OFF or CLOSED to OPEN etc…
Just do the same as you did in the rule in the binding.
Can you give me an example? When I receive the TOGGLE command from device how can I find out which command I need to execute on the linked channel: ON or OFF?
of the above posted code, you have already checked if the message you received is for the channel of the thing you are presently iterating. In other words you have found a thing that should react on the message.
Receiving a command via message should be the same as receiving a command via a button, the later are handled in the handleCommand routine.
Why not exchange the line above with: handleCommand (thHandler.getChannelUID, ToggleType.Toggle)
since I’m not on an IDE, I’m not sure sure on “thHandler.getChannelUID” (might be th.getChannelUID), the ToogleType has to be made up.
In the handleCommand of your NooliteSwitcherHandler.java you could use an if like:
if (command instanceof ToggleType) {
}
in which you could set the channel to the opposite state. However you are missing a variable to hold such information (if I’m not mistaken)
In this case handleCommand gets called in both instances. When a message is received and when we press a button in OpenHab. But in case of an incoming message i just want to toggle the state and in case of a OpenHab command i want to toggle the state and send out a message. Is this possible?