Philips Hue plugin

Questions and comments specific to a particular plugin should go here.
Post Reply
Aquila
Experienced User
Posts: 87
Joined: Wed Jan 28, 2015 2:49 am

Philips Hue plugin

Post by Aquila » Sun Feb 01, 2015 9:57 pm

This is a plugin for Philips Hue, more info about Philips Hue here: http://www2.meethue.com/en-xx/

Features:
- Controll Philips Hue Lights (on/off, dim, brightness, saturation, color, effects)
- Controll groups of Philips Hue lights
- Add/delete/modify groups of Philips Hue Lights
- Make bridge search for new lights and sensors
- Get status of lights and sensors
- Get events when light gets reachable by Hue Bridge
- Get events when sensors change state
- Get events when Hue switch button is pressed
- Get event when light is changed by other app

Note:
- There is no checking of the inputs from the configdialogs for the actions (and the plugin). If you enter incorrect data the action will fail.

Install procedure:
1. Put __init__.py in the folder ...\EventGhost\plugin\PhilipsHue
2. Restart EventGhost and add the plugin PhilipsHue to your configuration.
3. Write the IP-address of your Hue Bridge in the configuration and choose a Device name.
4. Push the "Get username from bridge" button in the configuration, and then the button on the Hue bridge before you click OK in the dialog that appeared. (You have 30 seconds to press OK from pushing the button on the Hue Bridge.)
5. Start using the plugin.

Upgrade procedure:
1. Exit EG
2. Replace __init__.py file in folder ...\EventGhost\plugin\PhilipsHue
3. Restart EventGhost

Changelog:
0.4.3 by Aquila 2018-03-03
- Fixed bug in SaveStatus where non-colored lights made an error. (Thanks to stoffix for reporting the bug.)
- Fixed bug in "Search for new lights"
0.4.2 by Aquila 2016-10-18
- Non-colored lights now handled correctly by eventthread.
- Buttonstate switches now correctly supported.
0.4.1 by Aquila 2016-10-05
- Searching for new sensors on init added.
- Removed fetching of current position of daylight sensor in config. Due to change in Hue Bridge behaviour.
- In ChangeLight there is now the posibility to choose if the light is turned on or not by the command.
- Fixed unhandled exception that crashed the plugin if a light with no colormode was changed by another app.
- Fixed error where the light change event triggerd even if change was by this plugin on systems where lights where not in numerical order from Hue Bridge.
- Plugin now catches daylight sensor changes.
- Events from changes in light status now has the new changed setting as payload.
0.4.0.1 by Aquila 2016-04-30
- Eventthread now detects errors in list of lights in groups, so that it does not try to get list of lights from deletede groups.
0.4.0 by Aquila 2016-04-06
- Plugin should now get button pushed event from all types of switches. (As requested by Windhowl.)
- Changes in light status NOT made by this plugin will trigger event: PhilipsHue.<light #>.changed
- createScene no longer requiers 3. string to be "<New Scene>" to create a NEW scene. 3. string still needs to be existing scene to override. (Thanks to yokel22)
- Fixed bug in error output in functions "isGroupOn", "getGroupStatusAsCommand" and "getStatus" when plugin set to print everything. (Thanks to yokel22)


Here you will always find the latest version of the plugin:
__init__.py
Version 0.4.3 - 03.03.2018
(124.04 KiB) Downloaded 103 times
Older versions:
__init__.py
Version 0.4.1 - 05.10.2016
(122.86 KiB) Downloaded 311 times
Last edited by Aquila on Sat Mar 03, 2018 10:48 am, edited 17 times in total.

goodcoproflcop
Posts: 21
Joined: Tue Aug 13, 2013 2:18 pm

Re: Philips Hue plugin

Post by goodcoproflcop » Tue Feb 03, 2015 10:09 am

Nice work, I don't have any Hue lights to test it yet. Can you tell us how you are using it atm? Also, does the hue tap work as well?

Aquila
Experienced User
Posts: 87
Joined: Wed Jan 28, 2015 2:49 am

Re: Philips Hue plugin

Post by Aquila » Tue Feb 03, 2015 10:33 am

goodcoproflcop wrote:Nice work, I don't have any Hue lights to test it yet. Can you tell us how you are using it atm? Also, does the hue tap work as well?
So far I use it to dim the lights when I turn on a movie. And I have a IR-detector outside my sons room (I use the Tellstick Duo plugin with the IR detector), if movement is detected after bedtime the lights in my bedroom and homeoffice flash red for 30 seconds. I have plans to setup diffrent scenarios to choose from in my web-controll of the house. I have tested the scenarios directly in EG, but I have not had time to implement it in my web-controll-interface yet.

The Philips Hue is very responsive, mush faster than the Tellstick. And you can check the status of the light if you want.

