@mortommy Thanks, I think I will give that a shot. I also found this when I was looking into it but I think I prefer your way. https://github.com/openhab/openhab/wiki/Hue-Binding#indirectly-using-a-livingcolors-remote-or-hue-dimmer-switch
I’ll post my config once I do it so others may be able to learn from it.
here it is mine:
String HueTapEventType "Hue Tap Event Type" { http="<[http://_bridgeip_/api/openHABRuntime/sensors/4:120000:JS(getHueTapEventType.js)]" }
String HueTapEventWhen "Hue Tap Event When" { http="<[http://_bridgeip_/api/openHABRuntime/sensors/4:120000:JS(getHueTapEventDate.js)]" }
and the transformations
getHueTapEventDate.js
(function(i) {
var json = JSON.parse(i);
return json['state']['lastupdated'];
})(input)
getHueTapEventType.js
(function(i) {
var json = JSON.parse(i);
return json['state']['buttonevent'];
})(input)
I have maybe a long pooling interval set, but it is ok with my use of the event.
Quick question about this @mortommy, this is bringing back the time in UTC. Do you know of a way to convert it to local time in the .js file?
Thanks for any help you may offer.
Yes, it’s true it is utc time, but actually since I’m only interest in the value changing I didn’t think about it. Maybe there’s something in the hue API.
Good call, I’ll try to look at the time of change instead of the time returned. I didn’t see anything in the API but I think your way will work well. Thanks!
@mortommy I tried to implement your solution in my system, unfortunately I can’t get it running.
I’m using openHab 1.8.
I’m relatively new to openHAB and I think the problem is the rule I’ve created.
I have the following two items in the items file:
String HueTasteSchlafzimmerZeit "Hue Taste Schlafzimmer Zeit [%s]" { http="<[http://-huebridgeip-/api/-SecretID-/sensors/10:2000:JS(HueSwitchDatumTransformation.js)]" }
String HueTasteSchlafzimmerTyp "Hue Taste Schlafzimmer Typ [%s]" { http="<[http://-huebridgeip-/api/-SecretID-/sensors/10:2000:JS(HueSwitchTasteTransformation.js)]" }
sensor 10 is one of my hue dimmer switches.
The transformations are in the folder transform and look like this:
HueSwitchDatumTransformation.js
(function(i) {
var json = JSON.parse(i);
return json['state']['lastupdated'];
})(input)
HueSwitchTasteTransformation.js
(function(i) {
var json = JSON.parse(i);
return json['state']['buttonevent'];
})(input)
Now the rule. I want a simple rule that turns off a specific light when the off button on the dimmer switch is pressed long and then released. (buttonevent = “4003”).
My rule looks like this:
rule "AlleLichterAus"
when
item HueTasteSchlafzimmerZeit changed
then
if (HueTasteSchlafzimmerTyp == "4003")
{sendCommand(huewz1, OFF)}
End
Can you help me with this issue?
Thanks in advance for any help.
Hi @burningstone,
could you try to change the rule in:
rule "AlleLichterAus"
when
Item HueTasteSchlafzimmerZeit changed
then
if (HueTasteSchlafzimmerTyp.state == "4003")
{sendCommand(huewz1, OFF)}
End
anyway, do you see the items update entries in the events.log?
Hi
Thanks for your quick reply. I just got it solved by myself yesterday
evening
The problem was that the “i” in item was not a capital letter and the
".state" in the condition was missing.
Thank you anyway.
Best regards
I’m trying to use this on my system but not having much luck. Here’s what I have inplace.
String HueTapEventType "Hue Tap Event Type" { http="<[http://192.168.10.69/api/HueSecretGUID/sensors/2:2000:JS(getHueTapEventType.js)]" }
String HueTapEventWhen "Hue Tap Event When" { http="<[http://192.168.10.69/api/HueSecretGUID/sensors/2:2000:JS(getHueTapEventDate.js)]" }
Here’s the contains of /opt/openhab/configurations/transform
-rwxr-xr-x. 1 root root 96 Jan 19 21:32 getHueTapEventDate.js
-rwxr-xr-x. 1 root root 96 Jan 19 21:33 getHueTapEventType.js
rule "Getting Of To Sleep"
when
Item HueTapEventWhen changed
then
if (HueTapEventType.state == "4003" && Current_Time_Of_Day.state == "Night" && Living_Room_Table_Light.state != 'ON'){
postUpdate(Master_Bedroom_In_Bed, "Yes")
First_Floor_Landing_Ceiling_Light.sendCommand(0)
}
end
There is nothing in the events.log file, so clearly something isn’t right. Any pointers?
Could you post one of the js file?
getHueTapEventDate.js
(function(i) {
var json = JSON.parse(i);
return json['state']['lastupdated'];
})(input)
getHueTapEventType.js
(function(i) {
var json = JSON.parse(i);
return json['state']['buttonevent'];
})(input)
Cannot see anything wrong. Are you sure about the sensor id?
Here’s what I get from a browser;
{"state":{"buttonevent":null,"lastupdated":"none"},"config":{"on":true,"battery":100,"reachable":true,"pending":[]},"name":"Master Bedroom Dimmer Switch","type":"ZLLSwitch","modelid":"RWL021","manufacturername":"Philips","swversion":"5.45.1.16265","uniqueid":"00:17:88:01:10:48:95:75-02-fc00"}
Ok, sorted my problem. Simple in the end, I hadn’t put the http binding into the addons folder. Oops.
Anyway, it’s all work fine now.
Hi
I have a hue dimmer kit and I would love to include it in my openhab setup.
I’m very new to the openhab system and when I look thought the thread I have no clue how I can add this to my system.
Could you please give me a hand, please?
I have the hue binding already and light working with this.
I have noticed that it sometimes thinks I’m pressing a different button any ideas on this?
It’s like the button press hasent changed yet and still thinks it’s a different button press I did add a thread:sleep at the top of my rule too give it chance too change this helped but did not solve this
According to the documentation the dimmer switch has 16 states. The faster you poll, the more different states you will see.
BUTTON | STATE | CODE |
---|---|---|
Button 1 (ON) | INITIAL_PRESSED | 1000 |
HOLD | 1001 | |
SHORT RELEASED | 1002 | |
LONG RELEASED | 1003 | |
Button 2 (DIM UP) | INITIAL_PRESSED | 2000 |
HOLD | 2001 | |
SHORT RELEASED | 2002 | |
LONG RELEASED | 2003 | |
Button 3 (DIM DOWN) | INITIAL_PRESSED | 3000 |
HOLD | 3001 | |
SHORT RELEASED | 3002 | |
LONG RELEASED | 3003 | |
Button 4 (OFF) | INITIAL_PRESSED | 4000 |
HOLD | 4001 | |
SHORT RELEASED | 4002 | |
LONG RELEASED | 4003 |
Thanks for another reply
I have also been trying too work that out i din’t realise it had that many states i have only been using
Codes 1000,2000,3000,4000 but sometimes when you press the button eg 3000 it gets confused and things button 1000 has been pressed
its any button not certain buttons its like the action happens before the button code changes thats why i added a small thread:sleep but the problems there sometimes still
After struggling with this a few hours, I’ve put a sample rules file and long-winded explanation for how to control non-Hue devices with the Hue dimmer here: