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.

scripting knx
#16
Okay, I copied and pasted the script.

But it's not running every hour. I know the function works:

Code:
test_enabled = grp.getvalue('32/3/41')
test_freq = grp.getvalue('32/3/40')

if not test_enabled then
return
end

key = 'prev_test_time'

curr_time = os.time()
prev_time = storage.get(key, 0)
elapsed_hours = math.round((curr_time - prev_time) / 3600)

if elapsed_hours < test_freq then
return
end

storage.set(key, curr_time)

------------------------------------------------------------
-- IP MONITORING (PING) - Simplified Version
-- Logic:
-- 1) Ping all IPs
-- 2) Send status (1/0)
-- 3) Send alarm (1 if no communication)
-- Execution: This script runs when you call it
------------------------------------------------------------

-- Devices: REAL IP + GA status (bool) + GA alarm (bool)
local devices = {
{ real_ip = "192.168.0.11", ga_status = "32/3/14", ga_alarm = "32/3/27" },

{ real_ip = "192.168.0.12", ga_status = "32/3/15", ga_alarm = "32/3/28" },

{ real_ip = "192.168.0.13", ga_status = "32/3/16", ga_alarm = "32/3/29" },

{ real_ip = { 192.168.0.16, ga_estado = "32/3/17", ga_alarma = "32/3/30" },

{ ip_real = "192.168.0.111", ga_estado = "32/3/18", ga_alarma = "32/3/31" },

{ ip_real = "192.168.0.112", ga_estado = "32/3/19", ga_alarma = "32/3/32" },

{ ip_real = "192.168.0.113", ga_estado = "32/3/20", ga_alarma = "32/3/33" },

{ ip_real = "192.168.0.121", ga_estado = { ip_real = "32/3/21", ga_alarma = "32/3/34" },

{ ip_real = "192.168.0.122", ga_estado = "32/3/22", ga_alarma = "32/3/35" },

{ ip_real = "192.168.0.123", ga_estado = "32/3/23", ga_alarma = "32/3/36" },

{ ip_real = "192.168.0.131", ga_estado = "32/3/24", ga_alarma = "32/3/37" },

{ ip_real = "192.168.0.132", ga_estado = "32/3/25", ga_alarma = "32/3/38" }, },

{ real_ip = "192.168.0.133", status_ga = "32/3/26", alarm_ga = "32/3/39" },

{ real_ip = "192.168.0.161", status_ga = "32/3/43", alarm_ga = "32/3/44" }
}

------------------------------------------------------------
-- Function: ping
------------------------------------------------------------
local function test_device(ip)
local cmd = "ping -c 1 -W 1 " .. ip .. " >/dev/null 2>&1"
local result = os.execute(cmd)
return (result == true or result == 0)
end

------------------------------------------------------------
-- Function: run test (only once)
------------------------------------------------------------
local function run_test()
for _, dev in ipairs(devices) do

local ok = test_device(dev.ip_real)

local estado = ok and 1 or 0

local alarma = ok and 0 or 1

grp.write(dev.ga_estado, estado)
grp.write(dev.ga_alarma, alarma)

end
end

------------------------------------------------------------
-- Direct execution of the test
------------------------------------------------------------
ejecutar_test()



I think everything is correct, thanks.

Attached Files Thumbnail(s)
   
Reply


Messages In This Thread
scripting knx - by ALEJANDRO - 08.04.2026, 06:28
RE: scripting knx - by admin - 08.04.2026, 06:37
RE: scripting knx - by ALEJANDRO - 08.04.2026, 14:44
RE: scripting knx - by admin - 08.04.2026, 14:47
RE: scripting knx - by ALEJANDRO - 08.04.2026, 14:59
RE: scripting knx - by AEK - 09.04.2026, 06:50
RE: scripting knx - by ALEJANDRO - 09.04.2026, 11:22
RE: scripting knx - by admin - 09.04.2026, 12:19
RE: scripting knx - by ALEJANDRO - 10.04.2026, 08:18
RE: scripting knx - by ALEJANDRO - 13.04.2026, 13:17
RE: scripting knx - by Daniel - 13.04.2026, 13:19
RE: scripting knx - by ALEJANDRO - 13.04.2026, 13:20
RE: scripting knx - by Daniel - 13.04.2026, 13:28
RE: scripting knx - by ALEJANDRO - 13.04.2026, 13:32
RE: scripting knx - by admin - 14.04.2026, 06:33
RE: scripting knx - by ALEJANDRO - Yesterday, 07:51
RE: scripting knx - by admin - Yesterday, 08:15

Forum Jump: