Using Virtual Switch to turn on and off multiple lights issue


(Triscuits) #1

I’m using ST with Amazon Echo and have set up virtual switches and virtual dimmers for groups of lights. I’m using virtual switches because of the strange verbiage Alexa needs. I could create routines that turn on all lights and a separate routine to turn off all lights, but I have to name them different things, and then tell Alexa to “turn on” name of routine no matter if it’s turning lights on or off. So that just seems weird to me. So the virtual switches/dimmers work so that I can say “Alexa, turn on All Living Room Lights”, and “Alexa, turn off All Living Room Lights”, and all lights assigned to the group inside the virtual switch (using a Dim With Me SmartApp) will turn on and off. This is great except for one issue.

If a virtual switch is in the off position, and I turn on a light or a set of lights, specifically by name, without using the virtual switch, then if I want to use the virtual switch by saying, “Alexa, turn off All Living Room Lights” it doesn’t work because that virtual switch is already off.

Is there something I can do that would allow that virtual switch to still send a turn off command to all the lights in the group assigned to that virtual switch, even though that virtual switch is already in the off position?

I hope this makes sense. Thanks!


Groups for Alexa commands and triggers
(Glen King) #2

It makes enormous sense. I just encountered this last week! The programming to get there, however, is significant. I have therefore decided that for any group-items that don’t need programming (for example, I can’t imagine ever needing SmartThings routines to, upon a particular sensed event, turn on/off the entire downstairs) the better solution is the Alexa groups.

The Alexa groups do not maintain any switch state; they simply apply your command to every item in the group whenever you utter the command. So “Alexa, turn downstairs off” sends the OFF command to any items that are included in that group. The spoken syntax is simple and direct, and the result is consistent.

One other benefit is dimming. Imagine you have a light fixture that holds three bulbs. Put three smart bulbs in, group them as a single unit in Alexa (say, ‘chandelier’) and then you can say “Alexa, turn the chandelier to 50 percent” and all three bulbs will obey. And if you later say “Alexa, dim the chandelier” ALL the bulbs in the chandelier will dim together. With zero complex programming.


#3

@Triscuits, I have the same situation and there are a couple viable solutions for you:

  1. Instead of using Dim With Me, you could use a synchronized dimming app. A synchronized dimmer would make it so that all lights were synchronized to the state of any light that sends an on/off/set level event.
  • This setup is extremely inflexible, since individual switches/lights cannot be controlled as individuals.
  • This setup results in a great deal of ping-ponging for states before all devices in the pool get to the correct state.
  1. Setup triggers so that if any of the lights isturned on that it turns on the Virtual “master” switch.
  • This basically makes the Virtual “master” a slave to the On state of any of the real devices.
  • This ensures that the Virtual Switch is always switched to On, if any of the real devices it’s meant to control are switched to On.
  • You would not want to tether it to the slaves’ Off states though, since the objective is for it to be on if ANY of the slave devices are on.
  1. Setup groups in Alexa that contain all the real switches/bulbs.
    • This would allow you to issue a “Alexa, turn off All Living Room Lights” command and have each real device receive the On/Off commands.
    • A Virtual Switch is not needed, since Alexa groups essentially function as Virtual Switches do.
  2. Setup groups in Alexa that contain all real switches/bulbs AND the Virtual Switch.
    • This is beneficial if you have other Routines or watchers that monitor this switch for some reason or another.
    • Since all real devices are also part of the group, it will function the same as Option 3, whether the the Virtual Switch is on or off.

One thing I’ve noticed with dimmers is that Alexa groups cannot always dim properly. In those cases I’ve used a Virtual Dimmer as the master and the slaves are tethered to the master’s set level event state, but not vice versa.

Besides that issue, I think Alexa groups (Option 3 or Option 4) would be the best solution for you.


(Triscuits) #4

Well, there you go! I actually didn’t even know Alexa had groups like that. I just tested it out, and I think this might be a solution for me. Thank you!


(Robin) #5

I’ve been pondering this method but I can’t make it work. Syncing the master switch to the slaves is the easy part.

The problem is this:

  • whatever light turns on
  • sync rule fires and switches on the master
  • the master turning on triggers the ‘all on’ routine
  • everything turns on

The act of turning one light in the group on will indirectly cause all of that group to turn on.

Using a complicated set of CoRE Pistons and global variables, it could in theory be made to work, but the logic required will be immense!

It would be easier to achieve with two simulated switches (one for on, one for off) but then you would need to name them differently which messes up the OP’s original requirement for the voice controls to be natural.

I don’t have an echo but I think @Glen_King method sounds the best


#6

Yep @RobinWinbourne, that one gets a bit messy and requires a flag that differentiates the state change from a “normal” state change, but that’s the easy part. The PITA is making sure that all other watchers are aware of this flag and know to ignore those state changes.


(Robin) #7

Actually thought of a way to make it work with a nudge from @MEarly

Requires an additional simulated switch. Let’s call it ‘hold’ (Could also be done with a Global Variable)