I do not have the Hue tap, so it is not implemented in the plugin. As far as I can see the python libary I use does not support the Hue Tap. In all, the python libary I use is not that easy to use for events as for actions. So I have just started testing if it would be easier for me to just implement the Hue API directly in the plugin. But this requiers much more work on my side, and I have just had the Philips Hue since friday. :p If the Hue Tap is as responsive as the rest of the Philips Hue system, it is a good remote. But 3 buttons limits the uses, but could be a nice way to increase the WAF.

goodcoproflcop
Posts: 21
Joined: Tue Aug 13, 2013 2:18 pm

Re: Philips Hue plugin

Post by goodcoproflcop » Tue Feb 03, 2015 11:43 am

Awsome :) Atm i'm using all kinds of 433mhz devices for our automation, with EventGhost to make all the scenes and timers, but the hue/zigbee protocol looks promising.

And indeed, the WAF is the main reason i asked about the Hue Tap haha. I'm using wall mounted 433mhz switches atm, but these use batteries (and 433mhz is easy to abuse). The Hue Tap contains an Enocean switch module (https://www.enocean.com/en/enocean_modules/ptm-215/) these are used in a wide range of "normal" looking wall switches: https://www.enocean-alliance.org/en/products/

Anyway; keep up the good work!

Aquila
Experienced User
Posts: 87
Joined: Wed Jan 28, 2015 2:49 am

Re: Philips Hue plugin

Post by Aquila » Tue Feb 03, 2015 3:07 pm

goodcoproflcop wrote:Awsome :) Atm i'm using all kinds of 433mhz devices for our automation, with EventGhost to make all the scenes and timers, but the hue/zigbee protocol looks promising.

And indeed, the WAF is the main reason i asked about the Hue Tap haha. I'm using wall mounted 433mhz switches atm, but these use batteries (and 433mhz is easy to abuse). The Hue Tap contains an Enocean switch module (https://www.enocean.com/en/enocean_modules/ptm-215/) these are used in a wide range of "normal" looking wall switches: https://www.enocean-alliance.org/en/products/

Anyway; keep up the good work!
I have a Hue Tap in order, so I will try it out when it arrives. I currently use a 433mhz remote with Tellstick, and it's slow. So very excited to see what can be done with the Hue Tap. I'm not sure if I can override the functions in the Hue Tap, but i'm pretty sure I can detect the changes it makes.

In a side note, I have been experimenting a bit with httplib instead of the phue libary. In I will change my plugin to accessing the Hue Bridge directly and not via the library. The phue library is for version 1.0 of the Hue API, the API is now at version 1.4. So I'm missing opportunities if I don't implement the API directly in my plugin.

krambriw
Plugin Developer
Posts: 2570
Joined: Sat Jun 30, 2007 2:51 pm
Location: Stockholm, Sweden
Contact:

Re: Philips Hue plugin

Post by krambriw » Tue Feb 03, 2015 4:26 pm

Related to getting events from the bridge without the need for polling, best is it is possible to subscribe and get events as notifications. I assume that this is how it is handled internally in the Hue Network, all devices are most likely subscribing to a service in the bridge and since they most likely have heard about IoT, it could be there is a message broker inside.

Do you know if the the Hue Bridge has support for websockets?
Or if there is a message broker inside like MQTT?
Is there anyone who has managed to install additional sw on the bridge?
Do you know if it runs under Linux?

Aquila
Experienced User
Posts: 87
Joined: Wed Jan 28, 2015 2:49 am

Re: Philips Hue plugin

Post by Aquila » Tue Feb 03, 2015 5:35 pm

krambriw wrote:Related to getting events from the bridge without the need for polling, best is it is possible to subscribe and get events as notifications. I assume that this is how it is handled internally in the Hue Network, all devices are most likely subscribing to a service in the bridge and since they most likely have heard about IoT, it could be there is a message broker inside.

Do you know if the the Hue Bridge has support for websockets?
Or if there is a message broker inside like MQTT?
Is there anyone who has managed to install additional sw on the bridge?
Do you know if it runs under Linux?
The Hue Bridge does not support push event, to get events I have to poll the Bridge. On the developer forum for Philips Hue this is a huge debate. Most developers want a push function, but Philips so far does not see the need for this.

I have not seen anyone who has manged to "hack" the bridge.

goodcoproflcop
Posts: 21
Joined: Tue Aug 13, 2013 2:18 pm

Re: Philips Hue plugin

Post by goodcoproflcop » Tue Feb 03, 2015 7:00 pm

Sounds promising, implementing the api instead of using an old library would be the best way to go of course. I have very little knowledge of the Hue ecosystem, but from the few articles I've read it looks like I need to start saving some money haha.

Aquila
Experienced User
Posts: 87
Joined: Wed Jan 28, 2015 2:49 am

Re: Philips Hue plugin

Post by Aquila » Thu Feb 05, 2015 5:35 pm

Hi all!

Just uploaded a new version. I have implemented the API directly in the plugin, seems to work good at my place. This makes me my own master, so I can now add anything form the API you need.

