Virtual Switch Causing Main Light To Turn Back Off

So, here’s what I’m trying to do. I have my garage lights on a smart switch. I want it so that when I turn them on with the switch, they stay on. I also have a motion sensor and a contact sensor that can turn them on if motion is detected or the overhead door is opened. It was suggested to me the way to do that could be that when either of the sensor routines turn them on, they also turn on a virtual switch. So then for the routines that would turn the lights off in 10 minutes or whatever, they will only turn the lights off if the virtual switch is also on. As an added detail, those sensor routines will only turn on the lights if they are off. So, in theory I’ve made it so the sensor routines can’t “override” the switch having turned the light on and turn them off on me when I’m working out there.

I’ve only ever used virtual switches as ways to control things in Alexa, so first I tried the Contact Sensor type virtual switch and then the Alexa Switch type without adding the separate contact sensor. What they are doing is, when the sensor routines turn on the light, they turn it back off right away. Then after the sensors’ recharge time, they turn them back on. If you look at the device histories, it shows the on, then off, then on in the light’s history, but in the virtual switch’s history, it only shows the switch turned on and the contact sensor opened once. If you remove the virtual switch from the routines entirely, the light behaves normally.

So, my question is, what type of virtual switch should I be using? I gravitated to the ones I was used to, but with so many other options, I’m not sure which one to use, or which ones have been kept up over time. Thanks!

Just use a normal virtual switch, not a momentary switch, contact sensor, or anything else. Just basic on/off is all that’s required. Also, be sure to turn off the virtual switch in the Routine that turns off the light after your 10 minute duration.

4 Likes

That makes me query what the sensor routines to turn the lights off are doing.

You’d see that behaviour if they are testing if their ‘virtual switch is on’ as a extra condition and the conditions are combined with ‘any conditions are met’. Turning the virtual switch on would trigger the routine to turn the lights off regardless of what the sensors were doing.

They should be testing that their ‘virtual switch is on’ as a ‘precondition’ with the condition being your sensor going inactive or having been inactive for a while.

3 Likes

You’re actually right. What I had was:

If:
garage light is off (precondition)
garage motion sensor detects motion

Then:
turn on garage light
turn on VS

And what was running right after that was:

*If: *
VS is on (precondition)
contact sensor for overhead door is closed

Then:
Turn off garage light after 1 minute.

Haha, pretty silly when I think about it. I just was trying to get it so the light would go off right after the door closes. BUT, you don’t really need that because you have the routine that will turn the light off after no motion is seen after 10 minutes.

I did switch to the VS type of Switch. All seems well with that. Thank you to you both!

2 Likes

Okay, I guess I spoke too soon. The motion routine works perfectly, but the one for the contact sensor does not. The light turns on for a second and turns right back off. ugh. I’m stumped now. Here are all my routines. Help!
Contact Sensor routine to turn light on (2 overhead doors)


No motion turn lights off

Motion detected turn lights on

Catch-all VS off routine.

That Routine will turn on the Garage Lights and the v10 Garage Light By Sensor if it is executed for any reason while either of Garage Door Sensor 1 or Garage Door Sensor 2 are reporting that they are open.

The Routine will be executed whenever either of the sensors reports that they are either open or closed. So closing one door will turn the lights on if the other door is still open.

That is probably a good thing.

This one will turn off the lights and the virtual switch whenever the Routine is executed and the motion sensor has been reporting motion as inactive for ten minutes and the virtual switch is on.

The Routine will be executed at the exact point when the motion has been inactive for ten minutes, at the point when motion becomes active again, and whenever the virtual switch reports a new state.

So that means if there hasn’t been motion for ten minutes when the virtual switch is turned on the lights will immediately be turned off.

If you edit the condition for the v10 Garage Light By Sensor and tick ‘Use a precondition’ it will prevent any changes to the virtual switch from causing the Routine to execute.

This will turn on the lights and the virtual switch if the Routine is executed when the motion sensor is ‘active’ and the lights are off.

The Routine will execute whenever the motion sensor reports a new state.

This looks exactly what you want. Only set the virtual switch if the lights were switched on by motion.

Looks fine to me. The lights being turned off will make sure your virtual switch is off.

2 Likes

Okay, I think I get what you are saying. The virtual switch needs to be changed to a precondition for No Motion Turn Lights Off, correct? Because of the fact that it is not a precondition, this routine is being triggered when the VS changes state as in when the other routine that executes when a garage door is opened? Man, that doesn’t make sense to me, but i tried it and it works! Thank you!

So, the motion sensor timer (that would turn the lights off) will not simply start when the lights come on, the motion sensor has to see motion first, right? I wasn’t sure about that, so that’s why I don’t have a 4th routine that will turn off the lights if they are triggered by the contact sensor, but NOT the motion sensor. That shouldn’t happen too often, I don’t think. Do you think if I added a “Turn off after 10 minutes” to the Garage Light in the Contact Sensor routine, that would catch that scenario, or is it asking for trouble? haha