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?
Global variable and competing scripts [Solved]
Moderator: leecollings
- waaren
- Posts: 6028
- Joined: Tuesday 03 January 2017 14:18
- Target OS: Linux
- Domoticz version: Beta
- Location: Netherlands
- Contact:
Re: Global variable and competing scripts
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
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
-
- Posts: 2
- Joined: Friday 18 October 2019 11:18
- Target OS: Raspberry Pi / ODroid
- Domoticz version:
- Contact:
Re: Global variable and competing scripts [Solved]
Thanks for the info and suggestion waaren, I'll try both versions!
Who is online
Users browsing this forum: No registered users and 1 guest