Hint on http binding with transformations

Hi, I need some help getting started with the http binding and transformations. I’m using the Slide curtain system, it has a local API to (amongst others) get / set the position of the Slide. The pos is reported as a 2 digit decimal ranging from 0.00 (open) to 1.00 (closed), I want to map this to a Dimmer Item (* 100). I’ve got some of it working but could use a hint on transforming the values.

this is my thing definition, I need some help for the parts between << and >>:

Thing http:url:slideCurtainLeft "Curtain Left" [ baseURL="http://<localip>/rpc/" , authMode = "DIGEST", username="user", password="<pwd>", stateMethod="POST", commandMethod="POST" ]{ 
   Channels:
      Type number : position "Position" [ 
               stateExtension="Slide.GetInfo", 
               stateTransformation="JSONPATH:$.pos << * 100 >>",
               commandExtension="Slide.SetPos", 
               commandTransformation="REGEX:(s/.*/{\"pos\": << $1 / 100 >>})/g"
      ]     
}
  • I want the stateTransformation to get the json path value and multiply by 100;
  • I want the commandTransformation to divide the channel’s Dimmer value by 100 and put it in a fixed json structure.

A hint is appreciated.

Have a look at JS transformation, with this you should be able to do the math.

Of course you can chain and combine the different transformations, e.g. first use json to extract the number and then run *100 with the he help of JS

Hello itb,

I just activated the slide local API and played around a little.
I simply mapped the Position channel to a dimmer item without multiplying or dividing. Since the dimmer item works with percentages, no conversion seems to be needed and it just worked out of the box.

I’d be interested to hear your own experience with the local API.

Cheers! Stefan