[Solved] Try to Transform shelly 2.5 pos Topic

  • Platform information:
    • Hardware: Raspberry pi 3B+
    • OS: linux Openhab image
    • Java : openjdk version “1.8.0_152”
    • openHAB version: openHAB 2.5.0~M4-1 (Milestone Build)

Hello,
I despair of trying to transform the shells 2.5 pos Topic to reverse the Shutter Icon.
On the Shelly device is
100 the blinds is close
0 the blinds is open
but at the sidemap the icon is open at 0 und closed at 100.

grafik

I search a while in the community and found a JS transform script.

InvertPercent.js

(function(i) {
// shelly 0% = Closed
// oh2 0% = open
//The following script converts [0% - 100%] to [100% - 0%].
var percent_shelly = parseInt(i, 10);
var percent_oh = (100.0 - percent_shelly);
//Return result with one decimal accuracy
return percent_oh.toFixed(1);
})(input)

I put the .js into the tranform Folder and add to the
.things

Thing topic Rollo_wozi_klein {
Channels:
Type string : online “Online” [ stateTopic=“shellies/shellyswitch25-73BF2B/online” ]
Type number : position “Position” [ stateTopic=“shellies/shellyswitch25-73BF2B/roller/0/pos”, commandTopic=“shellies/shellyswitch25-73BF2B/roller/0/command/pos”, transformationPattern=“JS:InvertPercent.js”]

but it does not work

Can anybody explain the mistake

Best regards
André

I used this js transformation file when I was using mqtt, and it worked :

(function(i) {
return (100-i);
}) (input)

I cannot tell if your files are correct because I just use PaperUI.

Anyway if you are interested there is a binding for Shelly, and it does the reverse transformation by itself.

https://github.com/markus7017/org.openhab.binding.shelly/releases/tag/2.4.2_stable

Thanks it works now…

I will give the binding a try at the next time.