16.07.2023, 10:10
(This post was last modified: 16.07.2023, 10:47 by josdegroot.)
Hello everyone,
I've been working on a Lua script to control a group object in my system, but I'm having some trouble getting it to work as expected. I was hoping someone here might be able to help me figure out what's going wrong.
Here's the idea behind the script: I want to check a specific group object (with ID "0/0/21") and see if it has not been turned on for at least 5 minutes. If it hasn't, I want to turn it on for 3 minutes and then turn it off again.
I'm using the `grp.getvalue(alias)` function to check the last time the group object was turned on, and the `grp.setvalue(alias, value)` function to turn the group object on and off. However, the script doesn't seem to be working as expected.
Does anyone have any ideas about what might be going wrong? Any help would be greatly appreciated!
Thanks in advance.
I've been working on a Lua script to control a group object in my system, but I'm having some trouble getting it to work as expected. I was hoping someone here might be able to help me figure out what's going wrong.
Here's the idea behind the script: I want to check a specific group object (with ID "0/0/21") and see if it has not been turned on for at least 5 minutes. If it hasn't, I want to turn it on for 3 minutes and then turn it off again.
Code:
-- Define the group object ID
local groupObjectID = "0/0/21"
-- Define the time duration in seconds
local fiveMinutesInSeconds = 5 * 60
local threeMinutesInSeconds = 3 * 60
-- Check the current status of the group object
local currentStatus = grp.getvalue(groupObjectID)
-- If the group object is off, start the timer
if currentStatus == 0 then
-- Check if the timer has already been started
if not offTime then
-- Start the timer
offTime = os.time()
else
-- Check if the group object has been off for at least 5 minutes
if os.time() - offTime >= fiveMinutesInSeconds then
-- Turn on the group object
grp.setvalue(groupObjectID, true)
-- Wait for 3 minutes
os.execute("sleep " .. threeMinutesInSeconds)
-- Turn off the group object
grp.setvalue(groupObjectID, false)
-- Reset the timer
offTime = nil
end
end
else
-- If the group object is on, reset the timer
offTime = nil
end
I'm using the `grp.getvalue(alias)` function to check the last time the group object was turned on, and the `grp.setvalue(alias, value)` function to turn the group object on and off. However, the script doesn't seem to be working as expected.
Does anyone have any ideas about what might be going wrong? Any help would be greatly appreciated!
Thanks in advance.