HomeKit Automation Tips

Getting more out of your smart home devices

Hue Dimmer Switch: Make a button toggle between different predetermined levels of brightness

Do more with the Hue Dimmer Switch (or any switch) in HomeKit!

This is the second of many tips about how you can get more out of your Hue Dimmer Switch. I’m going to talk about the Hue Dimmer Switch, but this is true for any HomeKit compatible light switch. If you can set it up in HomeKit, you should be able to do this.

UPDATE: As of the iOS 15 / tvOS 15 update, this shortcut will not work. There is a bug in iOS 15 / tvOS 15 which breaks the conditional if statements where we check for the brightness level of a light. Let’s hope Apple fixes this bug quickly.

UPDATE: It appears that the bug has been fixed with iOS 15.1 / tvOS 15.1 / HomePod Software Version 15.1.


At this point it’s important to understand that for this to work, you need to choose to configure it in the Apple Home app when you pair your Hue Dimmer Switch in the Hue app. If you’ve already configured it in the Hue app, you can always change that later. If the Hue Dimmer Switch is configured in both the Hue App and the Apple Home app, it will not work properly.

For more in-depth explanations, please check the first Do more with the Hue Dimmer Switch (or any switch) in HomeKit post.

In the entrance of our home, we’ve got a Hue Dimmer Switch with a button dedicated to toggle the hallway lights between 3 difference levels of brightness and off. If the lights are off, the lights will go to 95% with the first press, 50% on the second, 2% on the third, and finally off again on the fourth press.

We’ve got three Hue GU10 bulbs in the Hallway (named Hall spot 1, Hall spot 2 and Hall spot 3) under the group name Ceiling Lamps. When you’re using the If statement to check brightness, you have to do that for a single bulb, but you can control them as a group (that’s why the difference names in the If statement and the Set action in the picture).

By using several If statements, we are able to make one button toggle between different levels of brightness. You are of course not limited to three different levels of brightness, or a single lamp or group of lights. If you want to control more than one group of lights, you’ll just add more Set actions.


