Page 1 of 1

How to cancel queued commandArray{} events

Posted: Monday 22 January 2024 9:23
by Daiii
I'm porting over some old LUA scripts from seven years ago, and am wondering if something has changed in the method for cancelling a queued commandArray{} event. Suppose we issue:

Code: Select all

commandArray[ 'MyDevice' ] = "On AFTER 30"
and then, a little later, we wish to remove that queued request that hasn't yet fired. Or, perhaps we don't even know for sure if there are any pending requests, but we just want to make sure the device remains in it's present state without generating any radio traffic. It used to be we could issue:

Code: Select all

commandArray[ 'MyDevice' ] = "" -- Empty string cancellation request
and it would clear all queued requests on MyDevice. This worked in 2017 for OpenZwave devices, but with Domoticz 2024.2 and ZWave-JS-UI 9.7.1 the Domoticz log shows:

Code: Select all

Error: ZWaveMqtt: Switch command not supported ( - zwavejs2mqtt_0xef7cfb02_3-37-1-currentValue/MyDevice)
where ZWaveMqtt is my Domoticz MQTT autodiscovery gateway.

So, it looks like the empty "" commandArray{} string has lost its former special meaning of clearing the device queue, and is now just seen as a bogus unsupported command. Oddly, it DOES still have the effect of cancelling queued events even though it is reported as an error. Also, I verified that no ZWave MQTT traffic is generated directly in response to issuing the empty string.

Is there some new commandArray{} syntax to cleanly request that a device's queue be internally cleared?

Thanks

Re: How to cancel queued commandArray{} events

Posted: Monday 22 January 2024 10:06
by psubiaco
Hi,
commandArray is a "table" variable that the running script uses to send commands to Domoticz.
While the script is executing, it can add new entries, test if an entry exist, cancel entries, and so on.
When the script returns, commandArray is read by Domoticz.

Re: How to cancel queued commandArray{} events

Posted: Monday 22 January 2024 11:59
by jvdz
I do not think there is an option to cancel an scheduled event with regular LUA, but it seems to be possible in DzVents with: cancelQueuedCommands()

Re: How to cancel queued commandArray{} events

Posted: Monday 22 January 2024 12:51
by Kedi
Did you try?

Code: Select all

commandArray[ 'MyDevice' ] = "Cancel"

Re: How to cancel queued commandArray{} events

Posted: Monday 22 January 2024 17:55
by Daiii
Thank you, everyone, for your replies. I am not using DzVents, but your combined comments led me to inspect MQTTAutoDiscover::SendSwitchCommand for clues, and it turns out that a variation on Kedi's suggestion sortof accomplishes what I'm after:

Code: Select all

commandArray[ 'MyDevice' ] = "Stop"
I'd tried sending "Cancel" but that still logs the "Switch command not supported" error. However, the MQTT code recognizes "Stop", does not throw an error, and does indeed clear the device queue as a side effect.

This seems usable on the surface, but non-MQTT switches might not recognize "Stop", and the method comes with an undesirable side effect: the "Stop" command is accompanied by outgoing MQTT traffic to ZWave-JS-UI, and I have no idea whether that's creating additional radio traffic. Since queued future requests are completely internal to Domoticz, I was hoping for some method of clearing a device queue that did not "leak out" at all.

The (approx seven year old) method of clearing a device's queue simply by writing an empty command string was really nice. Was that lovely feature removed intentionally? I may just give up on this and write my own implementations of AFTER and FOR. That would mimic how DzVents manages to provide cancelQueuedCommands() within it's own mechanism.