And maybe just as interesting the plugin now gives events. This is a poll action (every second at the moment, I will evaluate this) and not a push from the bridge. This is due to limitations in the Hue Bridge. At the moment the plugin generates the following events:
PhilipsHue.<Hue Tap>.buttonXX
PhilipsHue.<Sensor>.change
PhilipsHue.<Light>.reachable
PhilipsHue.<Light>.unreachable
PhilipsHue.light.added
PhilipsHue.light.removed

I can implement other actions and events on request.

User avatar
yokel22
Experienced User
Posts: 256
Joined: Thu Feb 05, 2015 5:56 pm
Location: U.S. - Kansas city

Re: Philips Hue plugin

Post by yokel22 » Thu Feb 05, 2015 7:12 pm

Thanks for doing this. I was just about to start writing REST commands. This saves me a good amount of time. A couple of questions. Is 2.0 broken for anyone else? I tried reinstalling various versions of EG to no avail. It seems like it's kicking back on the username. Reverting back to 1.0, on build 1669 has things working well again. Also, in 1.0 i'm not getting any return values when issueing get status macros. Is there something i'm missing? I'd like to see grouping added to the plugin too. Again, nice work.

Aquila
Experienced User
Posts: 87
Joined: Wed Jan 28, 2015 2:49 am

Re: Philips Hue plugin

Post by Aquila » Thu Feb 05, 2015 10:59 pm

yokel22 wrote:Thanks for doing this. I was just about to start writing REST commands. This saves me a good amount of time. A couple of questions. Is 2.0 broken for anyone else? I tried reinstalling various versions of EG to no avail. It seems like it's kicking back on the username. Reverting back to 1.0, on build 1669 has things working well again. Also, in 1.0 i'm not getting any return values when issueing get status macros. Is there something i'm missing? I'd like to see grouping added to the plugin too. Again, nice work.
You have to use the "Register with Bridge" function before you try to use any functions, this is required even if you registered with 0.1.0. You have to set username in the config before you run the "Register with bridge" function. The phue library I used earlier implemented username and user-type wrong. Please leave any logs of errors here if this does not work.

It may be that the "getstatus" function was broken in 0.1.0. In 0.2.0 it returns a dictionary of the light.

The next major upgrade I plan is for group commands. It seems quite straight forward to implement.

User avatar
yokel22
Experienced User
Posts: 256
Joined: Thu Feb 05, 2015 5:56 pm
Location: U.S. - Kansas city

Re: Philips Hue plugin

Post by yokel22 » Fri Feb 06, 2015 1:33 am

Sorry if i was unclear. In 1.0 the getstatus commands were firing fine but just didn't return a value. In 2.0 i tried once again installing as instructed. When i add the plugin i get this message(PhilipsHue is started, and connecting to: 192.168.1.79). Followed by a slew of errors pictured in the attached screenshot. When i try to register the bridge it gives this error(Plugin "Philips Hue" is not activated). Yes, i did remember to push the button.
Attachments
Screenshot 2015-02-05 19.32.36.png

Aquila
Experienced User
Posts: 87
Joined: Wed Jan 28, 2015 2:49 am

Re: Philips Hue plugin

Post by Aquila » Fri Feb 06, 2015 1:53 am

yokel22 wrote:Sorry if i was unclear. In 1.0 the getstatus commands were firing fine but just didn't return a value. In 2.0 i tried once again installing as instructed. When i add the plugin i get this message(PhilipsHue is started, and connecting to: 192.168.1.79). Followed by a slew of errors pictured in the attached screenshot. When i try to register the bridge it gives this error(Plugin "Philips Hue" is not activated). Yes, i did remember to push the button.
Ahh, I see what is happening. I implemented the events after I had run the "Register with the bridge" on my own computer, so I never discovered this bug. The eventthread is trying to connect to the bridge before it is registered, and this breaks the plugin. If you comment out everything after "self.username = username" in the __start__ function of the PhilipsHue, does the plugin work then? If this works you can register with the bridge, exit EG, uncomment the lines and restart. Then it should work. I don't have a 2nd computer available right now to check this. I will make a bugfix as quick as possible.

Aquila
Experienced User
Posts: 87
Joined: Wed Jan 28, 2015 2:49 am

Re: Philips Hue plugin

Post by Aquila » Fri Feb 06, 2015 2:43 am

I have published a new version 0.2.1 (see first post), this should fix the problem. After changing username and registering with the bridge, you should restart EG to get events. Does this work?

(As you see I have started implementing group commands, but its not finished in this version. And the layout of the "createGroup" config is terrible.)

User avatar
yokel22
Experienced User
Posts: 256
Joined: Thu Feb 05, 2015 5:56 pm
Location: U.S. - Kansas city

Re: Philips Hue plugin

Post by yokel22 » Fri Feb 06, 2015 3:51 am

Yep, working well now. I'm still not getting any returns on the getstatus commands. Everything else is working well. I like the subdivisions you threw in too. Is it possible to send toggle commands to the api?

Post Reply