Rule that turn on/off light and smart plug when buttons is pushed

Hello, I'm still having trouble understanding the logic of the rules engine interface. It should be simple, but I still haven't figured out how the thing works...

I'd like to turn a socket on or off when I use a light switch.

The title of your topic says "virtual device," but I don't see any virtual devices in your description--or a need for any. If the below doesn't help, I'd suggest describing more about the automation you are trying to accomplish.

In general, assuming your device reports properly, the rule you want should be do-able a number of ways, perhaps most easily as this:

Trigger: Light Switch on

Actions to run:

On: Socket
Wait for event: Light Switch off 
Off: Socket

(where "Socket" and "Light Switch" are the names of your devices)

If you are intimidated by the interface of Rule Machine right now, you could also do something similar in Basic Rule. Other apps may also suit your needs, depending on what they may be.


There are Basic Rules, Rule Machine, Button Controller, and even a couple others. Which are you using? Rule Machine seems a bit heavy-handed for something this simple.

This is a Basic Rule, for example.

1 Like

Sounds easy, but can I add another trigger? Because I have to make sure that if I press button 1, it turns the socket ON, and if I press button 2, it turns the socket OFF.

Thank you, It work like a charm!

That will work, but there is an outlier that could cause it not to work, if only briefly.

If the hub is rebooted, for whatever reason, while it's waiting for the switch to be turned off, the lamp will not turn off again until you flip the switch off and then back on and off again.

A number of ways to deal with it. I would use a trigger of change instead of on. Then use a IF.

If switch is on
Turn on lamp
Turn off lamp

This is not the case, despite common misconceptions; a a reboot will have no effect on the subscription for the "Wait for event."

(What could happen is that if you turn the switch off when the hub is rebooting, nothing will happen--but there can be issues a time or so after that regardless of how the rule is written.)

1 Like

I thought a scheduled job would continue through a reboot. Waiting for events don't get cancelled?

No, neither scheduled jobs nor event subscriptions will be removed with a reboot (a "Wait" in RM will create either or both, depending on your options--as will triggers, BTW).

and if we use a variable, a reboot will clear the variable?

No, variables are not changed by a reboot.

Reboots, in general, do a lot less than many people seem to think. :smiley:

To be honest I didn't believe you about the wait for event not being lost on reboot, I had to see for myself. I was positive I had seen this issue pop up for me in the past.

I just tested it and the wait occurred after reboot, so you were right. There was another thread where I stated the same about a scheduled event. Although I knew the schedule would not be lost, I knew I had had issue because, as you mention, if the events occur while the hub is rebooting issues with your rule could occur.

Download the Hubitat app