[SOLVED] Handle Philips Hue dimmer switch events?

Tags: #<Tag:0x00007f6188d01588> #<Tag:0x00007f6188d01420> #<Tag:0x00007f6188d012b8>

I would like to write a rule that reacts to events of a Philips Hue dimmer switch as outlined in the binding documentation:

rule "example trigger rule"
when
   Channel "hue:0820:dimmer-switch:dimmer_switch_event" triggered <EVENT>
then
   ...
end

But I cannot find any working example out there so I guess I would have to write one rule per possible event (= 16 in total) or one rule with all of the triggers like this

rule "rule with all events"
when
   Channel "hue:0820:dimmer-switch:dimmer_switch_event" triggered 1000 or
   Channel "hue:0820:dimmer-switch:dimmer_switch_event" triggered 1001 or
   Channel "hue:0820:dimmer-switch:dimmer_switch_event" triggered 1002 or
   Channel "hue:0820:dimmer-switch:dimmer_switch_event" triggered 1003 ...

to catch all events. According to the Channel-based Triggers documentation you can leave out the <EVENT> in my first example. But how can I find out what event triggered the rule so it can react to it (e.g. within a switch statement)? There seems to be no implicit variable to do something like this:

rule "my event handling"
when
   Channel "hue:0820:dimmer-switch:dimmer_switch_event" triggered
then
   logInfo("DimmerTest", "Dimmer switch event " + triggeredEvent + " was triggered")
   Switch(triggeredEvent.state) {
    case 1001:
    ...
    }
end

How can I achieve this? Or is there another best practice?

1 Like

Link an item to the Channel
My guess is that it’s a Number channel but I could be wrong:

Item file:

Number Hue_Dimmer_Event { channel="hue:0820:dimmer-switch:dimmer_switch_event" }

Use the item as a trigger for the rule:

rule "rule with all events"
when
    Item Hue_Dimmer_Event changed
then
    ...
end

That sounds good. I will try that! Thank you!

Can you check if receivedEvent is working for you? Like this:

rule "my event handling"
when
   Channel "hue:0820:dimmer-switch:dimmer_switch_event" triggered
then
    logInfo("DimmerTest", "Dimmer switch event {} was triggered", receivedEvent)
    switch(receivedEvent.getEvent()) {
        case "1001": {
            ...
        }
    }
end
2 Likes

Just used this! Works for me! :slight_smile:

Although for some reason, my events all appear with a .0 at the end so I have to call them like that in my rules.

rule "Kitchen Dimmer"
when
   Channel "hue:0820:Southgate1:32:dimmer_switch_event" triggered
then
    logInfo("KitchenDimmer", "{}", receivedEvent)
    switch(receivedEvent.getEvent()) {
        case "1000.0": {
            AllKitchenLights_dummy.sendCommand("ON")
        }
       ...
    }
end

Great. Thanks for raising this topic. I used the opportunity to add it to the docs.

Thank you for the suggestion! Unfortunately, this did not work, neither with Number nor with String as type.

Yes, it works! Perfect!

I got my channel definition slightly different to work (I guess this is equivalent):

rule "MyHueDimmer event handling"
when
    Channel "hue:0820:<BRIDGEID>:MyHueDimmer:dimmer_switch_event" triggered
then
    logInfo("DimmerTest", "receivedEvent=" + receivedEvent)
    switch(receivedEvent.getEvent()) {
        case "1000.0": {
            ...
        }
       ...
    }
end

You are welcome! Many thanks for your excellent idea, Christoph!

Sounds good. I am happy that it is working for you.

After upgrading openhab to 2.5.0.M1 this does not always work

1 Like

Same for me after milestone.

Looks like we’re stuck with the problem too.

Same problem here. Any ideas?

Welcome to the openHAB community, @yulian! :grinning:

Unfortunately not. I am currently on milestone 2.5.0~M3-1 and it still does not work anymore. Every now and then an exception is thrown saying ‘getEvent’ is not a member of ... but the receivedEvent.getEvent() generally fails to do what it successfully did before.

Ok,
in last consequence i downgraded from 2.5.0~M3 back to 2.4.0.
Now the Dimmer Switch works as expected (like before) but the openhab2 system reacts slower.
But for me it’s better have a slightly slower system than have switches that didn’t work reliable.
The sadness is that i saw these problem on posts from late 2017 and nothing is going forward.
So i’ll stick on 2.4.0.

Anyway, many thanks for your answer!