This forum uses cookies
This forum makes use of cookies to store your login information if you are registered, and your last visit if you are not. Cookies are small text documents stored on your computer; the cookies set by this forum can only be used on this website and pose no security risk. Cookies on this forum also track the specific topics you have read and when you last read them. Please confirm that you accept these cookies being set.

Alert Manager
#85
I have written this script for surveillance of alarms. It will only generate one alarm if an Object is not updated within a range of time. You can use it as Resident or Scheduled Script. It takes every object with the tag "Alarm". Change the "controlltime" to your desire.

Code:
--This script is for Object surveillance passivley with the updatetime property
--Alarms will be updated on change!

alarms = grp.tag('Alarm') --add the Tag or Tags of the Object that need surveillance

controlltime = 30 --Allowed Time between recieved Telegramms in Seconds

--initializing Tables for Alarming
currentstate = {}
previousstate = storage.get("previousstate") or {}


now = os.time()

--Iteration throgh the alarms Table to get the update time of every Object

for index, alarm in ipairs(alarms) do
    lastrecieved = alarm.updatetime

    local online
    --calculating the Timedelta and comparing it with our Variable
    if (now - lastrecieved) > controlltime then
        online = false
    else
        online = true
    end

    -- Store the current status in the currentstatus table
    currentstate[alarm.id] = {id = alarm.id, comment = alarm.comment, online = online}

    -- Compare the current status with the previous status
    if previousstate[alarm.id] == nil or currentstate[alarm.id].online ~= previousstate[alarm.id].online then
        if not currentstate[alarm.id].online then
            alert("Alarm " .. currentstate[alarm.id].comment .. " nicht verfügbar")
          else
                  alert("Alarm " ..currentstate[alarm.id].comment .. " verfügbar")
        end
    end

end

-- Log the current status
-- log(currentstate)

-- Save the current status to persistent storage as previous status
storage.set("previousstate", currentstate)




And this script that will actively send a read request to check if alarms are still available. It will take every objekt with the tag "Alarm". This is designed to be used as resedent or scheduled script.

Code:
-- Variables as Tag
alarms = grp.tag('Alarm')


currentstatus = {}
previousstate = storage.get("previousstate") or {}

-- Iterate over all alarms
for index, alarm in ipairs(alarms) do
    value, responding = grp.readvalue(alarm.address, readtimeout)
    local online

    if responding == "timeout" then
        online = false
    else
        online = true
    end

    -- Store the current status in the currentstatus table
    currentstatus[alarm.id] = {id = alarm.id, name = alarm.name, online = online}

    -- Compare the current status with the previous status
    if previousstate[alarm.id] == nil or currentstatus[alarm.id].online ~= previousstate[alarm.id].online then
        if not currentstatus[alarm.id].online then
            alert("Alarm " .. currentstatus[alarm.id].name .. " nicht verfügbar")
        end
    end
end

-- Log the current status
--log(currentstatus)

-- Save the current status to persistent storage as previous status
storage.set("previousstate", currentstatus)
Reply


