Toggle option for Rules


(Davidjclarke1) #1

I’ve added a Flic button to control a smart bulb.

The behaviour that I want is to toggle the state of the light (ON/OFF) when a single click is received by the gateway.

It seems that my only option at the moment is to create two rules:

  1. If button pressed and light on -> turn light off
  2. If button pressed and light off -> turn light on

However, the single-click of a Flic button registers for long enough that both rules can be triggered from the same button press.

It would be great if there was a ‘toggle’ option for things that have a clear On/Off state (as there is in IFTTT). Is that a possibility?


(Martin Giger) #2

Yeah, sadly that’s a case that the rules system doesn’t really support well. My summary of the issue can be found at https://github.com/mozilla-iot/gateway/issues/1406#issuecomment-433920333 which sadly hasn’t lead to a reopen so far.

My workaround is to use single and double press/click to turn off/on.

I guess there’s also to be more toward what you are asking for: https://github.com/mozilla-iot/gateway/issues/694


(Davidjclarke1) #3

Thanks for your suggestion. I’m already using double press to set the brightness to high, and hold to dim the lights.

Eventually, I would like to be able to hold the button and gradually increase brightness, but I guess that’s a long way away!


(Martin Giger) #4

I just remembered that a new adapter for delays was recently published, trying to actually fix this using it now…

Edit: it’s called “Pulse”. Somehow my rules don’t trigger anymore with it.

Edit2: using the “Pulse” adapter with a pulse that has a duration of 3 works, you just have to toggle all the things involved in a rule condition after editing a rule for it to register (known bug). So I now have two rules, one for turning the light on and one for turning it off, both depending on the pulse to be off and both turning the pulse on.


(Dave Hylands) #5

Some of the buttons will generate events (like pressed). I haven’t personally tried this, but I would expect that it you used the event from the button (rather than the state of the button) in conjunction with the state of the light that you should be able to get a proper toggle.


(Martin Giger) #6

Sadly that doesn’t work, see the github comment I linked. The TL;DR is that events generate a “pulse” that is on for some amount of time in the rules engine, thus that assumption is not true. (But that’s also the reason why the pulse adapter lets you work around that issue)