Jump to content

Philips Hue Controller Workflow


Recommended Posts

Philips Hue Controller for Alfred

Quickly and easily control Philips Hue lights with Alfred.

index.png

Installation

  1. Download the workflow

  2. The first time you run the workflow it will ask you to press the button on top of the Hue bridge then action the item to authorize the workflow to control your Hue lights. The workflow automatically attempts to find the bridge on your local network. You can also manually specify the bridge's IP address. For example, if your bridge's IP is 192.168.1.126:

 

hue 192.168.1.126

 

Read more about features at the project's Github page.

Edited by benknight
Linking to latest release so I don't have to manually update the download link every gd time
Link to comment

F-ing awesome! Looking forward to the updates you have planned. Saving light-states as presets will be a great feature. I'd also like to see an "All" option under "Hue Lights". That way colors/brightnesses/etc. can be applied to all lights at once or individual lights.

 

Keep up the good work!

Link to comment
  • 3 months later...
  • 2 weeks later...
  • 4 months later...

UPDATE — I just edited the original post to release version 2.0 of this workflow to you all!

 

Features include:

  • 'Lights' is now the index result set.
  • New 'All Lights' option for setting the state for all lights in one command.
  • Lights icons are now the actual current light color!
  • Save presets states for all lights.
  • Set which lights the workflow controls using easy group management via `-hue set-group`
  • Set reminders (blink lights after some time delta).
Link to comment

thanks for your work and the update.

unfortunately the workflow didn't work anymore after updating.

what I can do is -hue set-bridge and the bridge is connected but after that when I type hue there is nothing to select.

I removed the workflow and installed it again but no hue, nowhere. 

Thanks in advance for your help.

Link to comment

Oh no!  If anyone's having issues can you make sure Alfred 2 is completely up to date and then try this:

 

1. Open up Alfred Preferences

2. Go to Workflows

3. Select the Philips Hue Controller workflow

4. Click the "Debugger" icon

 

Looks like this (the first one on the left):

 Screen%20Shot%202014-03-20%20at%209.22.4

 

5. Type "hue" into Alfred

6. Copy and paste what was spit out into the Debugger console.

 

That should tell me what's going wrong.

 

Thanks!

Ben

Edited by benknight
Link to comment

Thanks for your reply Ben.

Here's the content from the Debugger console

 

 

Starting debug for 'Philips Hue Controller'

 

[ERROR: alfred.workflow.input.scriptfilter] Code 1: Traceback (most recent call last):

  File "hue_filter.py", line 181, in <module>

    results = hue_filter.get_results(alp.args())

  File "hue_filter.py", line 143, in get_results

    lights = self._get_lights()

  File "hue_filter.py", line 96, in _get_lights

    self._load_lights_data_from_api()

  File "hue_filter.py", line 63, in _load_lights_data_from_api

    self._create_light_icon(lid, light_data)

  File "hue_filter.py", line 76, in _create_light_icon

    light_data['state']['xy'][0],

KeyError: 'xy'

[ERROR: alfred.workflow.input.scriptfilter] Code 1: Traceback (most recent call last):

  File "hue_filter.py", line 181, in <module>

    results = hue_filter.get_results(alp.args())

  File "hue_filter.py", line 143, in get_results

    lights = self._get_lights()

  File "hue_filter.py", line 96, in _get_lights

    self._load_lights_data_from_api()

  File "hue_filter.py", line 63, in _load_lights_data_from_api

    self._create_light_icon(lid, light_data)

  File "hue_filter.py", line 76, in _create_light_icon

    light_data['state']['xy'][0],

KeyError: 'xy'

Link to comment

That's a pretty strange error and there are a few possible scenarios going on here that I can imagine.

 

The error is telling me that a certain light attribute isn't present even though it's documented in the Philips Hue Lights API.  I wonder if maybe your bridge's software is out of date.  If you try using the iPhone or Android app does it prompt you to update?

 

There also might be some edge case here which I haven't accounted for.  Is there anything out of the ordinary going on with your Hue lights?  If you turn all of them on do you still get that error?  How many bulbs are there?  What happens if you type "-hue" and try to set the group or save the current state?

Edited by benknight
Link to comment

Thanks for your reply Ben.

 

I use the latest hue Bridge Firmware. And with the hup iOS App everything work as expected.

There are 12 Lights (5x hue bulbs, 5x LivingWhites Adapter, 1x LivingColors Bloom, 1x LivingColors Iris).

Also with third party Apps everything is good.

 

What I noticed is that when I typ  the word hue in Alfred starting with the letters hu in the list there is your hue workflow alongside withe other OS X App with the name hue. When the word hue is finished, your workflow is not in the Alfred list.

Select your workflow when its up in the list with hu it brings me the default search. (see screenshot)

 

Sorry that there is not more I can say. :/

 

Thanks again for your Ideas on this.

 

Bildschirmfoto%202014-03-21%20um%2023.50

Link to comment

Now I totally see why!  It's because you have lights on the system that aren't hue bulbs (5x LivingWhites Adapter, 1x LivingColors Bloom, 1x LivingColors Iris), which I haven't tested this workflow with.  I will fix this is an update.  Sorry for the inconvenience.  As a temporary fix, you can find out the ID number of each bulb and use the "-hue set-group" command so that you're only controlling the hue bulbs which I'm pretty sure will prevent this error.

Link to comment
  • 1 month later...

Ben, first and foremost, AMAZING workflow!!!! Thank you!

 

I have a small suggestion, would it be possible for you allow for the user to set the IP of their HUE bridge via the "-hue set-bridge" command? Something like "-hue set-bridge 192.168.2.20".

 

The reason why is because for people like me that get an empty response from "http://www.meethue.com/api/nupnp", we are not able to get the bridge to pair. I had to modify the setup.py script so that I could pair my bridge.

 

You can see in bold the change I made below. I know that it is not a good permanent change, but it was good enough for me to get it to work.

 

class HueAlfredSetup:

    def setup(self):
        r = requests.get('http://www.meethue.com/api/nupnp')
        bridges = r.json()
       

        # Changed "If not" to an "If" so that it skips to the else.
        if bridges:
            print 'No bridges found on your network.'
        else:
            # Statically assigned the IP address of my bridge.

            bridge_ip = '192.168.2.20'
            settings = alp.Settings()

            # Create API user for the workflow
            r = requests.post(
                'http://{bridge_ip}/api'.format(bridge_ip=bridge_ip),
                data=json.dumps({'devicetype': 'Alfred 2'}))

            resp = r.json()[0]

            if resp.get('error'):
                print 'Setup Error: %s' % resp['error'].get('description')
            else:
                settings.set(bridge_ip=bridge_ip, group='')
                settings.set(username=resp['success']['username'])
                print 'Success! You can now control your lights by using the "hue" keyword.'

        return None

Link to comment
  • 4 weeks later...

Ben, first and foremost, AMAZING workflow!!!! Thank you!

 

I have a small suggestion, would it be possible for you allow for the user to set the IP of their HUE bridge via the "-hue set-bridge" command? Something like "-hue set-bridge 192.168.2.20".

 

The reason why is because for people like me that get an empty response from "http://www.meethue.com/api/nupnp", we are not able to get the bridge to pair. I had to modify the setup.py script so that I could pair my bridge.

 

You can see in bold the change I made below. I know that it is not a good permanent change, but it was good enough for me to get it to work.

 

class HueAlfredSetup:

    def setup(self):

        r = requests.get('http://www.meethue.com/api/nupnp')

        bridges = r.json()

       

        # Changed "If not" to an "If" so that it skips to the else.

        if bridges:

            print 'No bridges found on your network.'

        else:

            # Statically assigned the IP address of my bridge.

            bridge_ip = '192.168.2.20'

            settings = alp.Settings()

            # Create API user for the workflow

            r = requests.post(

                'http://{bridge_ip}/api'.format(bridge_ip=bridge_ip),

                data=json.dumps({'devicetype': 'Alfred 2'}))

            resp = r.json()[0]

            if resp.get('error'):

                print 'Setup Error: %s' % resp['error'].get('description')

            else:

                settings.set(bridge_ip=bridge_ip, group='')

                settings.set(username=resp['success']['username'])

                print 'Success! You can now control your lights by using the "hue" keyword.'

        return None

 

Hey carbon copy, I'm surprised you're having this issue.  As far as I know all Hue devices would depend on this public endpoint working.  I think what you did (manually editing the script) is probably the best approach here.  I would hesitate to program a feature for this because I can't imagine this is a common problem.

Link to comment

Thanks for posting this! I finally got this working after changing as noted.

 

 

 

Ben, first and foremost, AMAZING workflow!!!! Thank you!

 

I have a small suggestion, would it be possible for you allow for the user to set the IP of their HUE bridge via the "-hue set-bridge" command? Something like "-hue set-bridge 192.168.2.20".

 

The reason why is because for people like me that get an empty response from "http://www.meethue.com/api/nupnp", we are not able to get the bridge to pair. I had to modify the setup.py script so that I could pair my bridge.

 

You can see in bold the change I made below. I know that it is not a good permanent change, but it was good enough for me to get it to work.

 

class HueAlfredSetup:

    def setup(self):
        r = requests.get('http://www.meethue.com/api/nupnp')
        bridges = r.json()
       

        # Changed "If not" to an "If" so that it skips to the else.
        if bridges:
            print 'No bridges found on your network.'
        else:
            # Statically assigned the IP address of my bridge.

            bridge_ip = '192.168.2.20'
            settings = alp.Settings()

            # Create API user for the workflow
            r = requests.post(
                'http://{bridge_ip}/api'.format(bridge_ip=bridge_ip),
                data=json.dumps({'devicetype': 'Alfred 2'}))

            resp = r.json()[0]

            if resp.get('error'):
                print 'Setup Error: %s' % resp['error'].get('description')
            else:
                settings.set(bridge_ip=bridge_ip, group='')
                settings.set(username=resp['success']['username'])
                print 'Success! You can now control your lights by using the "hue" keyword.'

        return None

Link to comment
  • 4 months later...

Does anyone know how I can customize this workflow so that I can quickly access presets with a keyword like "hue p" ? 

I would also like to know how to quickly access the presets, but I'd like do it by using a hotkey (like using one of the function ('F') keys on my keyboard to go strait to the presets).

 

Any suggestions would be greatly appreciated... Thanks!

Edited by m021478
Link to comment

Hi,

 

your workflow is really really great!!!

 

But I have one problem:

 

Alfred doesn't sync the hue presets over dropbox sync???

 

Is it my fault...??? I don't know....can you help me?

 

Thanks a lot...

Edited by ST1
Link to comment
  • 2 weeks later...

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...