Messages In This Thread
Alert Manager - by Erwin van der Zwart - 07.02.2017, 10:36
RE: Alert Manager - by buuuudzik - 07.02.2017, 11:58
RE: Alert Manager - by Erwin van der Zwart - 07.02.2017, 12:23
RE: Alert Manager - by buuuudzik - 07.02.2017, 13:59
RE: Alert Manager - by Igor68 - 09.02.2017, 15:18
RE: Alert Manager - by Erwin van der Zwart - 09.02.2017, 18:44
RE: Alert Manager - by Igor68 - 13.02.2017, 10:41
RE: Alert Manager - by Erwin van der Zwart - 13.02.2017, 13:00
RE: Alert Manager - by Igor68 - 14.02.2017, 15:42
RE: Alert Manager - by Erwin van der Zwart - 14.02.2017, 15:56
RE: Alert Manager - by Igor68 - 15.02.2017, 01:38
RE: Alert Manager - by Erwin van der Zwart - 16.02.2017, 09:10
RE: Alert Manager - by Igor68 - 16.02.2017, 15:51
RE: Alert Manager - by admin - 16.02.2017, 16:06
RE: Alert Manager - by admin - 17.02.2017, 10:28
RE: Alert Manager - by Trond Hoyem - 20.02.2017, 07:09
RE: Alert Manager - by Erwin van der Zwart - 20.02.2017, 08:07
RE: Alert Manager - by Mirco - 20.02.2017, 14:05
RE: Alert Manager - by Erwin van der Zwart - 20.02.2017, 16:12
RE: Alert Manager - by Igor68 - 20.02.2017, 14:17
RE: Alert Manager - by admin - 20.02.2017, 14:24
RE: Alert Manager - by Igor68 - 20.02.2017, 15:39
RE: Alert Manager - by cekca - 07.06.2017, 14:28
RE: Alert Manager - by Erwin van der Zwart - 07.06.2017, 16:45
RE: Alert Manager - by Thomas - 07.06.2017, 17:26
RE: Alert Manager - by Erwin van der Zwart - 07.06.2017, 18:09
RE: Alert Manager - by Thomas - 08.06.2017, 09:30
RE: Alert Manager - by Erwin van der Zwart - 08.06.2017, 12:05
RE: Alert Manager - by Erwin van der Zwart - 01.08.2017, 20:52
RE: Alert Manager - by morak - 02.08.2017, 16:47
RE: Alert Manager - by davidsilva - 16.07.2019, 18:06
RE: Alert Manager - by suporte.arqtech - 29.11.2017, 17:19
RE: Alert Manager - by Erwin van der Zwart - 29.11.2017, 19:08
RE: Alert Manager - by andrepneves@gmail.com - 12.12.2017, 16:15
RE: Alert Manager - by Erwin van der Zwart - 12.12.2017, 19:00
RE: Alert Manager - by ajgarcia.reyse - 04.09.2018, 07:28
RE: Alert Manager - by Erwin van der Zwart - 04.09.2018, 08:20
RE: Alert Manager - by domotiqa - 24.09.2018, 16:36
RE: Alert Manager - by Erwin van der Zwart - 24.09.2018, 19:27
RE: Alert Manager - by Daniel - 25.09.2018, 07:23
RE: Alert Manager - by domotiqa - 26.09.2018, 07:25
RE: Alert Manager - by Daniel - 26.09.2018, 07:29
RE: Alert Manager - by dennisslutter - 02.10.2018, 15:39
RE: Alert Manager - by Erwin van der Zwart - 02.10.2018, 16:11
RE: Alert Manager - by domotiqa - 17.07.2019, 07:19
RE: Alert Manager - by Daniel - 17.07.2019, 07:46
RE: Alert Manager - by domotiqa - 17.07.2019, 13:18
RE: Alert Manager - by domotiqa - 01.10.2019, 04:59
RE: Alert Manager - by Erwin van der Zwart - 01.10.2019, 10:02
RE: Alert Manager - by Daniel - 06.12.2019, 13:33
RE: Alert Manager - by alexgleyzer - 25.02.2020, 17:52
RE: Alert Manager - by Erwin van der Zwart - 25.02.2020, 18:07
RE: Alert Manager - by alexgleyzer - 27.02.2020, 16:37
RE: Alert Manager - by Trond Hoyem - 30.03.2020, 09:06
RE: Alert Manager - by Daniel - 25.02.2020, 18:54
RE: Alert Manager - by davidchispas - 14.04.2020, 17:43
RE: Alert Manager - by Erwin van der Zwart - 14.04.2020, 20:23
RE: Alert Manager - by JRP - 24.06.2020, 11:09
RE: Alert Manager - by Erwin van der Zwart - 24.06.2020, 13:52
RE: Alert Manager - by JRP - 27.06.2020, 15:23
RE: Alert Manager - by Erwin van der Zwart - 27.06.2020, 19:58
alert manager problem - by Frank68 - 23.09.2020, 13:15
RE: Alert Manager - by Erwin van der Zwart - 23.09.2020, 21:30
RE: Alert Manager - by davidchispas - 12.01.2021, 09:31
RE: Alert Manager - by Daniel - 12.01.2021, 09:47
RE: Alert Manager - by davidchispas - 12.01.2021, 11:30
RE: Alert Manager - by Daniel - 12.01.2021, 11:31
RE: Alert Manager - by davidchispas - 12.01.2021, 11:35
RE: Alert Manager - by davidchispas - 14.01.2021, 15:42
RE: Alert Manager - by Daniel - 14.01.2021, 15:50
RE: Alert Manager - by Frank68 - 18.01.2021, 09:09
RE: Alert Manager - by JRP - 20.04.2021, 09:10
RE: Alert Manager - by Daniel - 20.04.2021, 09:13
RE: Alert Manager - by Erwin van der Zwart - 20.04.2021, 10:50
RE: Alert Manager - by JRP - 20.04.2021, 10:55
RE: Alert Manager - by xxyzz - 02.06.2024, 16:41
RE: Alert Manager - by admin - 03.06.2024, 06:51
RE: Alert Manager - by Erwin van der Zwart - 03.06.2024, 11:05
RE: Alert Manager - by iJAF - 03.06.2024, 11:33
RE: Alert Manager - by Daniel - 03.06.2024, 11:34
RE: Alert Manager - by xxyzz - 05.08.2024, 04:47

Forum Jump: