I’m having an issue where at least one of my lights was not comming on when it was supposed to. I don’t have a lot of time right now to debug issues like these so I’m doing triage. I had a little bit of time today and looked at the logs and it seems that the commands are being sent but one of my lights isn’t comming on when it’s commanded.
On a hunch I am guessing that the problem is too many commands are going out all at once on the same technology.
An important piece of info here is that I’m using Scenes.
I didn’t want to go through all of the effort of totally changing my approach so I did some digging and figured out a pretty simple rule that can retrieve the Items and the commands defined in a Scene.
The following code does the following:
- maps the time of day to the UID of a Scene
- pulls the Scene from the registry
- extracts the Item names and commands to send
- sends the commands with a 200 msec delay between them instead of all at once as fast as possible like the scene normally does
const { ruleRegistry } = require('@runtime/RuleSupport');
const { Gatekeeper } = require('openhab_rules_tools');
const gk = cache.private.get('gatekeeper', () => Gatekeeper());
const mapping = { "MORNING": "lights-morning",
"DAY": "lights-day",
"AFTERNOON": "lights_afternoon",
"EVENING": "lights-evening",
"NIGHT": "lights_night",
"BED": "lights_bed" };
const sceneID = mapping[items.TimeOfDay.state];
const modules = utils.javaListToJsArray(ruleRegistry.getByTag('Scene').find(scene => scene.getUID() == sceneID).getModules());
modules.forEach(m => {
const iName = m.getConfiguration().get('itemName');
const cmd = m.getConfiguration().get('command');
console.info('Sending command ' + iName + ' ' + cmd);
gk.addCommand(200, () => items[iName].sendCommandIfDifferent(cmd));
});
Gatekeeper comes from my OHRT library (installable from openHABian or through the rule template on the marketplace) and the rule is triggered based on changes to the TimeOfDay Item which is driven by the Time State Machine rule template. Both tempaltes can be installed through the Add-on store.
When I have some time I’ll figure out a way to make this a reasonable rule template. But in the mean time I figured some might find it useful to see the code. The last seven lines of the code above are the main ones. You could use a sleep instead of Gatekeeper.