How can I pass parameters into openhab2 transformations?

1k Views Asked by At

I have a openhab 2.1 setup, and I am using the http binding to get the additional data from my hue bridge that is not available in the hue binding (yet). I am mostly interested in the light- and temperature sensors built into the motion sensors, but I also want to be able to react to button presses (and, since this is interactive, with as little delay as possible).

So i chose to go with polling the bridge using the http binding.

I have:

hue.url=http://192.168.61.21/api/[KEY]/sensors/
hue.updateInterval=500

and I am using JS or JSONPATH transformations to extract values.

the problem I am having is this:

I can easily do:

Number hue_dimmer_buttons_study_1 "Study Dimmer (last button)" { http="<[hue:500:JSONPATH($.16.state.buttonevent)]" }
Number hue_dimmer_scene_study_1 "Study Dimmer (current scene)" { http="<[hue:500:JSONPATH($.17.state.status)]" }

and get the values from entire list. But I can only do EITHER a transformation like this and get the raw value from the JSON, OR I can do additional transformations (such as mapping "true" to "ON" and 1995 to 19.95) - I cannot do both.

Also, if I retrieve all sensor states anyways, I might as well retrieve all values from the same string - for this, my only option is to write one (for example) getHueTemperature.js for EACH SENSOR, i.e.:

getHueTemperature14.js:

(function(i) {
    return JSON.parse(input).14.state.temperature / 100;
})(input)

and then do:

[...] { http="<[hue:500:JS(getHueTemperature14.js)]" }

I cannot pass in which element I want to extract from and then use one transformation for all sensors, such as:

getHueTemperature.js:

(function(i) {
    return JSON.parse(input)[element].state.temperature / 100;
})(input, element)

and then:

[...] { http="<[hue:500:JS(getHueTemperature.js,14)]" }

... or can i? any help would be very much appreciated.

thanks

.rm

0

There are 0 best solutions below