In the first go I just wanted to figured out at what happens (regarding the rules) at what startlevel
, what is the status of the rules and whether they are detected at all.
I did not implement a restart of the automation bundle yet. (And in the meanwhile I now know that the restart by the rule is useless because the rule is not triggered.)
startlevel
s according to /usr/share/openhab/runtime/services.cfg
:
# Start level definitions
startlevel:20=dsl:items,managed:item,dsl:things,managed:thing,managed:itemchannellink,dsl:persist,managed:metadata
startlevel:30=persistence:services,persistence:restore,automation:scriptEngineFactories
startlevel:40=dsl:rules,managed:rule,rules:refresh,rules:dslprovider
startlevel:50=ruleengine:start
startlevel:70=dsl:sitemap
startlevel:80=things:handler
My javascript rule ( I like it anyway ;-), perhaps the rule will be of interest in other scenarios:
rules.JSRule({
name: "Rule SystemStartlevelTrigger",
triggers: [
triggers.SystemStartlevelTrigger(20),
triggers.SystemStartlevelTrigger(40),
triggers.SystemStartlevelTrigger(50),
triggers.SystemStartlevelTrigger(70),
triggers.SystemStartlevelTrigger(80),
triggers.SystemStartlevelTrigger(100),
],
execute: function(event) {
console.log(event);
// https://www.openhab.org/javadoc/latest/org/openhab/core/automation/ruleregistry
const { automationManager, ruleRegistry } = require('@runtime/RuleSupport');
const RuleManager = osgi.getService('org.openhab.core.automation.RuleManager');
const allRules = ruleRegistry.getAll()
const content = [];
allRules.forEach(function(rule) {
content.push(
[ rule.getUID()
, rule.getName()
, rule.getActions()[0].getConfiguration().getProperties().type ?? "undefined"
, RuleManager.isEnabled(rule.getUID()).toString()
, RuleManager.getStatus(rule.getUID())
]
)
});
content.sort( function(a, b) {
const nameA = a[0].toUpperCase(); // to avoid case while sort
const nameB = b[0].toUpperCase();
if(nameA > nameB)
return 1;
else if(nameB > nameA)
return -1;
else
return 0;
})
/*
user@ubuntu24-qnap:/etc/openhab/automation/js/node_modules/colors/lib/system$ diff supports-colors.js.org supports-colors.js
28a29,32
> // Failed to execute rule Rule-SystemStartlevelTrigger-ef725908-5555-410b-9bf6-c4d8acb5b527: TypeError: undefined has no such function "indexOf": TypeError: undefined has no such function "indexOf"
> // at exports (/etc/openhab/automation/js/node_modules/colors/lib/system/supports-colors.js:29)
> return false; // colors do not matter for me. "return false" because of exception above.
>
*/
const Table = require('cli-table');
const table = new Table({
head: ['#', 'id', 'name', 'type', 'enabled', 'status']
, colWidths: [ 6, 64, 80, 34, 9, 15]
, colAligns: ['right', 'left', 'left', 'left', 'left', 'left']
});
let i=0
content.forEach( function(row) {
row.unshift(++i)
table.push(row)
})
console.log("\n"+table.toString());
}
});
On restart of openHAB it does not fire att all.
After manual restart of the automation bundle it get
{
"raw": {},
"eventClass": "org.openhab.core.events.system.StartlevelEvent",
"payload": {
"startlevel": 40
}
}
2025-02-09 10:17:44.116 [INFO ] [.automation.script.file.test_rule.js] -
ββββββββ¬βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ¬βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ¬βββββββββββββββββββββββββββββββββββ¬ββββββββββ¬ββββββββββββββββ
β # β id β name β type β enabled β status β
ββββββββΌβββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββΌβββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββΌβββββββββββββββββββββββββββββββββββΌββββββββββΌββββββββββββββββ€
β 1 β 86d89b4908 β Test jruby β application/x-ruby β true β IDLE β
ββββββββΌβββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββΌβββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββΌβββββββββββββββββββββββββββββββββββΌββββββββββΌββββββββββββββββ€
β 2 β aquaClean-1 β user is sitting β application/vnd.openhab.dsl.rule β true β IDLE β
ββββββββΌβββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββΌβββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββΌβββββββββββββββββββββββββββββββββββΌββββββββββΌββββββββββββββββ€
| ... | ... | ... | ... | ... | ... |
ββββββββΌβββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββΌβββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββΌβββββββββββββββββββββββββββββββββββΌββββββββββΌββββββββββββββββ€
β 39 β windbreak-1 β update knx sensor (switch button) β application/vnd.openhab.dsl.rule β true β IDLE β
ββββββββ΄βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ΄βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ΄βββββββββββββββββββββββββββββββββββ΄ββββββββββ΄ββββββββββββββββ
The rule is currently free of side effects. It doesnβt help, but it doesnβt hurt - the result is nice to look at.