![]() |
|
scripting knx - Printable Version +- LogicMachine Forum (https://forum.logicmachine.net) +-- Forum: LogicMachine eco-system (https://forum.logicmachine.net/forumdisplay.php?fid=1) +--- Forum: Scripting (https://forum.logicmachine.net/forumdisplay.php?fid=8) +--- Thread: scripting knx (/showthread.php?tid=6381) |
scripting knx - ALEJANDRO - 08.04.2026 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: -- 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. RE: scripting knx - admin - 08.04.2026 What script type are you using? The correct approach is to use a scheduled script that runs every 5 minutes and remove the while loop and os.sleep at the end. What is the data type of rented status object. Is it boolean or 1 byte? |