Controlling Hue Bulbs With Harmony on a Mac

I wanted to be able to press a button on my harmony smart control to turn on my Hue bulbs.

I'll briefly describe how I did this.

Harmony Configuration

First, you need to configure your harmony to work in Plex mode with your Mac activity and install Remote Buddy on your mac.

The Remote Buddy configuration I used is described here, and is very time consuming.

NOTE: you will need to choose the second type of apple remote when setting up the hardware remotes, it defaults to the first type which has fewer buttons and will not work. The black one, not the white one.

Hue Control Script

Next we are going to write a little Python program to turn the Hue lights on and off, here is mine:

#!/usr/bin/env python

import socket, os.path, sys
from phue import Bridge

bridge = Bridge('rafael_living_hue')

arg = sys.argv[1].lower() if len(sys.argv) > 1 else 'toggle'

    on_state = { 'on': True, 'off': False, 'toggle': not bridge.get_group(1, 'on') }[arg]
except KeyError:
    raise ValueError("command must be 'on', 'off' or 'toggle'")

bridge.set_group(1, { 'hue': 33862, 'sat': 50, 'bri': 254, 'on': on_state }, transitiontime=0)

You will need to install phue, as described here:

NOTE: I use the Homerew Python, I recommend you do the same.

The Bridge call takes a Hue bridge IP address, I recommend assigning a static DHCP lease on your router and rebooting the bridge to use it. This will give you a nice hostname like the one I'm using here.

This script will set the Concentration theme. If you want another theme, set it first using another app on your phone or whatever, then use get_light to read the hue, sat and bri values you need from one of the lights.

Someone mapped the values for the default themes here:

NOTE: you will need to test the script before we map it in Remote Buddy, and the first time you run it you will need to press the link button on your bridge first.

Put the script somewhere like:


Make sure to chmod +x it so it is executable.

Remote Buddy Mapping

- - - From the Remote Buddy menu, choose Behaviour Construction Kit and make a new action in the Action Factory pane. I called mine "Toggle HUE" in group "HUE".

Under implementation add Applescript, and for the code add the following:

do shell script "/Users/your-user/bin/toggle_hue"

replace the path with the actual path of the executable script. If the script is not executable, prepend the path with "python " to run it with python.

Next, in the Metadata pane choose "Action globally available".

Close the Behaviour Construction Kit and open Preferences, go to the Mapping pane.

Go to the very top entry, Global Mappings. Find the button according to the Plex mapping described in the first section, I use the Yellow button, which is Remote 159 Select. For the action, go to "Miscellaneous" and your new global action should be there, choose it.

Now you can test the button on your harmony and it should toggle your lights on and off.

UPDATE: I added vastly better Python code for the hue toggle script.

Last modified: 2017-1-8 (日) at 9:14 pm