When migrating from OH2 to OH3 startup is not executed. In openhab log is
2023-02-26 11:51:52.905 [INFO ] [.thing.internal.GenericThingProvider] - No ThingHandlerFactory found for thing exec:command:arduino_send (thing-type is exec:command). Deferring initialization.
2023-02-26 11:51:52.909 [INFO ] [.thing.internal.GenericThingProvider] - No ThingHandlerFactory found for thing exec:command:persistence (thing-type is exec:command). Deferring initialization.
skipping log garbage from startup
2023-02-26 11:52:03.902 [INFO ] [rg.openhab.core.model.script.STARTUP] - Startup finished...
In events log is
2023-02-26 11:52:05.084 [INFO ] [ab.event.ThingStatusInfoChangedEvent] - Thing 'exec:command:arduino_send' changed from UNINITIALIZED to INITIALIZING
2023-02-26 11:52:05.104 [INFO ] [ab.event.ThingStatusInfoChangedEvent] - Thing 'exec:command:arduino_send' changed from INITIALIZING to ONLINE
2023-02-26 11:52:05.112 [INFO ] [ab.event.ThingStatusInfoChangedEvent] - Thing 'exec:command:persistence' changed from UNINITIALIZED to INITIALIZING
2023-02-26 11:52:05.128 [INFO ] [ab.event.ThingStatusInfoChangedEvent] - Thing 'exec:command:persistence' changed from INITIALIZING to ONLINE
Startup needs the bindings, but as you see the bindings have started cca 2 seconds after startup finished, all exec commands in startup returned NULL.
Searching this forum gets me to idea of waiting for needed exec bindings to be ONLINE and I have created this code:
var ThingStatus = Java.type("org.openhab.core.thing.ThingStatus")
var Thing_exec_binding = Java.type("org.openhab.core.model.script.actions.Things")
var persistence_binding_status = Thing_exec_binding.getThingStatusInfo("exec:command:persistence")
var arduino_binding_status = Thing_exec_binding.getThingStatusInfo("exec:command:arduino_send")
rule "Startup"
when
System started
then
logInfo ("STARTUP", "System Starting...")
auto_runner_lock.lock()
while ((persistence_binding_status != ThingStatus.ONLINE) || (arduino_binding_status != ThingStatus.ONLINE)) {
logInfo ("STARTUP", "Waiting for exec bindings to start, currently persistence: "+persistence_binding_status+" arduino:"+arduino_binding_status)
Thread::sleep (1234)
persistence_binding_status = Thing_exec_binding.getThingStatusInfo("exec:command:persistence")
arduino_binding_status = Thing_exec_binding.getThingStatusInfo("exec:command:arduino_send")
}
When uploaded to OH3 there is following error:
2023-02-26 12:10:53.237 [INFO ] [el.core.internal.ModelRepositoryImpl] - Validation issues found in configuration model 'rollershutter.rules', using it anyway:
The field Tmp_rollershutterRules.Thing_exec_binding refers to the missing type Object
The field Tmp_rollershutterRules.Thing_exec_binding refers to the missing type Object
The field Tmp_rollershutterRules.persistence_binding_status refers to the missing type Object
The field Tmp_rollershutterRules.arduino_binding_status refers to the missing type Object
The field Tmp_rollershutterRules.persistence_binding_status refers to the missing type Object
The field Tmp_rollershutterRules.arduino_binding_status refers to the missing type Object
The field Tmp_rollershutterRules.persistence_binding_status refers to the missing type Object
The field Tmp_rollershutterRules.Thing_exec_binding refers to the missing type Object
The field Tmp_rollershutterRules.arduino_binding_status refers to the missing type Object
The field Tmp_rollershutterRules.Thing_exec_binding refers to the missing type Object
2023-02-26 12:11:09.134 [WARN ] [e.runtime.internal.RuleContextHelper] - Variable 'Thing_exec_binding' on rule file 'rollershutter.rules' cannot be initialized with value '<XFeatureCallImplCustom>.type(<XStringLiteralImpl>)': The name 'Java' cannot be resolved to an item or type; line 16, column 26, length 4
2023-02-26 12:11:09.140 [WARN ] [e.runtime.internal.RuleContextHelper] - Variable 'persistence_binding_status' on rule file 'rollershutter.rules' cannot be initialized with value '<XFeatureCallImplCustom>.getThingStatusInfo(<XStringLiteralImpl>)': 'getThingStatusInfo' is not a member of 'Object'; line 17, column 34, length 65
2023-02-26 12:11:09.145 [WARN ] [e.runtime.internal.RuleContextHelper] - Variable 'arduino_binding_status' on rule file 'rollershutter.rules' cannot be initialized with value '<XFeatureCallImplCustom>.getThingStatusInfo(<XStringLiteralImpl>)': 'getThingStatusInfo' is not a member of 'Object'; line 18, column 30, length 66
Can someone please guide me what I’m doing wrong. I’m not very good at the specific language used in openhab rules.
Thank you