10.05.2023, 12:33
Use this as a starting point and fill in the blanks
1. inputgroup maps group address to group id. groupobjects contains group address to value map for each group id. If object is not found then it won't be added.
2. In groupwrite handler check if destination group address belongs to a certain group id. If so then new value is cached and updategroup is called.
3. updategroup checks if there's at least one group address in the group that is on (true). Place this function before the groupwrite handler.
For outputs you can simply use grp.checkwrite to prevent sending the same values.
1. inputgroup maps group address to group id. groupobjects contains group address to value map for each group id. If object is not found then it won't be added.
Code:
local inputgroup = {}
local groupobjects = {}
for i = 1, 60 do
groupobjects[ i ] = {}
for j = 11, 241, 10 do
local addr = i .. "/2/" .. j
local value = grp.getvalue(addr)
if value ~= nil then
inputgroup[ addr ] = i
groupobjects[ i ][ addr ] = value
end
end
end
2. In groupwrite handler check if destination group address belongs to a certain group id. If so then new value is cached and updategroup is called.
Code:
local addr = event.dst
local group = inputgroup[ addr ]
if group then
local value = tonumber(event.datahex, 16) ~= 0
groupobjects[ group ][ addr ] = value
updategroup(group)
end
3. updategroup checks if there's at least one group address in the group that is on (true). Place this function before the groupwrite handler.
Code:
local function updategroup(group)
local objects = groupobjects[ group ]
local groupon = false
for addr, value in pairs(objects) do
if value then
groupon = true
break
end
end
log(groupon)
end
For outputs you can simply use grp.checkwrite to prevent sending the same values.