Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

Itinj24

Contributor
Original poster
Nov 8, 2017
4,694
2,764
New York
Any Shortcuts experts on here? Seeking a little help.

I have a LIFX switch on my wall. It has four buttons and each one has three actions- single tap, double tap, long tap. Within the switch settings, you can convert any of the button actions to a Shortcut.

What I’m looking to do is single tap button #1 to turn on a set of lights (not grouped together) if the lights are off and tap the same button to turn off those lights if they are already on.

I can accomplish this with one light or a set of lights grouped together. I run into an issue when the lights are not grouped together as I don’t see an “and” or “or” action in shortcuts.

Tried using a series of “If” actions but it doesn’t work: If staircase light is on, if bedroom light is on, if bathroom light is on, turn off All lights (in a scene) otherwise if staircase light is off, if bedroom light is off, if bathroom light is off, turn on all lights (in a scene) otherwise end if.

Can’t use scenes or multiple HomeKit devices for an “if” action. Only as an end result.

Appreciate any input or if there is an “and” and/or “or” action in shortcuts that I’m missing, I’d appreciate being pointed in the right direction.
 
You can use scenes in an IF-action.
  • Define/create different scenes, e.g. one for “all lights on”, one for “all lights off”, et cetera - you basically have to define each desired end configuration in a scene.
  1. create a new shortcut and add an If-action which checks the toggle of the LIFX switch, e.g. wether it is ON. Shortcuts will automatically add an Otherwise- and an End If-building tile.
  2. Add a Set Scenes and Acessories-building tile, selecting one of the scenes you previously created, e.g. “all lights on”, whatever.
  3. Now move/drag this Set Scene-block between the If- and the Otherwise-Block.
  4. Add another Set Scenes and Acessories-building tile, selecting the “opposite” configuration to the one you added previously ( “all lights on”).
  5. Move/drag this after the Otherwise-building tile before the End IF-tile.
Test the shortcut. Then create an e.g. Automation which works for everyone in your home.
 
Last edited:
  • Like
Reactions: Itinj24
There are no "and" or "or" operators, but you can accomplish the same thing by how you nest your "if" statements.

For "and", you need to nest your "if" statements under each one.
This example will run the "Turn Off Lights" scene if all three lights are on.
Code:
If Staircase Is On
  If Bedroom Is On
    If Bathroom Is On
      Set Turn Off Lights
    Otherwise
    End If
  Otherwise
  End If
Otherwise
End If

For "or", you need to put the "if" statements under the "otherwise" statements (and use multiple actions).
This example will run the "Turn Off Lights" scene if any of the three lights are on.
Code:
If Staircase Is On
  Set Turn Off Lights
Otherwise
  If Bedroom Is On
    Set Turn Off Lights
  Otherwise
    If Bathroom Is On
      Set Turn Off Lights
    Otherwise
    End If
  End If
End If

