afterSec() cancels previous afterSec()
Posted: Thursday 01 September 2022 21:11
I have an event that when a certain temp sensor is >= X then it sends an switchOff().afterSec(900) command. So when the value reaches X, I want to send the OFF command to the device 900 seconds later.
But the temp sensor gets updates every approx 60 seconds. Eventually the OFF command is never sent as I expect that the next minute the afterSec() command will overwrite the previous queue command. Eventually the OFF command is always scheduled, net never met.
Is there a function to solve this? I can create a dummy device and set the 'new' value and only send the switchOff().afterSec(900) command when the dummy value is not off, but this is not a nice solution.
Is there a way to read the queue and if there is already a switchOff() command in the queue, then ignore, if there's nothing in the queue, then schedule the command.
But the temp sensor gets updates every approx 60 seconds. Eventually the OFF command is never sent as I expect that the next minute the afterSec() command will overwrite the previous queue command. Eventually the OFF command is always scheduled, net never met.
Is there a function to solve this? I can create a dummy device and set the 'new' value and only send the switchOff().afterSec(900) command when the dummy value is not off, but this is not a nice solution.
Is there a way to read the queue and if there is already a switchOff() command in the queue, then ignore, if there's nothing in the queue, then schedule the command.