# Trigger a rule when a thing goes Offline because of COMMUNICATION\_ERROR

**URL:** <https://community.openhab.org/t/trigger-a-rule-when-a-thing-goes-offline-because-of-communication-error/146494>\
**Category:** Scripts & Rules\
**Created:** [May 5, 2023, 8:34am UTC](https://community.openhab.org/t/trigger-a-rule-when-a-thing-goes-offline-because-of-communication-error/146494 "2023-05-05T08:34:55Z")\
**Posts on this page:** 12\
**Page:** 1

<div class="post-metadata">

**Author:** ![obones](https://community.openhab.org/user_avatar/community.openhab.org/obones/32/68523_2.png) [@obones](https://community.openhab.org/u/obones)\
**Post date:** [May 5, 2023, 8:34am UTC](https://community.openhab.org/t/trigger-a-rule-when-a-thing-goes-offline-because-of-communication-error/146494/1 "2023-05-05T08:34:55Z")

</div>

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:

```auto
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?

---

<div class="post-metadata">

**Author:** ![rlkoshak](https://community.openhab.org/user_avatar/community.openhab.org/rlkoshak/32/75251_2.png) [@rlkoshak](https://community.openhab.org/u/rlkoshak)\
**Post date:** [May 5, 2023, 2:04pm UTC](https://community.openhab.org/t/trigger-a-rule-when-a-thing-goes-offline-because-of-communication-error/146494/2 "2023-05-05T14:04:03Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![obones](https://community.openhab.org/user_avatar/community.openhab.org/obones/32/68523_2.png) [@obones](https://community.openhab.org/u/obones)\
**Post date:** [May 5, 2023, 2:57pm UTC](https://community.openhab.org/t/trigger-a-rule-when-a-thing-goes-offline-because-of-communication-error/146494/3 "2023-05-05T14:57:35Z")

</div>

> [@rlkoshak](#):
>
> Why not trigger on the COMMUNICATION\_ERROR state instead of OFFLINE?

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

 ![image](https://community-openhab-org.s3.dualstack.eu-central-1.amazonaws.com/original/3X/3/6/364ad1f4861f664b165e8cd00efd86fca4f055da.png)

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

---

<div class="post-metadata">

**Author:** ![rlkoshak](https://community.openhab.org/user_avatar/community.openhab.org/rlkoshak/32/75251_2.png) [@rlkoshak](https://community.openhab.org/u/rlkoshak)\
**Post date:** [May 5, 2023, 3:32pm UTC](https://community.openhab.org/t/trigger-a-rule-when-a-thing-goes-offline-because-of-communication-error/146494/4 "2023-05-05T15:32:22Z")

</div>

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

```javascript
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.

---

<div class="post-metadata">

**Author:** ![obones](https://community.openhab.org/user_avatar/community.openhab.org/obones/32/68523_2.png) [@obones](https://community.openhab.org/u/obones)\
**Post date:** [May 5, 2023, 3:48pm UTC](https://community.openhab.org/t/trigger-a-rule-when-a-thing-goes-offline-because-of-communication-error/146494/5 "2023-05-05T15:48:36Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Matze0211](https://community.openhab.org/letter_avatar_proxy/v4/letter/m/c0e974/32.png) [@Matze0211](https://community.openhab.org/u/Matze0211)\
**Post date:** [May 15, 2023, 6:18am UTC](https://community.openhab.org/t/trigger-a-rule-when-a-thing-goes-offline-because-of-communication-error/146494/6 "2023-05-15T06:18:08Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![obones](https://community.openhab.org/user_avatar/community.openhab.org/obones/32/68523_2.png) [@obones](https://community.openhab.org/u/obones)\
**Post date:** [May 15, 2023, 7:32am UTC](https://community.openhab.org/t/trigger-a-rule-when-a-thing-goes-offline-because-of-communication-error/146494/7 "2023-05-15T07:32:30Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![Chiuaua79](https://community.openhab.org/user_avatar/community.openhab.org/chiuaua79/32/58738_2.png) [@Chiuaua79](https://community.openhab.org/u/Chiuaua79)\
**Post date:** [September 18, 2023, 2:35pm UTC](https://community.openhab.org/t/trigger-a-rule-when-a-thing-goes-offline-because-of-communication-error/146494/8 "2023-09-18T14:35:44Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![obones](https://community.openhab.org/user_avatar/community.openhab.org/obones/32/68523_2.png) [@obones](https://community.openhab.org/u/obones)\
**Post date:** [September 18, 2023, 3:25pm UTC](https://community.openhab.org/t/trigger-a-rule-when-a-thing-goes-offline-because-of-communication-error/146494/9 "2023-09-18T15:25:04Z")

</div>

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

```auto
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

```

---

<div class="post-metadata">

**Author:** ![Chiuaua79](https://community.openhab.org/user_avatar/community.openhab.org/chiuaua79/32/58738_2.png) [@Chiuaua79](https://community.openhab.org/u/Chiuaua79)\
**Post date:** [September 18, 2023, 5:02pm UTC](https://community.openhab.org/t/trigger-a-rule-when-a-thing-goes-offline-because-of-communication-error/146494/10 "2023-09-18T17:02:12Z")

</div>

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…

---

<div class="post-metadata">

**Author:** ![Chiuaua79](https://community.openhab.org/user_avatar/community.openhab.org/chiuaua79/32/58738_2.png) [@Chiuaua79](https://community.openhab.org/u/Chiuaua79)\
**Post date:** [December 30, 2023, 9:44pm UTC](https://community.openhab.org/t/trigger-a-rule-when-a-thing-goes-offline-because-of-communication-error/146494/11 "2023-12-30T21:44:58Z")

</div>

Aaaaaand it is beyond Christmas and the rule did not provide a successful reset yet. TBH today the bridge finally turned zombie for once. And the rule I made in rules DSL behaved correctly but did not solve the problem. I think due to a power outage one month ago due to which the Innr power plug did not reconnect to my hue bridge properly (I have two Innr plugs, both were unreachable after that time). My hypothesis is that the plugs probably want to connect to the bridge when it is not yet online, fail and don’t retry. I did not try to reconnect them on purpose, just because of this rule.

Anyway, my DSL rule looks like this:

```php
// Triggers:
// - When velux:klf200:meterkast changed

// context: veluxreset-1
if (getThingStatusInfo("velux:klf200:meterkast").getStatusDetail().toString() == "COMMUNICATION_ERROR") {
	logWarn("VeluxWARN", "Velux KLF is zombie, restarting it via the power socket")
	logInfo("VeluxINFO", "Velux KLF zombie -> disable bridge")
	sendHttpPutRequest("http://localhost:8080/rest/things/velux:klf200:meterkast/enable", "text/plain", "false", headers, 1000)
	Thread::sleep(2000)
	logInfo("VeluxINFO", "Velux KLF zombie -> power off")
	Velux_Bridge_Smartplug.sendCommand(OFF)
	Thread::sleep(10000)
	logInfo("VeluxINFO", "Velux KLF zombie -> power on")
	Velux_Bridge_Smartplug.sendCommand(ON)
	VeluxEnableTimer = createTimer(now.plusSeconds(30))[|
		logInfo("VeluxINFO", "Velux KLF zombie -> enable bridge")
		sendHttpPutRequest("http://localhost:8080/rest/things/velux:klf200:meterkast/enable", "text/plain", "true", headers, 1000)
		VeluxEnableTimer = null
	]
}

```

Reason that it took three-and-half month to finally turn zombie:  
I bought the Innr plugs only after the previous post (innr as these had the right dimensions not to block the plugs next to it and are compitable with the hue environment that is already present).  
After incorporating them in hue, one wall switch of hue commanded a room i.s.o. a single light, took me a few weeks to figure out that mistake (turning off the bridge together with the light).  
Had to turn of power a few times for other reasons and finally the power outage one month ago…

Now waiting for the next zombie state (plugs are paired again) 🙂

---

<div class="post-metadata">

**Author:** ![Matze0211](https://community.openhab.org/letter_avatar_proxy/v4/letter/m/c0e974/32.png) [@Matze0211](https://community.openhab.org/u/Matze0211)\
**Post date:** [December 30, 2023, 11:02pm UTC](https://community.openhab.org/t/trigger-a-rule-when-a-thing-goes-offline-because-of-communication-error/146494/12 "2023-12-30T23:02:36Z")

</div>

Not sure if it will help:  
After I moved the klf200 bridge closer to the roller shutters I want to control, I have not faced the communication error between klf200 and OH again. Maybe weak signal was causing this
