04.07.2022, 07:24
Do you mean that there are two objects - heat/cool and on/off status? In this case two tags are needed - central_onoff for on/off status objects and central_state for heat/cool status. Objects must be assigned in a way that they follow the same group address order for both objects. For example 1/1/1 and 1/2/1 - device A, 1/1/2 and 1/2/2 - device B and so on. Gaps between group addresses is ok.
Code:
function tag_status(onoff_tag, state_tag)
local function sorter(a, b)
return a.id < b.id
end
local result = false
local onoff_objs = grp.tag(onoff_tag)
local state_objs = grp.tag(state_tag)
table.sort(onoff_objs, sorter)
table.sort(state_objs, sorter)
local onoff_count = 0
local state_count = 0
for i, onoff_obj in ipairs(onoff_objs) do
if onoff_obj.data then
onoff_count = onoff_count + 1
local state_obj = state_objs[ i ]
if state_obj.data then
state_count = state_count + 1
end
end
end
return state_count > math.floor(onoff_count / 2)
end
res = tag_status('central_onoff', 'central_state')
grp.checkupdate('1/1/1', res)