29.05.2023, 11:23
Is this the right way?
Code:
local inputgroup = {}
local groupobjects = {}
function readAndSetTemperature(group, j)
local base = group .. '/'
local readAddress = base .. '0/15'
local setAddress = base .. '4/' .. j
local temperature = grp.getvalue(readAddress)
if temperature ~= nil then
grp.checkwrite(setAddress, temperature)
end
end
client = require('localbus').new(0.1)
client:sethandler('groupwrite', function(event)
local addr = event.dst
local group = inputgroup[addr]
if group then
local value = grp.getvalue(addr)
groupobjects[group][addr] = value
local controlCheck = group .. '/0/11'
local controlValue = grp.getvalue(controlCheck)
local zeroCheck = group .. '/0/13'
local zeroValue = grp.getvalue(zeroCheck)
if zeroValue == false or controlValue == true then
for j = 17, 117, 10 do
local addr = group .. '/4/' .. j
grp.checkwrite(addr, 0)
end
else
for j = 17, 117, 10 do
readAndSetTemperature(group, j)
end
end
end
end)
for i = 0, 60 do
local group = i
groupobjects[group] = {}
for j = 13, 113, 10 do
local addr = group .. '/4/' .. j
local value = grp.getvalue(addr)
if value ~= nil then
inputgroup[addr] = group
groupobjects[group][addr] = value
end
end
end
while true do
client:loop(1)
end