[SOLVED] Why is the item updated only after two events

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

You seem to be saying triggering from Item XX is not synchronized with Item YY changes?
If you can’t trigger from Lichtschalter_Buero directly (maybe it doesn’t always change) then perhaps you just need to allow a little time delay between trigger and processing in the rule…

2 Likes

My bad :-(…Sometime you don’t see the most obvious errors. Off course I needed to check against the change of Lichtschalter_Buero and not Lichtschalter_Buero_Zuletzt

I better get some sleep :wink:

thx

Stefan

1 Like

click rossko’s reply as the solution
my reply had some mistakes in it (and I removed it) :slight_smile: