Page 1 of 1

Global variable and competing scripts

Posted: Monday 11 November 2019 14:27
by tarentula
Hi all,

I'm quite new to dzVents and Domoticz and I just read about global persistent variables and I thought of a use case where I might use such variables. It's for my alarm system where I want to have motion detected by two different motion sensors within a given time range to trigger the alarm. The reason I don't trigger the alarm right away is to cut down on the number of false alarms.
Anyway, I thought that I would set the current time in a global variable when a motion is detected and the name of the detecting device in another variable. Then when the next sensor detects a motion, it can compare time and name to see if the alarm should be triggered or if it should just update the variables with a new time and device name.
It's important that this pattern is very stable and I wonder if there is any risk of exceptions or other behavior I forgot to think of due to perhaps competing scripts trying to change the same global variables at the same time?
Or perhaps there is a much better way to achieve this?

Re: Global variable and competing scripts

Posted: Monday 11 November 2019 17:14
by waaren
tarentula wrote: Monday 11 November 2019 14:27 It's important that this pattern is very stable and I wonder if there is any risk of exceptions or other behavior I forgot to think of due to perhaps competing scripts trying to change the same global variables at the same time?
This is one way of doing it. No risk of competing scripts because the domoticz event system is single threaded and thus only one script can be active at any time.
Another way might be to evaluate the state and lastUpdate.secondsAgo attributes of the other sensors. That would not require the use of global persistent variables

Re: Global variable and competing scripts  [Solved]

Posted: Wednesday 13 November 2019 9:00
by tarentula
Thanks for the info and suggestion waaren, I'll try both versions!