Hi,
While creating the roller shutter element I wanted to show its position, such information is in the returned JSON. Unfortunately, I can’t read it even though the code seems to be correct. Any suggestions? At the begining I wanted to show the value inside rollershutter item, finally I created a new one.
That is complete code, one thing is enough for manipulate and read position: Rollershutter S_Room "Pokój []" <rollershutter> (Shutters) { http=">[DOWN:GET:http://192.168.0.120/s/d] >[STOP:GET:http://192.168.0.120/s/s] >[UP:GET:http://192.168.0.120/s/u] <[http://192.168.0.120/api/shutter/state:3000:JSONPATH($.shutter.desiredPos.position)]" }
Do you use blebox.eu dimmer module? Dimmer has different api and do not need DOWN/UP/STOP commands( https://technical.blebox.eu/dimmerBoxAPI/). So, you should read currentBrightness and set desiredBrightness on change. The code for dimmer should look like this:
transform/brightness.js (to calculate percent for dimmer item because source brightness value is between 0-255): (function(value) { var brightness_val = JSON.parse(value).dimmer.desiredBrightness; var brightness_percent = Math.round((brightness_val / 255) * 100); return brightness_percent; })(input)
What kind of equipment do you actually use and where is the api documentation?
If you can not bind http directly for an item, do it with rule, like that: rule "My shutter" when Item Dim received command then val String URL = "http://IP/api/shutter/set - check your api" val String contenttype = "application/json" var String jsondata = '{"shutter": {"position": ' + Dim.state + '}} - check your json structure' sendHttpPostRequest(URL, contenttype, jsondata) logInfo("rshutter.rules", "Dimm position set to " + Dim.state) end
At least, consider use rollershutter item in place of dimmer.
This is simple bind for dimmer item controling shutter: Dimmer YOUR_ITEM "LABEL [%d %%]" <rollershutter> { http=">[*:GET:http://YOUR_IP/API/%2$s] <[http://YOUR_IP/API/state:3000:JSONPATH(target position)]" }
This one >[*:GET:http://YOUR_IP/API/%2$s] send new position to shutter controller, %2$s means dimmer position
Next one: <[http://YOUR_IP/API/state:3000:JSONPATH($.shutter.desiredPos.position)] is an example of read target position. You should read the target position, if you have one, not the current one (current = loops). $.shutter.desiredPos.position depends on the structure of your json respond.
If won’t work restart openhab service: sudo systemctl restart openhab2.service.
But i don’t understand why on the habpanel the status of the switch works instead on the sitemap no.
Infact on the sitemap when a switch go off i am not able to see this switch.
Why?