I have searched the forums but can't find an answer. I want to be able to do different things with a Shelly attached to a physical switch.
One example is: I have a Shelly on a bathroom fan switch. If I turn it on, the fan is on until the switch is off. But if I turn it on and off right away I want the fan to run for 10 minutes then turn off.
Maybe there's another way to do this but seems like I should be able to tell, in an HE rule for instance, that the switch was turned on in the last 2 seconds when the 'Off' trigger is fired.
I guess I could set a global variable then clear it 2 seconds later, is that the 'right' way?
Any help is appreciated, esp. references to educational material.
Thanks.
I'm not familiar with Shelly but does it support changing the button type? Might be able to recognize a double tap off and accomplish what you want. Instead of an on off.
Hmm virtual switch comes to mind. Then you could compare the two states. A Boolean could also work. Two seperate rules could also do it. If you still need help hit me up tomorrow. About to hit the sack. 3am here.
If Shelly is controlling the load to the fan you need to set the button type to detached and then control the relay within a rule or something similar. Don't know if the builtin driver works for this as I use my own driver for all my Shelly devices (all 30+ of them).
I have a similar but totally different use case where I use a Shelly 1 and a door sensor with cable as a garage door opener which works great and in my custom driver I'm also able to use it with Apple Carplay through homebridge. As you can decouple all the functions in Shelly I use the button switch input for the door sensor, and control the relay with code, with the new action urls since Shelly fw 1.7.0 feedback to Hubitat is instant! So all in all a really cheap garage door opener with homekit support for $15
The Turn off virtual switch with two second delay should be a bit longer in case you take a second or two longer but not longer than you be in there under normal use. Like 10 seconds. Also helps if hub is lagged out by something.
Switch off portion:
Trigger virtual switch turned off.
Action
if light switch not on
Turn off fan delay 10 minutes
Else
wait for light switch off
Turn off fan
Endif
There's probably a better way to write this but it should work till I think of something better or someone else chimes in.
I ended up doing this with dimmable deck lights first. If you turn them off then back on they will switch between 40% and 100%.
Thanks for all the help.
Here's the Rule:
Thanks for the discussion! I wanted to share a small tweak which makes the toggling work equivalently starting from either the on state or off state. I also simplified the logic a bit, in particular making the "payload" all be at the end. (A programming style some call "don't gift wrap.") Finally, I removed a potential race condition by adding a "delay cancel" before setting the variable to true.
Triggers:
Bedroom Ceiling Lights turns *changed*
Actions:
IF (Variable recently_changed = false) THEN
Cancel Delayed Actions
Set recently_changed to true
Set recently_changed to false --> delayed: 0:00:02(cancelable)
Exit Rule
END-IF
Set recently_changed to false
// Anything after here is what we want to happen when the switch has been rapidly toggled, i.e., within a two second window either: switched on then switched off or switched off then switched on.
IF (Bedside Lamps, Bedroom Floor Lamp any is on) THEN
Off: Bedside Lamps, Bedroom Floor Lamp
ELSE
Color Temperature: Bedside Lamps, Bedroom Floor Lamp: 2700 -> Level: 100
END-IF