OpenHAB controls Hue lights

OpenHAB and Philips Hue

Just a few years ago it was unthinkable to use intelligent light bulbs. What would be the point? For decades, the light goes on when you press the light switch and goes off again the same way. Only with LED technology could light bulbs suddenly do more: change colour temperature or shine in different colours. In my opinion, the best system in this area is the one from Philips with Hue. The products are very well thought-out, energy-saving. But unfortunately also relatively expensive.

Hue has a hub that is integrated into the local network. The lamps and light sources themselves communicate with the hub via the industry standard Zigbee - and this is where it really gets interesting: luminaires from other manufacturers that support the same standard can be integrated into the Hue system. For example, I have garden lights from Osram; but IKEA also has lights compatible with the TRÅDFRI range (and of course there are many other manufacturers).

Normally the lamps are controlled by an app or an additional switch. As I already wrote in the introduction, I don't find either of these desirable: I want the house to work really intelligently. All manual actions should be controllable by everyone via a normal switch (which ideally is not different from other switches).

The Wiring

In order for the home automation system to switch on a lamp, it needs power - and it always needs power. Conventional wiring must therefore be partially modified; if the normal light switch prevents the lamp from being energized, nothing and no one can switch on the lamp - except the switch. It must therefore be ensured that voltage is always present for all lights that are to be switched on and off (also) automatically.

How this works best is a question of the individual case. I have a floor lamp that gets its power from a wall socket. Here it is sufficient not to switch off the lamp on the device itself. Ceiling lamps, on the other hand, are typically controlled by a switch that cuts off the power supply. Here I have had good experience with HomeMatic switches: these are available as actuators that actually switch power (but can also be controlled by the home automation system) or as pure sensors; in this case, the ceiling lamp is simply always supplied with power. I have both versions in use: for Hue control, the lamps are always powered and are switched by the HomeMatic switch via the home automation detour.

Magic that nobody sees

With HomeMatic push-buttons, you can use the original covers of the existing switches; for many manufacturers there are corresponding adapters available. So the push button looks exactly like the light switch it replaces. And with the appropriate configuration, it works the same way - at least for visitors. If you press it, the light goes on. And off again. :)

Something more happens in the background: pressing the button reports this to the HomeMatic. This in turn reports the desired command to the Hue-Hub, which passes this on to the lights via the Zigbee standard. All this happens in a few milliseconds.

And: the home automation system is now able to switch the light on and off independently. For example, an intelligent holiday control system is conceivable in which the house simulates presence. Or a time or context-dependent control of the lamp: it's 3 a.m. and someone presses the switch? Presumably someone is half asleep when they go into the bathroom; so it makes sense not to dazzle the occupant and only switch on the lamp at 30%. Or the home automation system detects that the TV has been switched on and switches on the appropriate light scene.

The possibilities are endless - and I will be implementing one or the other idea on this blog.

 

Making the Hue headquarters known to OpenHAB

First, we need to teach OpenHAB to communicate with the Hue Hub. To do this we first install the appropriate binding in the PaperUI ("Add-ons" -> "Bindings" -> "Hue Binding" -> install).

To authorize the brigde, the Hue Gateway button must be pressed, and the OpenHAB logs (/var/log/openhab.log) will show the prompt

 

Creating new user on Hue bridge 192.168.91.100 - please press the pairing button on the bridge.

 

and as soon as you follow this, a cryptic username. With this we can make the Bridge permanently known. We enter this in /etc/openhab2/things/hue.things:

 

Bridge hue:bridge:1 [ ipAddress="192.168.91.100", userName="oU*****************************" ] ]

 

The luminaires configured in the Hue system are then visible in the inbox including the internal address.

Let there be light

The lamps can be defined in /etc/openhab2/items. For this I created a file hue.items and defined the corresponding lamps and their properties:

 

Switch WZ_Stehlampe_Switch "Stehlampe" (Light, Hue) { channel="hue:0100:0017********:6:brightness" }
Dimmer WZ_Stehlampe_Dimmer "Floor lamp dimming" (light, hue) { channel="hue:0100:0017********:6:brightness" }

 

The first simple application is to make a light switchable using the HomeMatic push-button configured in the last section. In /etc/openhab2/rules we create a new file wohnzimmer_hm_schalter.rules

 

rule "HM_Stehlampe_TOGGLE"
when
  Channel "homematic:HG-HM-RC-2-PBU-FM:0eb8f8ab:NEQ******:1#BUTTON" triggered SHORT_PRESSED
then
  val state = if(WZ_Stehlampe_Schalter.state == OFF || WZ_Stehlampe_Schalter.state == 0) ON else OFF
  WZ_Stehlampe_Schalter.sendCommand(state)
end

 

Dimmable Hue lamps are off when the State is set to 0 or OFF, so we have to cover both cases.

If you want to dim the lamps via the switch, you can do this as follows:

 

rule "HM_ceiling_lamp_DIMMDOWN"
when
  Channel "homematic:HG-HM-RC-2-PBU-FM:0eb8f8ab:NEQ******:1#BUTTON" triggered LONG_PRESSED
then
  var bright=WZ_ceiling_light_dimmer.state as Number
  bright = bright - 25;
  EZ_ceiling_lamp_Dimmer.sendCommand(bright.intValue);
  WZ_ceiling_lamp_dimmer.sendCommand(bright.intValue);
end

rule "HM_ceiling_light_DIMMUP"
when
  Channel "homematic:HG-HM-RC-2-PBU-FM:0eb8f8ab:NEQ******:2#BUTTON" triggered LONG_PRESSED
then
  var bright=EZ_ceiling_light_dimmer.state as Number
  bright = bright + 25;
  EZ_ceiling_lamp_Dimmer.sendCommand(bright.intValue);
  WZ_ceiling_lamp_dimmer.sendCommand(bright.intValue);
end

 

increases/reduces the light intensity (in this case of two lamps) by pressing the switch for a long time.

Comments (0)

No comments found!

Write new comment reply