I am experiencing a reproducible problem with the initialising of things after a reboot of my RP (openhabian). To me this looks like a race condition, openhab starts at the same time as EVCC, MQTT and Zigbee2MQTT + ZWave-js. As a result, some of the things for EVCC and for Zigbee / Zwave nodes stay UNINITIALISED or in ERROR communicating or OFFLINE. I presume because the startup of openhab is faster than the startup of the other packages. The problem is reproducible, in that it happens after each reboot, only that it is not always the same nodes, of course.
I found a hack to fix this, namely a small JS script:
rules.JSRule({
name: "JS: Thing_Status update on Trigger_Things",
description: "Updates all Thing_Status items on command",
triggers: [
triggers.GenericCronTrigger("0 9,39 * ? * * *")
],
//conditions: [
// () => items.getItem("Delayed_Startup").state === "ON"
//],
execute: () => {
logger.info("JS ---> Run Thing Status update");
const group = items.getItem("Thing_Status");
group.members.forEach((item) => {
const meta = item.getMetadata("thingUID");
if (!meta) {
logger.warn(`JS ---> Status item ${item.itemName} has no Metadata for ThingUID`);
return;
}
const thing = things.getThing(meta.value);
if (!thing) {
logger.warn(`JS ---> Thing not found for UID: ${meta.value}`);
return;
}
const thingStatus = thing.status;
// check if not ONLINE and try to recover
if (!thingStatus || thingStatus.toString() !== "ONLINE") {
logger.info(`JS --> Thing ${meta.value} is ${thingStatus.toString()}, trying to recover by disabling/enabling the thing`);
// disable
thing.setEnabled(false);
// wait 30 sec
java.lang.Thread.sleep(30000);
// enable
thing.setEnabled(true);
}
});
}
});
I am storing the UI in the metadata of items that I arrange in a group, as you can see, to make this work. After this rule has run the first time, all things are ONLINE.
I was wondering, to me this setup of using MQTT + Zigbee/Zwave and/or EVCC looks rather standard, do others have a similar issue at startup ? Is there a way to fix this centrally instead of this hack ?