IF
Any of XYZ switches changes to on
THEN
Turn on ‘Hold’ switch
Wait 3 seconds
Turn on ‘Master’ switch
Wait 3 seconds
Turn off ‘Hold’ switch
BUT IF
All of XYZ switches is off
THEN
Turn on ‘Hold’ switch
Wait 3 seconds
Turn off ‘Master’ switch
Wait 3 seconds
Turn off ‘Hold’ switch

To run the routines (all off / all on) you need a seperate CoRE Piston. (Could be combined in CoRE expert mode but keeping it simple)

IF
’Master’ switch changes to on
AND
’Hold’ switch is off
THEN
execute routine ‘All On’
BUT IF
’Master’ switch changes to off
AND
’Hold’ switch is off
THEN
execute routine ‘All Off’


#8

Brilliant! Very nice.


#9

I was having the same issue. (I use Google home instead of Alexa)

I changed my virtual dimmer device handler def Off value to

sendEvent(name: “switch”, value: “off”, isStateChange: true, displayed: false)

Now even when the virtual Dimmer is off and it receives the off command the rest of the lights I have slaved to it turn off.


(Ryan Smith) #10

Got my ST a couple weeks ago and this is the first thing I wanted to do. I really wanted something similar (using Google Home). I followed this thread and put lights into groups on Google Home. Problem was I eventually wanted some lights to appear in more than 1 group/room, so I came back to this thread.

I thought of creating a bunch of duplicate virtual switches that would mimic an actual switch, but that could get out of hand. Instead I did the following -

Create 2 virtual switches MasterOn/MasterOff. Along with a smart app to turn on/off a group of switches given one of these changing. After MasterOn turns on the smartapp turns it back off (vice versa for MasterOff). I could then add both of these to a different group in Google Home.


#11

Fantasitc! Thanks defiante! This method worked perfectly, cleanly, and with little effort.

For those of you who might not completely understand at first…The virtual dimmer device handler that will work per definate’s solution can be found here. Before installing that device handler, just change the one line in the handler code to match what was provided.

Change line “sendEvent(name: “switch”, value: “off”)” in handler code to “sendEvent(name: “switch”, value: “off”, isStateChange: true, displayed: false)”

Install that modified code virtual dimmer and then use it as the virtual switch for all your light groupings. That’s it. Works like a charm.


(Adam Wiseman) #12

Ok, please forgive my noobness, but how do I incorporate this? I’ve gotten to the point where I’ve successfully added the Virtual Dimmer virtual switch, and it shows up in my app now. Now how do I associate several physical switches with it? By “light groupings”, do you mean rooms? What if I want to control lights in more than one room.

Basically, here’s what I’m trying to accomplish: I’d like to use my Google Home and IFTTT to make smartthings turn off any downstairs lights that are on in a few rooms (kitchen, dining room, living room) when I say something like “Hey Google, Good night!”.

Thanks in advance!


(tinsnow) #13

follow instructions in this website.
http://thingsthataresmart.wiki/index.php?title=Virtual_Dimmer#Latest_Version

after the switch is added to smartthings, use automation “Smart Lightning” to turn on/off your desired lights when you turn on/off your “Virtual Dimmer”

i named my virtual dimmer switch as “Some Lights”. Had automation to turn on/off “Living Room Light” “Kitchen Light” “Hallway Light” etc when “Some Lights” is turned on/off.

Added the virtual switch “Some Lights” to Google Home. Try to discover again in Google Home once your automation is complete.


(Victor Kao) #14

Is there a similar solution for Google Home?


(Victor Kao) #15

How do you use the virtual switches to set up groups? I’ve gotten up to the point of creating a virtual switch but don’t know where to go after that. I basically want to be able to turn of all downstairs lights even though my lights are currently designated to specific rooms.


(Tagyoureit) #16

@RobinWinbourne Great logic! Per my comments on the WebCore forums (and for the benefit of anyone else reading this), using the Global Variable was not effective for some reason (to be specific, the execute piston didn’t pick up the state of the global variable at the appropriate time). The logic/flow worked flawlessly with a 2nd virtual switch.

Also, the logic can be slightly simplified for the off sections:

Hold routine

BUT IF
All of XYZ switches is off
THEN
// Turn on ‘Hold’ switch
// Wait 3 seconds
Turn off ‘Master’ switch
// Wait 3 seconds
// Turn off ‘Hold’ switch

and execute routine

BUT IF
’Master’ switch changes to off
// AND
// ’Hold’ switch is off
THEN
execute routine ‘All Off’

It’s a minor item, but since all of the switches will already be off using the logic “ALL of the switches are off”, we can safely let the hold routine execute but save 6 seconds (for a more responsive experience). And the execute routine will also run when all switches are off but, again, because all switches are already off there won’t be any action taken by ST.

Now, if only we could hide the virtual hold switch… hmm. :shushing_face:


(Robin) #17

Yeah, changes to webCoRE global variables only appear to the piston on a new execution of the piston.

So if a piston changes a global variable, that same piston won’t know about it until it gets re-triggered.

Local variables don’t have the same problem.

‘Hide’ the simulated switch by naming it ‘ZZZZZ name’ so as to push it to the bottom of the things list.


(Ron Talley) #18

Could also use Trend Setter…