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
#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:
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


Messages In This Thread
Cool Heat Changeover - by KoBra - 30.06.2022, 09:49
RE: Cool Heat Changeover - by admin - 30.06.2022, 10:25
RE: Cool Heat Changeover - by KoBra - 04.07.2022, 06:45
RE: Cool Heat Changeover - by admin - 04.07.2022, 07:24

Forum Jump: