Trigger a rule when a thing goes Offline because of COMMUNICATION_ERROR

Hello,

As I’m using the Velux KLF 200 bridge to control my blinds, I’m faced with the regular “zombie bridge” issue where the only solution is to disable the bridge in openHab, unplug, wait, replug the KLF200 and enable the bridge.
As I have a remote controlled socket on the KLF 200 power line, I can do that just fine manually via Main UI but this is somewhat tedious and I may not notice immediately when the KLF goes zombie.
As such, I would like to write a rule that triggers when the thing goes Offline because of a COMMUNICATION_ERROR state.

I have the following trigger:

triggers:
  - id: "1"
    configuration:
      thingUID: velux:klf200:4b425d26ec
      status: OFFLINE
    type: core.ThingStatusChangeTrigger

but I’m having a hard time figuring out how to specify the COMMUNICATION_ERROR part.

Would you have any suggestions for openHab 3.4.3?

Why not trigger on the COMMUNICATION_ERROR state instead of OFFLINE?

If you can’t do that, you’ll have to trigger some rule (maybe the same one) on COMMUNICATION_ERROR and set a timestamp. Then trigger some rule on OFFLINE and send your commands to the switch only if the OFFLINE was close in time to the COMMUNICATION_ERROR.

Because I have no idea how to do that. I mean, here are the choices I have in MainUI:

image

But if there’s a way to trigger on COMMUNICATION_ERROR directly, I’d gladly use that.

I thought the UI would let you type in the status, not just select one from the list (similar to Item triggers).

The COMMUNICATION_ERROR is a part of the status details. You could try changing it in the Code tab to OFFLINE (COMMUNICATION_ERROR) but there is no guarantee that will work.

If it doesn’t, trigger the rule just using OFFLINE. Then you can get the Thing and pull the details from the status.

GraalVM JS Scripting

var thing = things.getThing('velux:klf200:4b425d26ec');
if(thing.statusInfo == 'COMMUNICATION_ERROR') {
  // toggle the switch
}
else {
  console.info('Thing went offline for some other reason');
}

Unfortunately Blockly doesn’t expose the statusInfo in a block.

Thanks, I already have a JS script to do the on/off part, so adding the test in statusInfo is good for me.

I also faced the communication_error issue nearly ever 24 hours.

I was only using a random power supply from an old mobile phone.
After changing the power supply to the original, I have not seen the issue anymore.

Maybe that’s helpful for you

Yes, I believe it has to do with the power supply, but I am using the original one and it happens every once in a while.

Just for reference to others, the test has to be written like this in JS:

const bridge = things.getThing("velux:klf200:4b425d26ec");
if (bridge.statusInfo == "OFFLINE (COMMUNICATION_ERROR)")

The status info takes both parts, it’s not just empty COMMUNICATION ERROR as I originally expected.

I have just ordered additional smart plugs, one to be used for the KLF200 as it goes into zombie mode about once every month.

Do you remove power for a certain amount of time? (Like 10, 30 or 60 seconds).
Do you have to disable the binding during reset and enable after it?
Long story short, would you mind sharing your rule with actions?

Here is the entire definition, you’ll have to adjust for your items:

configuration: {}
triggers:
  - id: "1"
    configuration:
      thingUID: velux:klf200:abdcef
    type: core.ThingStatusChangeTrigger
conditions: []
actions:
  - inputs: {}
    id: "3"
    configuration:
      type: application/javascript;version=ECMAScript-2021
      script: >-
        (
          function()
          {
            const bridge = things.getThing("velux:klf200:abcedf");
            const aubess = items["aubess_power_outlett_state"];

            console.log("Veluf KLF status changed: " + bridge.status + " / " + bridge.statusInfo);
            if (bridge.statusInfo == "OFFLINE (COMMUNICATION_ERROR)")
            {
              console.warn("Veluf KLF is zombie, restarting it via the zigbee power socket");
              console.log("Veluf KLF zombie -> disable bridge");
              bridge.setEnabled(false);
              java.lang.Thread.sleep(2000);
              console.log("Veluf KLF zombie -> power off");
              aubess.sendCommand("OFF");
              java.lang.Thread.sleep(10000);
              console.log("Veluf KLF zombie -> power on");
              aubess.sendCommand("ON");
              java.lang.Thread.sleep(5000);
              console.log("Veluf KLF zombie -> enable bridge");
              bridge.setEnabled(true);
            }
          }
        )

        ();
    type: script.ScriptAction
1 Like

Thank you so much!

With Autumn kicking in and the binding being far less active (less sunshade and window opening action), finetuning (and troubleshooting) my own rule would take beyond Christmas I’m afraid…