The ability to smartly turn your voice on and off is one of the best things about a smart home. If you don’t have an Amazon Echo or Google Home, although you prefer keyboard shortcuts, you can use the AutoHotkey script to control your Philips Hue lights from your computer.

RELATED: Beginner’s Guide to Using AutoHotkey Script

In this tutorial, we’re going to use AutoHotkey, an amazing little program that allows you to write your own automation scripts and even remap keys on your keyboard. If you’re new to AutoHotkey or need to download it on your Windows PC, check out our beginner’s guide here.

What you need

We’re going to show you a basic script that you can use to turn a set of lights on and off (which you can customize later). Before we do that, you’ll need a few things.

  • Windows machine with AutoHotkey installed: if you haven’t already, you can download AutoHotkey here. Unfortunately, it is only available for Windows computers. The application will run in the background and interpret the scripts you create (usually in programs like Notepad).
  • Your Philips Hue Bridge IP address: you will need to enter your bridge’s IP address into the script for it to work. We’ll tell you how to find this information below.
  • Philips Hue Developer API username. The script we are using also uses the Developer API. In order to use it, you need to have an account and know the developer’s API username. Once again, we will show you how to get an account and find your ID below.
  • Autohotkey script: in the next big section below we will see the script that this tutorial is based on. Reddit user tardit created a template that we will use here if you want to go deeper into it. However, we have tweaked this script to make it easier. Copy the script from the section below, paste it into an empty Notepad document, and then save it with a name such as hueshortcut.ahk .

If you already know your bridge IP address and API username, you can skip it.

How to Find Your Bridge’s IP Address

The IP address of your bridge is relatively easy to find. Follow this link and sign in to your Philips Hue account.

At the top of the page, click Bridge.

Click the «Show more bridge details» button.

Write down your internal IP address. You will need this later.

Hold on to that for the next section.

How to get a Hue Developer API account

If you don’t have a Hue Developer account yet, or if you’ve forgotten your API username, you need to get one now. This part is a bit tricky, but if you’re comfortable using a few text commands, things should be easy. Start by heading here and creating a new developer account with Hue.

You will receive an email asking you to verify your account and create a password. Once this is done, navigate to the following URL, replacing to the IP address you took from the previous section.


Here you will see a tool that allows you to manually send commands to your Hue bridge. If you don’t understand everything on this page, you’re fine. You only need to use this tool to get the username of the API. To do this, enter /api/ in the URL field. AT {"devicetype":"my_hue_app#iphone peter"} messages» enter {"devicetype":"my_hue_app#iphone peter"} replacing iphone peter to whatever descriptor you want, preferably one that describes the device you’re using it on.

Once you have entered all the information, click on the link button on the Hue bridge. This is a security step to make sure only you or someone in your home can create apps to control your light. After you have clicked the link button on your bridge, click POST.

In the Command Response field, you should see a result similar to the one below (without the censor blur, of course). You will be given a long randomized username. Copy it somewhere and save it. You will need it for the script later.

Now that you have these two pieces of information, you are ready to customize your script!

How to set up an AutoHotkey script

As I mentioned earlier, for this tutorial we are using redroitor tarrosion’s modified version of this script. We’ve set it up to add shortcuts so you can turn a group of lights on and off at once instead of all the lights in your home. Here are the following hotkeys that you will be able to use with this script:

You can create or modify as many light groups as you need. For this example, I created two groups of two lights each, one for the office and one for the living room. You can change their names as you wish. You may also need to change the values ​​of each group depending on how many lights you have.

First, copy the script below into a Notepad document and save it as something like «huelights.ahk», making sure to change the .txt extension to .ahk. Without this, Notepad will save it as a text file and AutoHotkey won’t be able to run it.

 WinHTTP := ComObjCreate("WinHTTP.WinHttpRequest.5.1") lightsOn := 1 office := [1,2] livingroom := [3,4] curgroup := office  WinHTTP := ComObjCreate("WinHTTP.WinHttpRequest.5.1") lightsOn := 1 office := [1,2] livingroom := [3,4] curgroup := office lightoff (light, ByRef WinHTTP) {WinHTTP.Open ("PUT", "http: // <ваш-IP-адрес вашего моста> / api / <ваше-api-имя пользователя> / lights /". light . "/ state", 0) bodytext = {"on": false} WinHTTP.Send (bodytext) return} lighton (light, ByRef WinHTTP) {WinHTTP.Open ("PUT", "http: //  / api /  / lights / ". Light." / State ", 0) bodytext = {" on ": true} WinHTTP.Send (bodytext) return} setlightct (light, newct, ByRef WinHTTP) {WinHTTP.Open ("PUT", "http: // <ваш-bridge-IP-адрес> / api / <ваше-api-имя пользователя> / lights /". light. "/ state", 0) bodytext = {"ct":% newct%} WinHTTP.Send (bodytext)} modifylightct (light, amount, ByRef WinHTTP) {WinHTTP.Open ("PUT", "http: //  / api /  / lights / ". light." / state ", 0) bodytext = {" ct_inc ":% amount%," transitiontime ": 2} WinHTTP.Send (bodytext)} modifylightbrightness (light, amount, ByRef WinHTTP) {WinHTTP.Open ("PUT", "http: // <ваш-IP-адрес вашего моста> / api / <ваше-api-имя пользователя> / lights /". li  гхт  "/ state", 0) bodytext = {"bri_inc":% amount%, "transitiontime": 2} WinHTTP.Send (bodytext)}; ctrl-alt-1: перейти в группу 1 ^! 1 :: curgroup: = возврат в офис; ctrl-alt-2: перейти в группу 2 ^! 2 :: curgroup: = возвращение в гостиную; ctrl-alt-o: включить подсветку группы ^! o :: for _, включить свет в curgroup lighton (light, WinHTTP ) return; ctrl-alt-i: выключить подсветку группы ^! i :: for _, подсветка в curgroup lightoff (light, WinHTTP) return; ctrl-alt-l: переключить все подсветки ^! l :: WinHTTP.Open ( "PUT", "http: // <ваш-IP-адрес вашего>> api / <ваше-api-имя пользователя> / groups / 0 / action", 0), если lightsOn> 0 bodytext = {"on": false } else bodytext = {"on": true} WinHTTP.Send (bodytext) lightsOn: = 1 - lightsOn return;  ctrl-alt-k: все индикаторы выключены ^! k :: WinHTTP.Open ("PUT", "http: // <ваш-bridge-IP-адрес> / api / <ваше-api-имя пользователя> / groups / 0 / action ", 0) bodytext = {" on ": false} WinHTTP.Send (bodytext) lightsOn: = 0 return; ctrl-alt-Up: увеличить теплоту текущей группы источников света ^! Up :: for _, источник света в curgroup modifylightct (light, 43, WinHTTP) return; ctrl-alt-Down: уменьшить теплоту текущей группы источников света ^! Down :: for _, источник света в curgroup. modifylightct (light, -43, WinHTTP) return; ctrl-alt-Left: увеличить яркость группы освещения ^! Left :: for _, свет в curgroup modifylightbrightness (light, -32, WinHTTP) return; ctrl-alt-Right: уменьшить яркость группы света ^! Right :: for _, light в curgroup modifylightbrightness (light, 32, WinHTTP) возврат 

Now you need to make a couple of settings. First, in the script, replace each instance to the IP address you received from your bridge earlier. Then replace with your Hue API username. In the script above, there should be seven instances of each.

Next, you’ll see a section at the top that defines the groups you can manage. This section looks like this:

  офис: = [1,2]
 гостиная: = [3,4] 

The first two lines define your light groups. Each light bulb is assigned a number, although it is not always obvious which number each of your lights corresponds to. The easiest way to check this is to open the Hue app and tap Settings, then tap Adjust Lighting.

Here you will see a list of all your lights. Count each one down to find out what number you have. For example, two lights in my office are at the top, so they should be 1 and 2. Below are my living room lights, so they should be 3 and 4. If you removed and added new lights from your setup, these numbers might shift a bit, so test your scenarios and use a small trial to make sure you are using the correct lighting.

Once you have found the numbers that match your lights, change them in the two lines above. You can also change the name of each of the groups if you like. Just make sure you change each instance this group name in the script. If you want to add a third group (or more), create a new line below the first two using the following format, replacing X, Y with the numbers of lights you want to add to this group:

  имя комнаты : = [X, Y] 

You will also need to add another shortcut to get to the third group. Select the next text block in the script above and make a copy of it below this text block, changing all 2’s to 3’s and changing «living room» (or whatever name you gave your second group) to the name of the third group:

  ; ctrl-alt-2: перейти в группу 2
  ^! 2 ::
  curgroup: = гостиная

If you’re familiar with AutoHotkey, you can further customize this script to add new shortcuts or control your lights in different ways. Check the AutoHotkey documentation if you need help. You can also check out the Philips Hue API here for more commands you can integrate into your script.

Похожие записи