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.

Advertisements

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.

 
Advertisements

6 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?
    Thanks.

    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
      OtherWise
          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 🙂

Leave a Comment

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