How to create a rule that triggers on error?

I’ve had a pretty stable installation with both zigbee and zwave like once a month they become unavailable. Not knowing exactly why they fall out it is resolved by unplugging and reinserting the usb dongles (or lately by running “usbreset 002/002” to reset the internal usbhub). While I could investigate why they are falling out, it seems hard to solve.

As it happens seldom and is easily fixed by a reset, I was thinking that maybe Openhab could trigger a rule when the error happens? However, I don’t know how to trigger such rule on an error event?

Obviously I am open to other ways of triggering the reset!

Some platform information:

  • Platform information:
    • Hardware: Intel(R) Core™ i7 CPU L 640 @ 2.13GHz, 4GB
    • OS: Ubuntu 22.04.1 LTS
    • openHAB version: openHAB 3.3.0.RC1 - docker environment

Docker container configuration:

docker run \
--name openhab \
--net=host \
-v /etc/localtime:/etc/localtime:ro \
-v /etc/timezone:/etc/timezone:ro \
-v /opt/openhab/conf:/openhab/conf \
-v /opt/openhab/userdata:/openhab/userdata \
-v /opt/openhab/addons:/openhab/addons \
-d \
-e USER_ID=997 \
-e GROUP_ID=997 \
-e CRYPTO_POLICY=unlimited \
--device=/dev/zwave \
--device=/dev/zigbee \
--restart=always \


2022-10-20 14:55:41.145 [ERROR] [zigbee.dongle.ember.ZigBeeDongleEzsp] - EZSP Dongle: Unable to open serial port


2022-11-04 09:07:59.769 [INFO ] [ab.event.ThingStatusInfoChangedEvent] - Thing 'zigbee:coordinator_ember:57f0bf2477' changed from OFFLINE (COMMUNICATION_ERROR) to OFFLINE: Failed to open communications port
2022-11-04 09:07:59.771 [INFO ] [ab.event.ThingStatusInfoChangedEvent] - Thing 'zigbee:coordinator_ember:57f0bf2477' changed from OFFLINE: Failed to open communications port to OFFLINE (COMMUNICATION_ERROR)

lsusb output

Bus 002 Device 021: ID 1a86:7523 QinHeng Electronics CH340 serial converter <= /dev/zigbee
Bus 002 Device 020: ID 10c4:ea60 Silicon Labs CP210x UART Bridge
Bus 002 Device 019: ID 0658:0200 Sigma Designs, Inc. Aeotec Z-Stick Gen5 (ZW090) - UZB <= /dev/zwave
Bus 002 Device 002: ID 8087:0020 Intel Corp. Integrated Rate Matching Hub
Bus 002 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
Bus 001 Device 005: ID 138a:0007 Validity Sensors, Inc. VFS451 Fingerprint Reader
Bus 001 Device 004: ID 03f0:241d HP, Inc Gobi 2000 Wireless Modem (QDL mode)
Bus 001 Device 003: ID 03f0:231d HP, Inc Broadcom 2070 Bluetooth Combo
Bus 001 Device 002: ID 8087:0020 Intel Corp. Integrated Rate Matching Hub
Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub

dmesg.txt (269.5 KB)

So, there’s an openHAB event that can be used to trigger a rule. Is it related to your problem though, or to your unplug/plug recovery action?

I’m not sure what the rule can do, apart from ringing a bell for you. If openHAB cannot get at the serial port, there isn’t much it can do,

Are you able to run that usbreset utility from openHAB?

The event keeps repeating because it cant access the serial port for some reason. So my thought was to trigger an execution of the usbreset using exec binding or something like that whenever I would spot this error in the log. I would need to publish that command to the docker container to do it.

So if I do build a rule for this, im worried that while the usbreset is happening that it will retrigger the rule and end up in an endless loop… any suggestions to how to avoid that?

Sure, make a dummy Item “mySerialError” or something, set it to “recovery in progress” or something when your rule runs, and don’t set it off again until recovery is complete. You might detect that with another rule looking for Thing going ONLINE.

You can very much do a rule on a Thing (say, your zigbee dongle)'s status change. See: Rules | openHAB