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.
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.
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
20 thoughts on “Hue Dimmer Switch: Make a button toggle between different predetermined levels of brightness”
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.
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/sunsetā part 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 š
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.
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.
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 š¤
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 š
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.
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.
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?
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.
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.
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.
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.
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.
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.
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
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.
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.
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/sunsetā part 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 š
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.
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.
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 š¤
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 š
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.
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.
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
Tristan
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.
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.
https://share.icloud.com/photos/0ET4lZM6KgaU4mkWpfll3xokg
Do you perhaps have another idea?
Thank you very much
Tristan
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.
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
Tristan
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.
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%.
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.
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
Tristan
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.
Yes, you are right Stefan.
We need to wait.
Do you know a way to tell Apple about these delays?
I’ve been using the Apple Product Feedback page, this is for the Home App: http://www.apple.com/feedback/home-app/
I have a feeling that the more reports they are getting on an issue, the higher the chance that they will act on it š