04.06.2021, 13:46
Event script (attached to a tag):
Resident script. Adjust the sleep time as needed (at least 5 seconds) depending on the average delay between objects value being detected as out of bounds and the alarm object change to 1.
Code:
value = event.getvalue()
name = grp.find(event.dst).name
now = os.time()
h_key = 'h_alarm'
l_key = 'l_alarm'
h_lim_obj = string.gsub(name, '_PV', '_HAL')
l_lim_obj = string.gsub(name, '_PV', '_LAL')
alarm_h_obj = string.gsub(name, '_PV', '_AHL')
alarm_l_obj = string.gsub(name, '_PV', '_ALL')
h_alarm = value > grp.getvalue(h_lim_obj)
l_alarm = value < grp.getvalue(l_lim_obj)
if h_alarm then
storage.exec('hsetnx', h_key, name, now)
else
storage.exec('hdel', h_key, name)
grp.checkwrite(alarm_h_obj, false)
end
if l_alarm then
storage.exec('hsetnx', l_key, name, now)
else
storage.exec('hdel', l_key, name)
grp.checkwrite(alarm_l_obj, false)
end
Resident script. Adjust the sleep time as needed (at least 5 seconds) depending on the average delay between objects value being detected as out of bounds and the alarm object change to 1.
Code:
if not check then
storage.openconn()
check = function(storage_key, alarm_obj_key)
local now = os.time()
local items = storage.exec('hgetall', storage_key)
for name, time in pairs(items) do
local delay_obj = string.gsub(name, '_PV', '_AD')
time = time + grp.getvalue(delay_obj)
if now >= time then
local alarm_obj = string.gsub(name, '_PV', alarm_obj_key)
grp.checkwrite(alarm_obj, true)
end
end
end
end
check('h_alarm', '_AHL')
check('l_alarm', '_ALL')