I have DSL code which call external script, but external script read “old” state. Is there possible to force some upgate of items in OH before call external script?
The code seems as following:
vlState = OFF; //or ON
SwitchVirtual_SwitchVirtualAllSwitches.sendCommand(vlState);
logInfo("key pressed", "-------key pressed 8, vlState:{}", vlState.toString()); //<---here is ok
// some force update method of OH??
callScript("Switches-All-OFF.script");
// //*** called script - inside this script is:
// var vlState = SwitchVirtual_SwitchVirtualAllSwitches.state.toString();
// logInfo("22:00 - ALL LIGHTS IN HOME OFF", "time: {}, w.state:{}", vtCurrentTime,vlState.toString()); //<--- here is previous value :-(
// //***end called script
logInfo("pilot pressed", "pilot pressed - key: {}, vlState: {}", viKey.toString(), vlState.toString()); // <--- here is ok, actual value
The short answer is no, there is no way to wait for the Items to change state after receiving a command. Commands are processed in parallel and there is no guarantee that the Item will ever change state in response to the command anyway. And if this Item is a Group Item, as it’s name implies, you don’t have just the one Item that needs to be updated in response to the command (and may never actually change state at all) but all it’s members.
You can add a sleep or make the call happen in a timer to delay the call but there’s no guarantee that the state is the result of the command. If the delay is too short it might still be processing the command. If it’s to long, it may be another command was sent or other interactions changed things in the mean time.
If you want a log statement when this Item changes to OFF, trigger a rule based on that event and put your log statement there. Or, since you know you command the Item to OFF, pass that as an argument to the script and log out that argument.
Ultimately this smells of an XY Problem. This is a really odd thing to put into a script and it’s not clear why it’s in a script.