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