When sending a command to an item from scripting via sendCommand in ECMAScript-2021, the command is processed asynchronously and the script actually does not know if the command was processed successfully. Is there any way for the script to find out whether a command has been executed without errors or not?
Not directly. But OH is event driven and there is an event when an Item changes state. If you turn off autoupdate (see the “Add metadata” section of the Item) than the Item will not update/change it’s state until the device reports a new state. So you could create a timer and check to see if the Item changed state as expected sometime after sending the command.
Thanks, I’ll give that a try. Not sure if it works in my situation, I am looking at the Speak channel of an Amazon Echo Dot via that binding. It is of type String and with sendCommand you send the text there, but I don’t know at which point the state gets updated with the text, before or after it was actually processed.
In that case I’m pretty certain the state of the Item gets updated by autoupdate only which happens immediately. I don’t think the Speak channel ever updates the Item to anything at all. If you disable autoupdate the Item will remain NULL forever and you’ll have no way to know if the command made it to the device.