I have a similar shortcut and have done it the following way. (If there's a mix of on/off lights, it will turn them all on first; a second tap will then turn them all off.)
Code:
If Staircase Is On
  If Bedroom Is On
    If Bathroom Is On
      Set Turn Off Lights
    Otherwise
      Set Turn On Lights
    End If
  Otherwise
    Set Turn On Lights
  End If
Otherwise
  Set Turn On Lights
End If

Alternatively, if you prefer the opposite behavior (to turn them all off first before turning them all on)...it would look like this:
Code:
If Staircase Is Off
  If Bedroom Is Off
    If Bathroom Is Off
      Set Turn On Lights
    Otherwise
      Set Turn Off Lights
    End If
  Otherwise
    Set Turn Off Lights
  End If
Otherwise
  Set Turn Off Lights
End If
 
Last edited:
  • Like
Reactions: Itinj24
You can use scenes in an IF-action.
  • Define/create different scenes, e.g. one for “all lights on”, one for “all lights off”, et cetera - you basically have to define each desired end configuration in a scene.
  1. create a new shortcut and add an If-action which checks the toggle of the LIFX switch, e.g. wether it is ON. Shortcuts will automatically add an Otherwise- and an End If-building tile.
  2. Add a Set Scenes and Acessories-building tile, selecting one of the scenes you previously created, e.g. “all lights on”, whatever.
  3. Now move/drag this Set Scene-block between the If- and the Otherwise-Block.
  4. Add another Set Scenes and Acessories-building tile, selecting the “opposite” configuration to the one you added previously. “all lights on”
  5. Move/drag this after the Otherwise-building tile before the End IF-tile.
Test the shortcut. Then create an e.g. Automation like which works for everyone in your home.
Very much appreciate you taking the time to post this reply. This was my first approach. The problem is, this Shortcut has to be written as a “Convert to Shortcut” within the switches’ settings in HomeKit. Can’t be imported from the Shortcuts app. The toggle of the switch can’t be checked by the Shortcut either. It has to check the power state of the concerned light bulbs, which also can’t check multiple grouped lights or scenes. Each separate grouping of multiple lights needs its own block of “if” and “otherwise”. This approach only worked one way though and it was destroying me for a few days.

I did find the solution, after posting this, in a four year old Reddit post after researching for days lol.

Adding a “Stop This Shortcut” action after every block of “ifs” and “otherwise a” creates a pseudo “or” action. Nested “if” didn’t work for me either.
 
There are no "and" or "or" operators, but you can accomplish the same thing by how you nest your "if" statements.

For "and", you need to nest your "if" statements under each one.
This example will run the "Turn Off Lights" scene if all three lights are on.
Code:
If Staircase Is On
  If Bedroom Is On
    If Bathroom Is On
      Set Turn Off Lights
    Otherwise
    End If
  Otherwise
  End If
Otherwise
End If

For "or", you need to put the "if" statements under the "otherwise" statements (and use multiple actions).
This example will run the "Turn Off Lights" scene if any of the three lights are on.
Code:
If Staircase Is On
  Set Turn Off Lights
Otherwise
  If Bedroom Is On
    Set Turn Off Lights
  Otherwise
    If Bathroom Is On
      Set Turn Off Lights
    Otherwise
    End If
  End If
End If

I have a similar shortcut and have done it the following way. (If there's a mix of on/off lights, it will turn them all on first; a second tap will then turn them all off.)
Code:
If Staircase Is On
  If Bedroom Is On
    If Bathroom Is On
      Set Turn Off Lights
    Otherwise
      Set Turn On Lights
    End If
  Otherwise
    Set Turn On Lights
  End If
Otherwise
  Set Turn On Lights
End If

Alternatively, if you prefer the opposite behavior (to turn them all off first before turning them all on)...it would look like this:
Code:
If Staircase Is Off
  If Bedroom Is Off
    If Bathroom Is Off
      Set Turn On Lights
    Otherwise
      Set Turn Off Lights
    End If
  Otherwise
    Set Turn Off Lights
  End If
Otherwise
  Set Turn Off Lights
End If
Thank you very much for that reply. I tried using nested “if” actions but for some reason, it only worked one way and it was the first block (turning them all on). The second block to turn them all off was being ignored for some reason. Been trying this for a few days before posting here.

I did find the solution, after posting this, in a four year old Reddit post after researching for days lol.

Adding a “Stop This Shortcut” action after every block of “ifs” and “otherwise a” creates a pseudo “or” action. Works the way I expected it to finally. It’s a long shortcut but it checks the power state of each light bulb in the mix and if any one of them are on, it turns them all off. Conversely, if any one of them are off, it turns them all on.

This is a staircase switch that I want to tap just once to turn them all on when I’m walking down or turn them all off as I’m leaving a walking up. There are two separate rooms in this zone.
 
This is what the Shortcut ended up looking like, in case anyone else is seeking the same solution.

Note that in the “if” actions, it is only able to take one bulb from a group of bulbs. Shortcuts doesn’t recognize a group of bulbs. So for example, “TV Wall Sliding Door Light” is included in a group of lights called “Theater Lights.”

There are two rooms in this zone: Zone is: Den, Rooms are: Theater and Game Room.

“Stop this Shorcut” adds an “or” action.




IMG_1860.pngIMG_1861.pngIMG_1862.pngIMG_1863.pngIMG_1864.pngIMG_1865.png
 
It’s a long shortcut but it checks the power state of each light bulb in the mix and if any one of them are on, it turns them all off. Conversely, if any one of them are off, it turns them all on.
This doesn't make sense, unless I'm misunderstanding something. If some lights in the mix are on and some are off...you can only turn them all off, or turn them all on. You can't have it both ways.

For example (based on your shortcut you posted), say your Staircase Light is on and you want to turn it off...it'll only turn off if the TV Wall Sliding Door Light is also on. (Because if the TV Wall Sliding Door Light is off, it turns all lights on.) On the flip side, say your Staircase Light is off and you want to turn it on...it'll only turn on if the TV Wall Sliding Door Light is also off. (Because if the TV Wall Sliding Door Light is on, it turns all lights off.) This is only dealing with the first two lights in your shortcut. It gets a little more complicated the further down you go and a light may not have the behavior you expected.

This is what the Shortcut ended up looking like, in case anyone else is seeking the same solution.

Note that in the “if” actions, it is only able to take one bulb from a group of bulbs. Shortcuts doesn’t recognize a group of bulbs. So for example, “TV Wall Sliding Door Light” is included in a group of lights called “Theater Lights.”

There are two rooms in this zone: Zone is: Den, Rooms are: Theater and Game Room.

“Stop this Shorcut” adds an “or” action.




View attachment 2236713View attachment 2236715View attachment 2236716View attachment 2236714View attachment 2236717View attachment 2236718
This is a good start, but it has unnecessary "if" statements. You are checking to see if a light is on, and then checking the same light again in the "otherwise" clause to see if it's off. The light can only be on or off. If it's not on during the first check in the "if" statement, you already know it's off...so no need to check it again. Your shortcut could be simplified to:
Code:
If TV Wall Sliding Door Light Is On
    Set Den Lights Off
Otherwise
    Set Den Lights On
    Stop this shortcut
    If Staircase Light Is On
        Set Den Lights Off
    Otherwise
        Set Den Lights On
        Stop this shortcut
        If Curved Window Can Is On
            Set Den Lights Off
        Otherwise
            Set Den Lights On
            Stop this shortcut
            If Light Fixture Is On
                Set Den Lights Off
            Otherwise
                Set Den Lights On
                Stop this shortcut
                If TV Upper Gradient Light Strip Is On
                    Set Den Lights Off
                Otherwise
                    Set Den Lights On
                End If
            End If
        End If
    End If
End If

Also, just for clarity, "Stop this shortcut" isn't an "or" action. The reason why you are needing it in your shortcut is because you are turning the lights on in the previous line, so you need to quit the shortcut before the next "if" statement checks to see if a light is on.

You'll still have the "unknown" behavior mentioned above, based on whatever state each of your lights are in. If you want a more consistent/"known" behavior, it would be best to decide what you want to happen if some lights in the mix are on and others are off. Do you want to turn everything off, or turn everything on?

This example will turn everything off first if a light is on; if all lights are off, then it'll turn everything on. I know you said this didn't work before, but it should. Pay close attention to the nesting and position of the statements. Post screenshots if you still have trouble.
Code:
If TV Wall Sliding Door Light Is On
    Set Den Lights Off
Otherwise
    If Staircase Light Is On
        Set Den Lights Off
    Otherwise
        If Curved Window Can Is On
            Set Den Lights Off
        Otherwise
            If Light Fixture Is On
                Set Den Lights Off
            Otherwise
                If TV Upper Gradient Light Strip Is On
                    Set Den Lights Off
                Otherwise
                    Set Den Lights On
                End If
            End If
        End If
    End If
End If
 
  • Like
Reactions: Itinj24
This doesn't make sense, unless I'm misunderstanding something. If some lights in the mix are on and some are off...you can only turn them all off, or turn them all on. You can't have it both ways.

For example (based on your shortcut you posted), say your Staircase Light is on and you want to turn it off...it'll only turn off if the TV Wall Sliding Door Light is also on. (Because if the TV Wall Sliding Door Light is off, it turns all lights on.) On the flip side, say your Staircase Light is off and you want to turn it on...it'll only turn on if the TV Wall Sliding Door Light is also off. (Because if the TV Wall Sliding Door Light is on, it turns all lights off.) This is only dealing with the first two lights in your shortcut. It gets a little more complicated the further down you go and a light may not have the behavior you expected.


This is a good start, but it has unnecessary "if" statements. You are checking to see if a light is on, and then checking the same light again in the "otherwise" clause to see if it's off. The light can only be on or off. If it's not on during the first check in the "if" statement, you already know it's off...so no need to check it again. Your shortcut could be simplified to:
Code:
If TV Wall Sliding Door Light Is On
    Set Den Lights Off
Otherwise
    Set Den Lights On
    Stop this shortcut
    If Staircase Light Is On
        Set Den Lights Off
    Otherwise
        Set Den Lights On
        Stop this shortcut
        If Curved Window Can Is On
            Set Den Lights Off
        Otherwise
            Set Den Lights On
            Stop this shortcut
            If Light Fixture Is On
                Set Den Lights Off
            Otherwise
                Set Den Lights On
                Stop this shortcut
                If TV Upper Gradient Light Strip Is On
                    Set Den Lights Off
                Otherwise
                    Set Den Lights On
                End If
            End If
        End If
    End If
End If

Also, just for clarity, "Stop this shortcut" isn't an "or" action. The reason why you are needing it in your shortcut is because you are turning the lights on in the previous line, so you need to quit the shortcut before the next "if" statement checks to see if a light is on.

You'll still have the "unknown" behavior mentioned above, based on whatever state each of your lights are in. If you want a more consistent/"known" behavior, it would be best to decide what you want to happen if some lights in the mix are on and others are off. Do you want to turn everything off, or turn everything on?

This example will turn everything off first if a light is on; if all lights are off, then it'll turn everything on. I know you said this didn't work before, but it should. Pay close attention to the nesting and position of the statements. Post screenshots if you still have trouble.
Code:
If TV Wall Sliding Door Light Is On
    Set Den Lights Off
Otherwise
    If Staircase Light Is On
        Set Den Lights Off
    Otherwise
        If Curved Window Can Is On
            Set Den Lights Off
        Otherwise
            If Light Fixture Is On
                Set Den Lights Off
            Otherwise
                If TV Upper Gradient Light Strip Is On
                    Set Den Lights Off
                Otherwise
                    Set Den Lights On
                End If
            End If
        End If
    End If
End If
Thanks again for the reply and all the help. Yes, that is exactly the behavior I was looking for. As I mentioned, this is a switch in a staircase that I wanted to behave in a way to turn everything off if even one light is on, or everything on if even one light is off in that whole zone, as I’m coming up or down the stairs. It’s not necessarily the main switch for each group of lights in the room. That’s why in my shortcut, I have it checking the power state of each light in that zone to see if they should all go off or all go on. To be honest, I just re-read my OP and I believe I wasn’t clear there with my goal. It was late and I was extremely frustrated lol.

There are a total of 6 of these 4-gang LIFX switches in this zone, and each of the 4 buttons has 3 actions so that’s 72 actions I can assign in total.

This switch is more of a hardwired scene controller than a switch but it can also be hardwired to a bulb via the circuit. Highly recommended, by the way.

So this switch has 4 gangs built in each one. The top button is the main zone controller which is what I was configuring for the shortcut in question. All on or all off depending if any one is on or any one is off. The second button can control just the staircase light alone which was my plan. hope this makes more sense now.

Thank you for the tip on the too many “if” statements. It’s probably out of habit I did that because it worked in all the other rooms I have one of these switches in. This is the first time I’m using it to control a whole zone of ungrouped lights. I’ll try your method of shortening it and see if it works. Would definitely save me a lot of time lol. Wondering if that’s why my nested “if” statements didn’t work. In theory, i thought it should which is why I came here seeking help. That’s also the way the Apple support page explained it but it only worked in one direction for me.

I know the “Stop this Shortcut” isn’t technically an “or” statement but it sure is behaving as such. Think I meant to write pseudo “or” like in a previous post.
So like in my shortcut, if you replace “Stop this Shortcut” with “Or” for arguments sake, it makes sense in the way I wanted it to behave which is exactly what it’s doing. I’m dreading the day I need an “and” statement lol. Not a clue what to do with that.

To be honest, after writing that shortcut, I was expecting it to take 5-10 seconds to complete. It’s really taking only 1-2 seconds. Not every bulb comes on or turns off at the exact same moment in time. Some do lag but the whole action is not more that 2 seconds in total. To add, these are all smart (Hue) bulbs. 10 of the recessed can lights, one Infuse light fixture, one play Gradient light strip, one ambiance Gradient light strip and four Play bars. Not too shabby at all.

Anyway, thanks a ton again. I’m gonna try shortening the “if” statements along with nested “ifs” again and see if that can save me some time. Got a lot of these switches to configure.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.