I am struggling through the different syntax (ECMA 5.1, ECMA 11, DSL). I am a beginner, so for many examples I don’t even know which syntax it is. Accordingly, I use Blockly where possible. Which code does Blockly actually generate, ECMA 5.1?
Anyway, I am not getting anywhere at this point:
I should know the syntax to add an item to a group in a Blockly Block “Inline Script” and add a member to the group accordingly. Unfortunately I can’t do it.
I also cannot implement this example: [Javascript: how to dynamically add items to groups? - #2 by Gonzo666
"use strict";
var logger = Java.type("org.slf4j.LoggerFactory").getLogger("org.openhab.rule." + ctx.ruleUID);
var dynamicGroup = ir.getItem("gDoorOverdue");
var triggeritem = ir.getItem(event.itemName);
if (event.itemState == "ON") {
triggeritem.addGroupName("gDoorOverdue");
dynamicGroup.addMember(triggeritem);
dynamicGroup.setState(ON);
} else {
triggeritem.removeGroupName("gDoorOverdue");
dynamicGroup.removeMember(triggeritem);
}
I always get errors whether I try to run this in ECMA or DSL. Even deleting the first line “use strict” ( whose meaning I don’t understand) doesn’t lead to any success.
What I am actually trying to implement is:
I have defined a scene for light.
Now I want to switch the scene to inactive if the condition for the scene is no longer true.
I want to trigger a rule when the status of an item in the scene changes.
To do this, I wanted to add the associated items to a group when the scene is activated.
And on an update in this group then start the “Scene still valid?” rule.
But I can’t add or remove an item from/to a group in Blockly and I can’t do it with the “Inline Script” block.
Alternatively I could write the items that belong to the scene into metadata. I can do this in Blockly. But how do I find out if an item of the scene has changed? I can’t use metadata to trigger a rule.
Do I have a wrong approach or just not the right syntax?