RM 4.0 Cancel Light Flash by Physical Switch

I've been trying to make it so I can cancel a light flash by pressing the switch.

Each kid has their own rule that works like as a 15 minute warning for their bed time flashing their ceiling light in their bedroom for 15 seconds and returns their light to it's original state.

I've set a variable for each kid using their name with their respective bed time.

I fired the rule off by clicking "Run Actions" then I physically press the light switch and it briefly pauses the flashing but then the flashing starts again, until the 15 seconds is over. I doesn't matter how many times I press the up, down or any combination, it never cancels the flashing until the 15 seconds is over.

It's just the cancelling of the flashing that isn't going as planned. I've tried two different methods I think should work shown below, but neither does.

Global Variable:
Amber's Warning Time 8:45PM

Trigger Event::
When time is Variable: Amber's Warning(08:45 PM)

Rule Name:
Amber's Warning

Select Actions To Run:
IF (Amberā€™s Light(off) is on(F) [FALSE]) THEN
Flash: Amberā€™s Light
Wait for events: Last Event Device is switch changed --> timeout: 0:00:15
On: Amberā€™s Light
ELSE
Flash: Amberā€™s Light
Wait for condition: Amberā€™s Light(off) is off TRUE --> timeout: 0:00:15
Off: Amberā€™s Light

Logs:
2020-05-29 08:28:42.719 pm [info]Amberā€™s Light is on [digital]
2020-05-29 08:28:39.910 pm [info]Amberā€™s Light was turned on [physical]
2020-05-29 08:28:34.973 pm [info]Amberā€™s Light is off [physical]
2020-05-29 08:28:34.410 pm [info]Amberā€™s Light is off [physical]
2020-05-29 08:28:33.205 pm [info]Amberā€™s Light is off [physical]
2020-05-29 08:28:32.947 pm [info]Amberā€™s Light is off [physical]
2020-05-29 08:28:31.762 pm [info]Amberā€™s Light is off [physical]
2020-05-29 08:28:31.545 pm [info]Amberā€™s Light is off [physical]
2020-05-29 08:28:31.189 pm [info]Amberā€™s Light was turned off [physical]
2020-05-29 08:28:27.058 pm [info]Amberā€™s Light was set to flash with a rate of 750 milliseconds

Okay I just had to give up and post, so of course I figured out how to solve it 1 minute later...

The below minor change makes it so if the light was off when it started flashing pressing up will stop the flash. If the light was on, pressing down will stop the flash. Obviously this doesn't return the light to it's original state, but oh well at least the kids can cancel it now.

I really wish there was a "if switch pressed" because a "toggle" seems to have to be a change in state, instead of it being okay to check for an on when already on...

Select Actions To Run:
IF (Amberā€™s Light(off) is on(F) [FALSE]) THEN
Flash: Amberā€™s Light
Wait for condition: Amberā€™s Light(off) is off TRUE --> timeout: 0:00:15
On: Amberā€™s Light
ELSE
Flash: Amberā€™s Light
Wait for condition: Amberā€™s Light(off) is on TRUE --> timeout: 0:00:15
Off: Amberā€™s Light

2 Likes

I sit corrected, it does return the light back to the state it was in prior to pressing the button! :slight_smile:

Rule Machine has "Capture Devices" and "Restore Devices" actions (under "Capture/Restore, Device Refresh or Polling"), which can be tricky with color bulbs and sometimes level but should be pretty straightforward for on/off switches. Otherwise, if this is working well for you, no reason to switch! In any case, that might have helped with some of this, but for on/off, the same result is pretty easy to do yourself with conditional actions based on the original state (looks like you might be trying to do that).

If you end up needing more specific advice, you might want to see what the "Flash" command actually does on your switch. This behavior (or the command itself--it's not on everything) isn't standardized. Sometimes it sends repeated on/offs that might make a "Wait for event" or "Wait for condition" match if it's looking for an on/off event or state. Sometimes it will continue indefinitely until you stop it with an explicit command to the bulb like on/off. Sometimes the device (if it implements this natively, as opposed to Hubitat faking it) will return to its previous state, sometimes it will stay on (or turn off). Sounds like you've got that figured out, though!

1 Like