20 thoughts on “Hue Dimmer Switch: Make a button toggle between different predetermined levels of brightness”

  1. Hiya,
    I’ve got another challenge that I think should be possible but I can’t get my head around all the ifs and otherwise commands as I think there’s a lot of embedding going to be needed.
    I have a Hue Smart Button and want to configure it so that depending on conditions, it does one of three things. I think this can be done but it’s advanced.
    If the current time is between sunrise and midnight, I want it to trigger scene A (which sets the bathroom light to 100%).
    If the time is between midnight and sunrise, I want it to trigger scene B (which sets the bathroom light to 50%).
    However, no matter what the time, if the button is pushed and the bathroom light is already on, I want it to switch the light off.
    I’m pretty sure that this can be done but I’ve been messing with it for a few days and I can’t get everything in the right order.
    Do you think this is something you could help me with please?

    1. Hi again Keith 🙂 I’m happy to help!

      The solution will actually use a lot of what I wrote about in the posts “The power of the Format Date function and how to use it for shortcuts using time of day or sunrise/sunsetpart 1 and part 2.

      You could either do it with two nested if-statements or use the Exit Shortcut action and use two separate if-statements. I’ll do the latter, as nested if-statements can sometime be difficult to understand.

      I’ll write my solution in text, but if you have any questions, just drop me a line. If you check out the “The power of the Format Date function and how to use it for shortcuts using time of day or sunrise/sunset” posts, you’ll see exactly how most of this looks.

      We start by getting the time as military style time, and putting it into a number variable, starting with the Format Date action.

      Format Current Date, Date Format Custom, Format String Hmm
      Get numbers from Formatted Date
      Set variable TimeNow to Numbers

      Next, we’ll get the time of sunrise, format it to military style time and put it into a number variable.

      Get current weather at Current Location (or put your actual location here for faster result)
      Get Sunrise Time from Weather Conditions
      Format Sunrise Time, Date Format Custom, Format String Hmm
      Get numbers from Formatted Date
      Set variable SunriseTime to Numbers

      Now we’re ready to create the first if-statement that checks if the light is already on. If true, we turn the light off, and exit the shortcut.

      If BathroomLight is on
          Set BatroomLight (turn it off)
          Exit Shortcut with Result (the result can be anything)
      End If

      Now, if the shortcut is still running, it means that the light in the bathroom was not on. And we only need to check for one of your conditions, as the other must be true if the first is not. It’s important to use 2359 (11:59 PM) instead of midnight, since if we put 0 (00:00 AM), between SunriseTime and 0 is the same as between 0 and SunriseTime, (it’s only numbers).

      If TimeNow is between Sunrise and 2359
          Set Scene A
          Set Scene B
      End If

      And that should work. Let me know how it goes, and if you’ve got any questions about the solution 🙂

      1. Hi Stefan,
        Wow, that was incredibly fast, thank you. I know all about military time, I’m a ham radio operator so everything is done in 24 hour time 😀

        Part of the problem I was having was that I was trying to run the switch off after the script so I was getting the light come on but then it went straight off again. I could see why it was happening but couldn’t work out what to do to make it work properly.

        Your solution works perfectly, thank you. To test it, I changed the switchover time from 2359 to 1600 and it triggered the nighttime scene perfectly. With the time set back to 2359, it runs the daytime scene.

        Thanks again for your help. I have been able to write quite a few shortcuts already but this one was just a stumbling block for me.

        1. The ham radio thing sounds really cool 🙂 Here in Finland, where I’m from, we use the 24-hour clock a lot. I’m happy that it solved the problem for you. Many times, trying to run these shortcuts in your head, or with a pen and paper, you might find out how to restructure them or changing the order to get it working. These shortcuts can be really fun problem-solving puzzles.

          1. I’ve made a very slight tweak, I’ve moved the “if light is on” section right to the top so that it doesn’t need to do any time of day checking before turning the light off. There’s no point in checking for sunrise and setting the variable if all it’s doing is turning the light off when it’s already on 🤠

            1. That’s a very good optimization. I often go back to shortcuts I’ve created long ago but that are still active, and find ways to make them more effective 🙂

  2. I’m attempting to just copy the functionality of my hue dimmer switch, and I’m glad that you figured out the actual dimmer part. However, the dimmer’s “on” button triggers a different scene each time you press it, and that’s what I’m having a hard time replicating. The “set scene” action is easy to find, but is there an “if this scene is active” conditional I’m not seeing? It looks like I can only check the stats on an individual bulb, which doesn’t help if a scene sets multiple bulbs to different values.

    1. Hi Greg,
      You are correct, there isn’t a way to query which scene, or even if a scene is active. As far as I know, there’s only two ways around it.

      If you’re using Homebridge/Hoobs, you could create some kind of variable which you then could set with scenes as well as query.

      Otherwise, if you’re able to have one lamp somewhere that is part of every scene, and it changes brightness between scenes, you could use that as the “variable” to check which scene is active.

  3. Hi Greg,

    thank you very much for that tutorial. That’s what I was looking for long time.
    Did you also have the delays, wenn you press a button? Are the Shortcuts so slow?

    Thank you very much for your response.

    Best regards

    1. Hi Tristan,
      Thank you for your comment. As far as the delays go, sometimes there is no delay, sometimes there is a delay of several seconds. It seems like the longer delays happen more often with dimmer switches that are far away from the Hue Bridge. It also seems like they’ve become a bit more frequent with the iOS/tvOS 15 update. The shortcuts themselves run very quickly, so I’m not quite sure what the problem is. Sometimes rebooting the router, HomeKit hub (AppleTV) and Hue Bridge helps.

      1. Hello Stefan,

        Thank you for your quick reply.

        I don’t think the delays can be explained like that. I restarted the router and Apple TV. However, I also have several HomoPod Mini in use. Even if I stand next to the Hue Bridge with the Hue Dimmer Switch, it does not change the delays.

        As can be seen in the video, the lamps react immediately to switches 1 and 4. There is no shortcut stored there. On switch two, I then have the delays due to the shortcut.


        Do you perhaps have another idea?

        Thank you very much

        1. Have you checked which HomeKit hub is the active one (connected instead of standby). You can check that in the Home app under Home Settings, Home Hubs & Bridges. The problem is you can’t select which one to be the active one. The only way is to remove power from all of them and plug in the one you want to be the active one first. I’ve got two AppleTV 4K (an older and a newer) and a HomePod Mini. The AppleTVs are connected via ethernet, so I always want one of them to be the active one. I can’t say that I’ve noticed more latency when the HomePod is the active hub but knowing that wired is always more stable than wireless, that’s how I want it.

          I just reprogrammed two buttons on my test Hue Dimmer Switch (I’ve got one just for trying out stuff) and set one to turn on a light without a shortcut, and another to use a shortcut to toggle between 50%, 100% and off. There was a very slight difference in latency, but hardly perceptible. However, we also have a Hue Dimmer Switch in the bedroom next to the bed, where one button only turns on the Good Night Scene (no shortcut involved). That one sometimes works without any delay, but at times it has taken it close to 5 seconds to complete.

          All I can say is that I’ve sometimes had the same problems as you, but I haven’t been able to pinpoint what is causing the delay, since it hasn’t been completely consistent. However, when there is latency, it usually behaves that way for 5 to 10 minutes before working without latency again, which has had me thinking that something else is going on in the Hub and everything is slowed down.

          I’m sorry I can’t be of more help.

          1. Hi Stefan,

            Exactly, I also wanted to look at the control centers, but forgot about it. As can be seen in the pictures at https://www.icloud.com/sharedalbum/#B0S5FrPQ6HkAGl, my AppleTV was deactivated. I can’t say why that was the case. I also unplugged the HomePod Bad in the bathroom and tested it again after the AppleTV was connected. The delays are the same.
            The AppleTV is connected via WiFi because I don’t have network cabling in my apartment.

            For the sake of completeness, I have still saved my shortcut for button 2 to the album. https://www.icloud.com/sharedalbum/#B0S5FrPQ6HkAGl

            Thanks to you and your blog, I’m one step further. Thank you for that and for your time to answer me detailed.

            Thank you and greetings

            1. Looking at your screenshots (and by the way, thank you for sharing the video and screenshots), I’m wondering if you are triggering the lights in the shortcut with a scene. If so, could you try changing the shortcut and instead of selecting the scene, select the lights and set them to the correct brightness. I sometimes have a feeling that scenes trigger more slowly than controlling the lights directly.

              1. Yes, i did it with scene. Don’t ask me why. Sometimes it’s easier.
                But I tried it with selected lights. The delays are the same unfortunately.

                Did you ever created and tested a HomeKit shortcut on the Mac? There you can watch the shortcut running. I posted a screencast in the shared album. https://www.icloud.com/sharedalbum/#B0S5FrPQ6HkAGl

                If I testet the shortcut on the Mac, the delays not as long as on the Hue dimmer switch. I think it cuts the duration by 50%.

                1. You are absolutely correct that scenes are useful when manipulating more lights at once in a shortcut, especially if you need to edit or rewrite the shortcut when testing.

                  Testing on different platforms, it seems like the mac is the fastest, then my iPhone, and the Dimmer Switch is the slowest. But usually, the Dimmer Switch is not so slow that I think about it, only sometimes.

                  Now, where the delay is introduced is the real question. When using the dimmer switch there is of course some routing going on. Your Hue bulbs are creating a mesh network to make it work over a larger distance. I wonder if there is a possibility that the command goes via several bulbs before getting to the Hue bridge. It then goes to the HomeKit Hub which runs the shortcut. The command to manipulate the light has then to go out via the Hue bridge again, and perhaps via several other bulbs.

                  If you are able to and want to test, you could always take the AppleTV to your router and connect with an ethernet cable, check that none of the other HomeKit hubs are active, and then test if the delay is shorter. But I would guess the difference would be insignificant.

                  In the end, it’s difficult to problem solve these issues, especially if they are not consistent.

  4. Hi Stefan,

    I tested again and now integrated a 3th party app in my tests. Maybe you know Controller for HomeKit https://apps.apple.com/en/app/controller-for-homekit/id1198176727

    Automations created with Controller for HomeKit work without delay.

    However, 3 individual automations are necessary for this, and not a complete one as with Apple HomeKit.
    Press → On → press → 50% → press → Off

    I also have to force automations to use scenes or create new scenes, because without them you can’t control lamps or other devices, I learned from the developer. Apple only allows scenes.

    But why are the automations created with Controller for HomeKit faster than that in the Home app with shortcuts?

    I would like to understand it and I think you would also like to understand it.

    In the shared album are 4 more screenshots and 1 video showing the difference in control. Switch 3 is programmed with the HomeApp and shortcuts and switch 4 with Controller for HomeKit. https://www.icloud.com/sharedalbum/#B0S5FrPQ6HkAGl

    Best wishes

    1. Yes, I’ve got Controller on my phone, but haven’t really had time to look any closer at it. I also like doing all the automations in HomeKit, so that’s another reason I haven’t done anything with it.

      Looking at your video, it almost seems the problem is in HomeKit. It’s also interesting that it’s consistently slow for you, and more sporadically for me.

      It might be that we need to wait for an update from Apple to fix this for HomeKit.

Leave a Comment

Your email address will not be published. Required fields are marked *