![]() |
|
Cool Heat Changeover - 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: Cool Heat Changeover (/showthread.php?tid=4123) |
Cool Heat Changeover - KoBra - 30.06.2022 Has anyone already built a script before that can act as a comparitor to see if multiple zones are on cooling, heating or off and to get an output of the mode where the most units are in? If not i have to start making something myself :-) RE: Cool Heat Changeover - admin - 30.06.2022 Assign a common tag to all zone status objects. Map an event script to this tag. It will write true when more than half of tagged objects are true, false otherwise. Make sure that the status output object is not mapped to the same tag. Code: function tag_status(tag)
local result, objects, count, halfcount
result = false
objects = grp.tag(tag)
count = 0
halfcount = math.floor(#objects / 2)
for _, object in ipairs(objects) do
if object.data then
count = count + 1
end
end
return count > halfcount
end
res = tag_status('central')
grp.checkupdate('1/1/1', res)RE: Cool Heat Changeover - KoBra - 04.07.2022 ok but what if i have 6 units and 1 is on in cool and 2 are on in heat? than i need heat output. RE: Cool Heat Changeover - admin - 04.07.2022 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) |