Hi All
I’m on OH 3.2 and migrate all my rules to blockly, so far so good. The rules where i need Group Filter i followed this Workaround and it works pretty well.
I have this rule sending a Telegram when a window is open, when more than one Window is open, as many messages are sent as windows are open, thats OK
Then i need another rule with a timer, after the timer expired the command should be sent to each item with the state ON.
This is the blockly
var list, names, status;
var logger = Java.type('org.slf4j.LoggerFactory').getLogger('org.openhab.rule.' + ctx.ruleUID);
var scriptExecution = Java.type('org.openhab.core.model.script.actions.ScriptExecution');
var zdt = Java.type('java.time.ZonedDateTime');
if (typeof this.timers === 'undefined') {
this.timers = [];
}
var list_list = Java.from(itemRegistry.getItem('Vorhaus_Licht').members);
for (var list_index in list_list) {
list = list_list[list_index];
names = list.getName();
status = list.getState();
if (status == 'ON') {
logger.warn(names);
if (typeof this.timers['MyTimer'] === 'undefined' || this.timers['MyTimer'].hasTerminated()) {
this.timers['MyTimer'] = scriptExecution.createTimer(zdt.now().plusSeconds(10), function () {
events.sendCommand(names, 'OFF');
logger.info(names);
})
}
}
}
and the log
2022-01-16 23:09:14.563 [WARN ] [org.openhab.rule.ABTest ] - Vorhaus_Vorhaus1
2022-01-16 23:09:14.603 [WARN ] [org.openhab.rule.ABTest ] - Vorhaus_Vorhaus2
2022-01-16 23:09:24.585 [INFO ] [openhab.event.ItemCommandEvent ] - Item 'GerderobeShelly01_state' received command OFF
2022-01-16 23:09:24.587 [WARN ] [org.openhab.rule.ABTest ] - GerderobeShelly01_stat
The log with the items state is correct but after 10 seconds the command is sent to an item with state not ON but in the same group and the log after the command is also not correct.
If i use a thread.sleep for 10 seconds, each command is sent but not at once, 10 seconds between the commands. and both logs.
var list, names, status;
var logger = Java.type('org.slf4j.LoggerFactory').getLogger('org.openhab.rule.' + ctx.ruleUID);
var thread = Java.type('java.lang.Thread')
var list_list = Java.from(itemRegistry.getItem('Vorhaus_Licht').members);
for (var list_index in list_list) {
list = list_list[list_index];
names = list.getName();
status = list.getState();
if (status == 'ON') {
logger.warn(names);
thread.sleep(10000);
events.sendCommand(names, 'OFF');
logger.warn(names);
}
}
2022-01-16 23:25:57.936 [WARN ] [org.openhab.rule.ABTest ] - Vorhaus_Vorhaus1
2022-01-16 23:26:07.943 [INFO ] [openhab.event.ItemCommandEvent ] - Item 'Vorhaus_Vorhaus1' received command OFF
2022-01-16 23:26:07.946 [WARN ] [org.openhab.rule.ABTest ] - Vorhaus_Vorhaus1
2022-01-16 23:26:07.948 [INFO ] [penhab.event.ItemStatePredictedEvent] - Item 'Vorhaus_Vorhaus1' predicted to become OFF
2022-01-16 23:26:07.956 [INFO ] [openhab.event.ItemStateChangedEvent ] - Item 'Vorhaus_Vorhaus1' changed from ON to OFF
2022-01-16 23:26:07.964 [WARN ] [org.openhab.rule.ABTest ] - Vorhaus_Vorhaus2
2022-01-16 23:26:17.967 [INFO ] [openhab.event.ItemCommandEvent ] - Item 'Vorhaus_Vorhaus2' received command OFF
2022-01-16 23:26:17.967 [WARN ] [org.openhab.rule.ABTest ] - Vorhaus_Vorhaus2
2022-01-16 23:26:17.972 [INFO ] [penhab.event.ItemStatePredictedEvent] - Item 'Vorhaus_Vorhaus2' predicted to become OFF
2022-01-16 23:26:17.985 [INFO ] [openhab.event.ItemStateChangedEvent ] - Item 'Vorhaus_Vorhaus2' changed from ON to OFF
I not need the thread.sleep, it was just a test because with the timer it is not working.
hope somebody can help.
Thanks Rolli