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
#1
Good morning,

I'm having a problem with the functions and I don't know how to solve it.

Here's the problem:

I currently have three logic machines taking KNX data from temperature, humidity, and CO2 sensors. I need them to calculate the average temperature, CO2, and humidity. But I only want to calculate this for the sensors located in rented properties.

I have the following variables.


Rented or non-rented status of 27 dwellings in group addresses from 2/0/176 to 2/0/202:

- Rented = 1

- Non-rented = 0
Temperature values delivered by each dwelling sensor:

'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'

Variable where the average building temperature will be stored:

2/0/164

And now I'll show you the code I wrote:

Code:
-- Direcciones de estado de las 27 viviendas (0=libre, 1=alquilada, 2=mantenimiento, 3=ocupada) 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 -- Intervalo de espera: 5 minutos (300 segundos) local INTERVALO = 300 -- ============================================================ -- BUCLE PRINCIPAL (TU MISMO CÓDIGO, REPITIÉNDOSE PARA SIEMPRE) -- ============================================================ while true do     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     -- Esperar 5 minutos antes de repetir     os.sleep(INTERVALO) end

Lo he intentado por todos los medios posibles y no me  calcula la temperatura media y cuando lo hace satura la memoria de la logic machine.
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: