Good evening all,
I have a Hue Dimmer Switch which I want to use in OH2. Below is my setup which I implemented following these instructions from @cweitkamp and which works ok but with a behaviour that I can’t explain and fix myself
http.cfg:
BueroDimmer.url=http://myserverip/api/somesecretkey/sensors/17
BueroDimmer.updateInterval=1000
default.items
Number Lichtschalter_Buero { http=“<[BueroDimmer:1000:JS(getHueButton.js)]” }
DateTime Lichtschalter_Buero_Zuletzt { http=“<[BueroDimmer:1000:JS(getHueLastChange.js)]” }
getHueButton.js (in /transform folder)
(function(i) {
var json = JSON.parse(i);
return parseInt(json[“state”][“buttonevent”]);
})(input)
and the rule:
rule "Test"
when
Item Lichtschalter_Buero_Zuletzt changed
then
switch Lichtschalter_Buero.state.toString {
case "1002.0": {
logInfo("ffd","")
logInfo("1002 pressed","") }
case "2002.0":
logInfo("2002 pressed","")
case "3002.0":
logInfo("3002 pressed","")
case "4002.0":
logInfo("4002 pressed","")
}
end
Everything works fine so far, I do seem to get the actual response code for the button back in Lichtschalter_Buero, according to the the system log. However, the switch statement seems to operate on the previous button code, not the one that was just generated by the user. See the log file entry: the first line is generated by the loginfo() call, the second one is what the system generated automatically. Butto 2002 was pressed, say 5 minutes agon, then the user presses button 3002 and get this:
2018-12-04 22:44:12.918 [INFO ] [.smarthome.model.script.2002 pressed]
2018-12-04 22:44:13.135 [vent.ItemStateChangedEvent] - Lichtschalter_Buero changed from 2002.0 to 3002.0
When I then press button 3002 a second time the switch statement works correctly
Does anyone have some clever advice on how to get it right the first time?
Thank you!
Stefan