Jump to content
benknight

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

Share this post


Link to post

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!

Share this post


Link to post

Good idea!  The "all" option in the lights menu is a no brainer.  I'll add that soon.

 

I'll also be pushing a fix that makes the filter script run much faster.

 

Please let me know if you run into any issues!

 

Ben

Share this post


Link to post

Workflow looks great and very useful for me.

Unfortunately I instantly get "No bridges found on your network" when typing setup-hue in alfred.

(Running Mavericks)

Share this post


Link to post

Love this workflow. Thanks for your work an sharing. I'm new the the Philips hue and was hoping to find a gerat workflow here. So I did. :)

Groups would be great in the Workflow. Hope development is going on. Thanks again.

Share this post


Link to post

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).

Share this post


Link to post

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.

Share this post


Link to post

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

Share this post


Link to post

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'

Share this post


Link to post

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

Share this post


Link to post

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

Share this post


Link to post

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.

Share this post


Link to post

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

Share this post


Link to post

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.

Share this post


Link to post

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

Share this post


Link to post

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

Share this post


Link to post

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

Share this post


Link to post

Hi,

 

is it o.k. that the white (only) bulbs are not shown??

 

I can only see and control the coloured hue bulbs...??????????????????????

 

 

Thanks

Share this post


Link to post

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...