myStrom Switch Control and State Update


I am a beginner and am trying to integrate the myStrom Switch into my openhab environment and since I dont want to use a mystrom account I dont use the existing myStrom binding. I want to control the switch “offline” via openhab and additionally want to detect if the user changed the state by manual pressing the button on the device:

To Control the switch there are two easy http-get commands like http://IP/relay?state=1 (or 0). To get the state, the device creates a json file at http://IP/report like:
“power”: 28.355360,
“relay”: true

Switch control is working:

Switch myStrom "myStrom Steckdose" <poweron> (Switches) { http=">[ON:GET:] >[OFF:GET:]" }

Switch state is displayed in a separate “String” item on openhab (which is updated every second)

String myStrom_State "State:[%s]" (Switches) { http="<[$.relay)]" }

But how do I integrate the state into my openhab-switch item? I tried adding


to my switch item but it does not seem to work. I guess I somehow have to transform “true” to ON and “false” to OFF.

I used mqtt bindings before where you can tranform the content of the mqtt package by adding ON:1 or OFF:1 at the end. But this doesnt seem to work either.


Do you have any idea what I have to change to get it working?

thx in advance

You are already using a transformation with JSONPATH, I am afraid but you can’t nest them.
So you have two options

  • Use a String Item and a rule to “transform” the string to your switch Item
  • Use a JS transform



String myStromString { http="<[$.relay)]"  }
Switch myStrom


rule "String to switch"
    Item myStromString changed
    if (myStromString.state.toString == "true") {
    else { // assuming that there are only two states true/false

Option 2 Javascript transform

Create a file called mystrom.js in your transform folder
With the following content:

(function(i) {
    var data = JSON.parse(i);
    var relaystate = data.relay;
    if (relaystate == 'true') {
        result = 'ON'
    } else {
        result = 'OFF'
    return result;

Your item:

Swith myStrom { http="<[]"  }

Good luck


thank you very much. I really could have come up with the rule-based solution by myself, but I was so focused on bindings that I forgot about the rules. :man_facepalming:

So I implemented your rule and it works perfectly. :slight_smile:

thx again.