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
#8
Yes, it is. But you need to remove the while loop from the code for it to works correctly. Check the Logs tabs, you will see 5 minutes between logs from this script.
Code:
local estados = {} for i = 1, 27 do     estados[i] = '2/0/' .. (175 + i)  -- 176 → 202 end -- Direcciones de temperatura individuales local direcciones_temp = {     '0/0/11','0/0/27','0/0/43','0/0/59','0/0/75','0/0/91','0/0/107',     '0/0/123','0/0/139','0/0/155','0/0/171','0/0/187','0/0/203',     '0/0/219','0/0/235','0/0/251',     '0/1/11','0/1/27','0/1/43','0/1/59','0/1/75','0/1/91','0/1/107',     '0/1/123','0/1/139','0/1/155','0/1/171' } -- Dirección donde guardar la temperatura media local destino1 = '2/0/164' -- Rango válido de temperaturas local min_temp = -20 local max_temp = 60 -- ============================================================ -- BUCLE PRINCIPAL (TU MISMO CÓDIGO, REPITIÉNDOSE PARA SIEMPRE) -- ============================================================ local suma = 0 local contador = 0 -- Recorrer las 27 viviendas for i = 1, 27 do     local estado = grp.getvalue(estados[i])     local valor = grp.getvalue(direcciones_temp[i])     -- Solo usar temperatura si la vivienda está alquilada     if estado == 1 then         if valor ~= nil and type(valor) == "number" then             if valor >= min_temp and valor <= max_temp then                 suma = suma + valor                 contador = contador + 1             else                 log("Temperatura fuera de rango en " .. direcciones_temp[i] .. ": " .. tostring(valor))             end         else             log("Valor de temperatura inválido o nulo en " .. direcciones_temp[i])         end     end end -- Guardar la media si hay datos válidos if contador > 0 then     local media = suma / contador     grp.write(destino1, media)     log("Temperatura media (solo alquilados) actualizada en " .. destino1 .. ": " .. media) else     log("No hay viviendas alquiladas con temperatura válida para calcular la media") end
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 - 17.04.2026, 07:51
RE: scripting knx - by admin - 17.04.2026, 08:15
RE: scripting knx - by ALEJANDRO - 21.04.2026, 13:31
RE: scripting knx - by ALEJANDRO - 04.05.2026, 06:20
RE: scripting knx - by admin - 04.05.2026, 07:40
RE: scripting knx - by ALEJANDRO - 04.05.2026, 09:07
RE: scripting knx - by admin - 04.05.2026, 13:32

Forum Jump: