This forum uses cookies
This forum makes use of cookies to store your login information if you are registered, and your last visit if you are not. Cookies are small text documents stored on your computer; the cookies set by this forum can only be used on this website and pose no security risk. Cookies on this forum also track the specific topics you have read and when you last read them. Please confirm that you accept these cookies being set.

Cool Heat Changeover
#1
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 :-)
Reply
#2
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:
12345678910111213141516171819
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)
Reply
#3
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.
Reply
#4
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:
1234567891011121314151617181920212223242526272829303132
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)
Reply


Forum Jump: