Hi,
as I read this topic:
I just had a look at my own “sync Button” script/rule combination:
Trigger:
configuration: {}
triggers:
- id: "4"
configuration:
groupName: VorkampswegX_OG_bath
type: core.GroupStateChangeTrigger
conditions: []
actions:
- inputs: {}
id: "2"
configuration:
blockSource: <xml xmlns="https://developers.google.com/blockly/xml"><block
type="oh_runrule" id="!(.8pu/U-Zgyj_m%YZT5" x="86" y="94"><value
name="ruleUID"><shadow type="text" id="S-~hVsRgu}^Gs]Y3em,d"><field
name="TEXT">ruleUID</field></shadow><block type="text"
id="S-~hVsRgu}^Gs]Y3em,d"><field
name="TEXT">script_sync_buttons</field></block></value><value
name="parameters"><block type="dicts_create_with"
id="jVly/bGQhlJ|!,):ZQ/#"><mutation items="2"></mutation><field
name="KEY0">sourceButton</field><field
name="KEY1">targetButton</field><value name="ADD0"><block
type="oh_context_info" id=",/Z)%nG3u/H~g93Ev@(%"><mutation asType="null"
contextInfo="itemName"></mutation><field
name="contextInfo">itemName</field></block></value><value
name="ADD1"><block type="oh_item" id="A0BEhyuegH,l|v=_d#`j"><mutation
itemName="VorkampswegX_OG_bath" itemLabel="Hauptbad"></mutation><field
name="itemName">VorkampswegX_OG_bath</field></block></value></block></value></block></xml>
type: application/javascript
script: >
rules.runRule('script_sync_buttons', {'sourceButton': event.itemName,
'targetButton': 'VorkampswegX_OG_bath'});
type: script.ScriptAction
var source, target, allready_in_execution;
var thread = Java.type('java.lang.Thread')
source = ctx['sourceButton'];
target = ctx['targetButton'];
if (!allready_in_execution) {
allready_in_execution = true;
items.getItem(target).sendCommand(items.getItem(source).state);
}
thread.sleep(500);
allready_in_execution = false;
Having following LOG:
- Item ‘ZWave_Node5_Schalter_2’ changed from ON to OFF
Item ‘VorkampswegX_OG_bath’ received command OFF
Item ‘ZWave_Node5_Schalter_2’ received command OFF
Item ‘ZWave_Node4_Schalter_1’ received command OFF
Item ‘ZWave_Node5_Schalter_2’ predicted to become OFF
Item ‘ZWave_Node4_Schalter_1’ predicted to become OFF
Item ‘ZWave_Node4_Schalter_1’ changed from ON to OFF
Item ‘VorkampswegX_OG_bath’ received command OFF
Item ‘ZWave_Node5_Schalter_2’ received command OFF
Item ‘ZWave_Node4_Schalter_1’ received command OFF
Item ‘ZWave_Node5_Schalter_2’ predicted to become OFF
Item ‘ZWave_Node4_Schalter_1’ predicted to become OFF
For sure it is working as exspected, but I guess everyone can see the issue that the script is triggerd a second time before the flag can be set for dont do it
Can it be optimized without changing the generall aproach? (I know all the alternative statements)
Greatings