[OH3] Implement toggle rule from remote button to switch

I’m trying to implement a ‘toggle’ rule such that a remote (NanoMote Quad) can toggle the state of a switch Item.

I want to use an update so that every of a button on the NanoMote will toggle the state of the switch. In the rules engine, there is the ‘if’ condition, but there seems to be no way to have an ‘else’ as I would use in the text based rules in OH 2.x.

How do I accomplish this with the OH3 rules engine.


1 Like

Good question. As of now I did two rules.
One to turn off only if on and one turn on only if off.

You could use an ECMA script in the rule:

var LichtBadOben = itemRegistry.getItem("LichtBadoben_State");

if (LichtBadOben.state == "ON") {
  events.sendCommand(LichtBadOben, "OFF");
} else if (LichtBadOben.state == "OFF") {
  events.sendCommand(LichtBadOben, "ON");
1 Like

That was easy enough.