# Do you guys use virtual switches for groups of lights?

**URL:** <https://community.smartthings.com/t/do-you-guys-use-virtual-switches-for-groups-of-lights/43938>\
**Category:** Devices & Integrations\
**Created:** [April 1, 2016, 11:34pm UTC](https://community.smartthings.com/t/do-you-guys-use-virtual-switches-for-groups-of-lights/43938 "2016-04-01T23:34:44Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![adawalli](https://yyz2.discourse-cdn.com/smartthings/user_avatar/community.smartthings.com/adawalli/32/29173_2.png) [@adawalli](https://community.smartthings.com/u/adawalli)\
**Post date:** [April 1, 2016, 11:34pm UTC](https://community.smartthings.com/t/do-you-guys-use-virtual-switches-for-groups-of-lights/43938/1 "2016-04-01T23:34:44Z")

</div>

Hello ST braintrust!

Do you guys tend to use virtual switches for your smart lights? I have a couple of scenarios where I feel like the virual switch breaks down.

Scenario: I have a virtual switch controlling my two smart bulbs.

Now that I have the bulbs integrated with Amazon Echo, Harmony, etc. I find that sometimes I control the bulbs directly which leaves the switch state incorrect. This stinks because my Goodnight routine turns off my Living Room switch. Well, if Alexa had turned on the lights as a group (not via the switch), the switch state is left in off state and my lights stay on.

- Is there a smartapp to maintain proper switch state (if Bulb A OR Bulb B on, switch = on, else off)? This would be trivial for me to write, but I just want to check first
- Do you guys recommend doing away with the virtual switch completely?

Thanks all!

---

<div class="post-metadata">

**Author:** ![Toy4Rick](https://avatars.discourse-cdn.com/v4/letter/t/3ec8ea/32.png) [@Toy4Rick](https://community.smartthings.com/u/Toy4Rick)\
**Post date:** [April 1, 2016, 11:44pm UTC](https://community.smartthings.com/t/do-you-guys-use-virtual-switches-for-groups-of-lights/43938/2 "2016-04-01T23:44:37Z")

</div>

Are you familiar with Rule Machine written by Bruce (bravenel)? It’s the bees knees and sounds like what you are looking for.

> [@Rule Machine Version 1.9 Released](https://community.smartthings.com/t/rule-machine-version-1-9-released/43204):
>
> Rule Machine Version 1.9 Released With this release comes a new and powerful scheduling feature, a new Trigger Event called Periodic. Release Notes: Added Periodic Trigger Event Added option to disable logging from a Rule Bug fixes for ZWN-SC7 button controller Periodic The Periodic feature brings the power of CRON scheduling to Rule Machine. There are many different kinds of periodic schedules you can create: Minutes Every N minutes Each selected minute Hourly Every N hours, starting at a selected time Each selected hour, at a selected minute after the hour Daily Every N days Every weekday Each selected day of the month – At a selected time Weekly Each selected day of the week – At a selected time Monthly On a selected day of every N months On a selecte…

Rick

---

<div class="post-metadata">

**Author:** ![adawalli](https://yyz2.discourse-cdn.com/smartthings/user_avatar/community.smartthings.com/adawalli/32/29173_2.png) [@adawalli](https://community.smartthings.com/u/adawalli)\
**Post date:** [April 1, 2016, 11:49pm UTC](https://community.smartthings.com/t/do-you-guys-use-virtual-switches-for-groups-of-lights/43938/3 "2016-04-01T23:49:26Z")

</div>

I hadn’t tried it yet, however it looks like a lot of code for simple control of lights. I am trying to find out best practices for light control 🙂

---

<div class="post-metadata">

**Author:** ![adawalli](https://yyz2.discourse-cdn.com/smartthings/user_avatar/community.smartthings.com/adawalli/32/29173_2.png) [@adawalli](https://community.smartthings.com/u/adawalli)\
**Post date:** [April 2, 2016, 12:17am UTC](https://community.smartthings.com/t/do-you-guys-use-virtual-switches-for-groups-of-lights/43938/4 "2016-04-02T00:17:55Z")

</div>

I just thought of something…if I turn one light one and use rule machine to control my switch, it’s going to automatically turn on the second light.

Anyone else have a suggestion of best practices for lights?

---

<div class="post-metadata">

**Author:** ![Toy4Rick](https://avatars.discourse-cdn.com/v4/letter/t/3ec8ea/32.png) [@Toy4Rick](https://community.smartthings.com/u/Toy4Rick)\
**Post date:** [April 2, 2016, 12:20am UTC](https://community.smartthings.com/t/do-you-guys-use-virtual-switches-for-groups-of-lights/43938/5 "2016-04-02T00:20:28Z")

</div>

Hey Adam,

There is basically no coding when you use rule machine. The code written by Bruce integrates into the ST app on your phone where you write “Rules” to control “Things” that fit your needs

Don’t be afraid to give it a go  
Rick

---

<div class="post-metadata">

**Author:** ![adawalli](https://yyz2.discourse-cdn.com/smartthings/user_avatar/community.smartthings.com/adawalli/32/29173_2.png) [@adawalli](https://community.smartthings.com/u/adawalli)\
**Post date:** [April 2, 2016, 12:29am UTC](https://community.smartthings.com/t/do-you-guys-use-virtual-switches-for-groups-of-lights/43938/6 "2016-04-02T00:29:20Z")

</div>

Hey Rick, I am a software dev, so it’s not the coding aspect of it that worries me. I feel like I have a simple situation that I am overcomplicating, and again, just trying to find out what most folks are doing. Thanks for the Rules Machine suggestion. I will certainly use that if something simpler doesn’t surface.

---

<div class="post-metadata">

**Author:** ![Ron](https://yyz2.discourse-cdn.com/smartthings/user_avatar/community.smartthings.com/ron/32/80532_2.png) [@Ron](https://community.smartthings.com/u/Ron)\
**Post date:** [April 2, 2016, 12:51am UTC](https://community.smartthings.com/t/do-you-guys-use-virtual-switches-for-groups-of-lights/43938/7 "2016-04-02T00:51:56Z")

</div>

I am a developer also but if Smart Things came with Rule Machine out of the box I probably never would have started any ST development (well I would still have to write/re-write ALL of my devices code) but you know what I am trying to say 🙂

---

<div class="post-metadata">

**Author:** ![Mclovin50](https://yyz2.discourse-cdn.com/smartthings/user_avatar/community.smartthings.com/mclovin50/32/24819_2.png) [@Mclovin50](https://community.smartthings.com/u/Mclovin50)\
**Post date:** [April 2, 2016, 1:29am UTC](https://community.smartthings.com/t/do-you-guys-use-virtual-switches-for-groups-of-lights/43938/8 "2016-04-02T01:29:57Z")

</div>

Try using a smart app called Trend Setter. It worked good for me when I used it.

---

<div class="post-metadata">

**Author:** ![adawalli](https://yyz2.discourse-cdn.com/smartthings/user_avatar/community.smartthings.com/adawalli/32/29173_2.png) [@adawalli](https://community.smartthings.com/u/adawalli)\
**Post date:** [April 2, 2016, 1:32am UTC](https://community.smartthings.com/t/do-you-guys-use-virtual-switches-for-groups-of-lights/43938/9 "2016-04-02T01:32:25Z")

</div>

fair enough but consider this race condition

My switch controls lights A and B

I have rule machine set to turn on my switch IF A OR B == ON

If I tell alexa however to turn on light A, rule machine will turn on the switch. But this will then turn on Light B as well.

See my problem? What am I missing here? I am doing something fundamentally wrong!

---

<div class="post-metadata">

**Author:** ![LedGecko](https://yyz2.discourse-cdn.com/smartthings/user_avatar/community.smartthings.com/ledgecko/32/28060_2.png) [@LedGecko](https://community.smartthings.com/u/LedGecko)\
**Post date:** [April 2, 2016, 2:56am UTC](https://community.smartthings.com/t/do-you-guys-use-virtual-switches-for-groups-of-lights/43938/10 "2016-04-02T02:56:10Z")

</div>

Your race condition is caused by being able to control them both individually and as a group, As such, you should anticipate that the group state can become out of sync due to individual control. One possible solution is to force a sync when you want to control the group, by simply toggling to the opposite state first. e.g. when you want to turn the group off, you first turn the virtual switch on, then turn it off.

EDIT: I haven’t yet used one myself, but “Simulated Button” might be what you’re looking for. Apparently it’s like a switch, but performs its actions without regard to state.

---

<div class="post-metadata">

**Author:** ![bamarayne](https://yyz2.discourse-cdn.com/smartthings/user_avatar/community.smartthings.com/bamarayne/32/18206_2.png) [@bamarayne](https://community.smartthings.com/u/bamarayne)\
**Post date:** [April 2, 2016, 3:48am UTC](https://community.smartthings.com/t/do-you-guys-use-virtual-switches-for-groups-of-lights/43938/11 "2016-04-02T03:48:26Z")

</div>

This is how I control my 5 kitchen bulbs via ST and Alexa.

In the ST environment, I have a virtual switch called kitchen lights. Using rule machine the VS controls all five kitchen bulbs. This is here strictly due to the GE link bulb firmware where the lights will only set to 25% when turned on. This switch turns on all of the bulbs at once to 100%.

In the Alexa environment, I can say turn on kitchen lights and Alexa turns on the VS, which turns on the five bulbs. Alexa can also control each bulb individually.

---

<div class="post-metadata">

**Author:** ![Jnick](https://avatars.discourse-cdn.com/v4/letter/j/48db29/32.png) [@Jnick](https://community.smartthings.com/u/Jnick)\
**Post date:** [April 2, 2016, 4:34am UTC](https://community.smartthings.com/t/do-you-guys-use-virtual-switches-for-groups-of-lights/43938/12 "2016-04-02T04:34:41Z")

</div>

What bulbs/switches are they? Also, what exactly is your end goal? In the OP, you said you wanted a “IF light A OR light B is on, turn on the switch”

Rule machine will do this. However you’re now saying that won’t work because you want to control the bulbs individually as well? What is the exact setup, in regards to bulb type, switch type. I’m also assuming these are two different lamps/fixtures/ceiling lights and not one fixture with multiple bulbs…right?

Once we have some more info on the actual use of the lights, we can better help you find a solution.

---

<div class="post-metadata">

**Author:** ![adawalli](https://yyz2.discourse-cdn.com/smartthings/user_avatar/community.smartthings.com/adawalli/32/29173_2.png) [@adawalli](https://community.smartthings.com/u/adawalli)\
**Post date:** [April 2, 2016, 12:33pm UTC](https://community.smartthings.com/t/do-you-guys-use-virtual-switches-for-groups-of-lights/43938/13 "2016-04-02T12:33:29Z")

</div>

@LedGecko I had thought about something similar to your suggesetion, however I was going to use two momentary button tiles where one button was on, and one button was off. In this instance, state would be ignored.

@Jnick, I have two Lightify bulbs, each in separate lamps. I currently have them tied to a single virtual switch. It works fine if I ONLY use the switch. However, if I start turning bulbs on and off individually, or even as a group with Alexa, the switch state can get out of sync.

A current issue with this setup looks something like this. My daughter comes through and tells Alexa to “Turn on the living room lights”. This uses the alexa group for those bulbs, however the virtual switch is not invoked (it still says off).

Then, later that night on my way to bed, I initiate my “Bed time routine” which checks and says “OK, living room switch is off, I don’t need to turn off the lights”. The issue here is that all my routines are tied to control the switch, but not the bulbs themselves.

---

<div class="post-metadata">

**Author:** ![Boston\_B](https://yyz2.discourse-cdn.com/smartthings/user_avatar/community.smartthings.com/boston_b/32/23539_2.png) [@Boston\_B](https://community.smartthings.com/u/Boston_B)\
**Post date:** [April 2, 2016, 1:19pm UTC](https://community.smartthings.com/t/do-you-guys-use-virtual-switches-for-groups-of-lights/43938/14 "2016-04-02T13:19:32Z")

</div>

@adawalli that photo looks real familiar? Are you this is me?

---

<div class="post-metadata">

**Author:** ![adawalli](https://yyz2.discourse-cdn.com/smartthings/user_avatar/community.smartthings.com/adawalli/32/29173_2.png) [@adawalli](https://community.smartthings.com/u/adawalli)\
**Post date:** [April 2, 2016, 1:38pm UTC](https://community.smartthings.com/t/do-you-guys-use-virtual-switches-for-groups-of-lights/43938/15 "2016-04-02T13:38:16Z")

</div>

It’s a photo from one of the greatest internet phenomenons of all time, the zombie kid that loves Turtles

---

<div class="post-metadata">

**Author:** ![Boston\_B](https://yyz2.discourse-cdn.com/smartthings/user_avatar/community.smartthings.com/boston_b/32/23539_2.png) [@Boston\_B](https://community.smartthings.com/u/Boston_B)\
**Post date:** [April 2, 2016, 1:46pm UTC](https://community.smartthings.com/t/do-you-guys-use-virtual-switches-for-groups-of-lights/43938/16 "2016-04-02T13:46:04Z")

</div>

Lol ya I know. I thought you were him!

---

<div class="post-metadata">

**Author:** ![bamarayne](https://yyz2.discourse-cdn.com/smartthings/user_avatar/community.smartthings.com/bamarayne/32/18206_2.png) [@bamarayne](https://community.smartthings.com/u/bamarayne)\
**Post date:** [April 2, 2016, 2:07pm UTC](https://community.smartthings.com/t/do-you-guys-use-virtual-switches-for-groups-of-lights/43938/17 "2016-04-02T14:07:31Z")

</div>

> [@adawalli](#):
>
> Then, later that night on my way to bed, I initiate my “Bed time routine” which checks and says “OK, living room switch is off, I don’t need to turn off the lights”. The issue here is that all my routines are tied to control the switch, but not the bulbs themselves

Just add the virtual switch to the Alexa group.

---

<div class="post-metadata">

**Author:** ![adawalli](https://yyz2.discourse-cdn.com/smartthings/user_avatar/community.smartthings.com/adawalli/32/29173_2.png) [@adawalli](https://community.smartthings.com/u/adawalli)\
**Post date:** [April 2, 2016, 2:53pm UTC](https://community.smartthings.com/t/do-you-guys-use-virtual-switches-for-groups-of-lights/43938/18 "2016-04-02T14:53:58Z")

</div>

@bamarayne, As mentioned above, that works fine until you turn on one both of the lights with alexa (but not via the virtual switch). Now the virtual switch is out of sync.

---

<div class="post-metadata">

**Author:** ![adawalli](https://yyz2.discourse-cdn.com/smartthings/user_avatar/community.smartthings.com/adawalli/32/29173_2.png) [@adawalli](https://community.smartthings.com/u/adawalli)\
**Post date:** [April 2, 2016, 2:55pm UTC](https://community.smartthings.com/t/do-you-guys-use-virtual-switches-for-groups-of-lights/43938/19 "2016-04-02T14:55:49Z")

</div>

I basically have achieved the behavior I want, but it feels super hacky.

I have two momentary buttons. One for the on state of my lights and one for off state. No state needs to be maintained. I basically wish I could have a tri-switch. After hitting ON, it would go back to neutral. After hitting OFF it would go back to neutral.

---

<div class="post-metadata">

**Author:** ![bamarayne](https://yyz2.discourse-cdn.com/smartthings/user_avatar/community.smartthings.com/bamarayne/32/18206_2.png) [@bamarayne](https://community.smartthings.com/u/bamarayne)\
**Post date:** [April 2, 2016, 3:03pm UTC](https://community.smartthings.com/t/do-you-guys-use-virtual-switches-for-groups-of-lights/43938/20 "2016-04-02T15:03:29Z")

</div>

For some reason I think you’re over thinking this.

What exactly are you using the virtual switch for?  
Are your smart bulbs connected to the ST hub?

[Next page](https://community.smartthings.com/t/do-you-guys-use-virtual-switches-for-groups-of-lights/43938.md?page=2)
