Rademacher Homepilot (DuoFern) via http-Binding

I have more good news - must be switchcraft :wink: - Meanwhile, after some cool testing session in this thread, it is possible to fully integrate a switch (relay, integrated relay in motion sensor, etc.).

This means that it is not only possible to send commands, but also the OH-internal status is updated according to the relay’s actual status. You do not need a separate channel for the status anymore! :smiley:

Here is the Thing definition:

        Type switch : Schalter_NL_Flur_2 "Schalter Nachtlicht Flur 2" [  // Relay switch  DID=<myDID>
            stateExtension="/v4/devices",
            stateTransformation="JSONPATH:$.devices[?(@.did==<myDID>)].statusesMap.Position",
            commandTransformation="JS:toSwitchCmd.js",
            commandExtension="/devices/<myDID>",
            onValue="100",
            offValue="0"
        ]

and here is the associated toSwitchCmd.js:

(function(x){
  try {
        if (x == "0") {
            return ("{\"name\":\"TURN_OFF_CMD\"}");
        }
        return ("{\"name\":\"TURN_ON_CMD\"}");
  } catch(e) {
    console.error('toSwitchCmd.js encountered an error: ' + e);
    return null;
  }
})(input)

And, believe it or not, I just thought I have some minutes to play around with the same idea with the rollershutters. And it almost immediately worked (with a little trick in the script). :smiley:

Here’s the Thing:

        Type rollershutter : Rolladen_Arbeitszimmer "Rolladen Arbeitszimmer" [   //DID=<myDID>
            stateExtension="/v4/devices",
            stateTransformation="JSONPATH:$.devices[?(@.did==<myDID>)].statusesMap.Position",
            commandTransformation="JS:RollerShutterControlAndPos.js",
            commandExtension="/devices/<myDID>",
            stopValue="STOP",
            downValue="DOWN",
            upValue="UP"
        ]

and here’s the RollerShutterControlAndPos.js script:

    try{
        if(x == "STOP") {
            return ("{\"name\":\"STOP_CMD\"}");
        }
        if(x == "DOWN") {
            return ("{\"name\":\"POS_DOWN_CMD\"}");
        }
        if(x == "UP") {
            return ("{\"name\":\"POS_UP_CMD\"}");
        }
        // if it's no keyword, assume it is the position number
        var obj = {name: "GOTO_POS_CMD", value: parseInt(x)};
        return (JSON.stringify(obj));
    } catch(e) {
        console.error('RollerShutterControlAndPos.js encountered an error: ' + e);
        return null;
    }
})(input)

OH just pushes through what you command it - in case of the control buttons it’s the content of the up/down/stop value definition, and if it’s a percentage position, it’s just a number.
So the trick was to make the script distinguish between button commands via keywords, and to assume that if it’s not a keyword it must be a percentage number.

With this setup, the GUI buttons work, as well as a pure number command from a rule, and the current position is displayed in the rollershutter object itself. :wink: