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.

Processing KNX Addresses
#9
I generally don't understand something. I tried using the advice you gave me, but apparently I'm not using them correctly.
Code:
local inputgroup = {}
local groupobjects = {}

for i = 1, 60 do
  groupobjects[i] = {}

  for j = 11, 241, 10 do
    local addr = i .. "/2/" .. j
    local status, value = pcall(grp.getvalue, addr)

    if status and value ~= nil then
      inputgroup[addr] = i
      groupobjects[i][addr] = value
    end
  end
end

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)

  local controlAddress = group .. '/2/0'
  local isControlEnabled = grp.getvalue(controlAddress)

  if isControlEnabled and isControlEnabled ~= nil then
    local changeState = not groupon

    for i = 11, 161, 10 do
      local address3 = group .. '/3/' .. i
      local address5 = group .. '/5/' .. (i + 7)

      if pcall(grp.getvalue, address3) then
        grp.checkwrite(address3, changeState)
      end

      if pcall(grp.getvalue, address5) then
        grp.checkwrite(address5, changeState)
      end
    end
  end
end


local function onStateChange(event)
  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
end


client = require('localbus').new(0.1)

if event then
  for group = 1, 60 do
    for device = 11, 161, 10 do
      local address = group .. '/2/' .. device
      if pcall(grp.getvalue, address) then
        event.register(address, onStateChange, 'groupwrite')
      end
    end
  end
else
  log('event not available')
end

while true do
  client:loop(1)
end
Reply


Messages In This Thread
Processing KNX Addresses - by AISystem - 10.05.2023, 07:13
RE: Processing KNX Addresses - by admin - 10.05.2023, 07:30
RE: Processing KNX Addresses - by AISystem - 10.05.2023, 08:24
RE: Processing KNX Addresses - by admin - 10.05.2023, 08:49
RE: Processing KNX Addresses - by AISystem - 10.05.2023, 11:50
RE: Processing KNX Addresses - by admin - 10.05.2023, 11:51
RE: Processing KNX Addresses - by AISystem - 10.05.2023, 12:05
RE: Processing KNX Addresses - by admin - 10.05.2023, 12:33
RE: Processing KNX Addresses - by AISystem - 10.05.2023, 14:21
RE: Processing KNX Addresses - by admin - 11.05.2023, 05:59
RE: Processing KNX Addresses - by AISystem - 11.05.2023, 07:28
RE: Processing KNX Addresses - by admin - 11.05.2023, 12:18
RE: Processing KNX Addresses - by AISystem - 22.05.2023, 11:29
RE: Processing KNX Addresses - by admin - 22.05.2023, 12:01
RE: Processing KNX Addresses - by AISystem - 25.05.2023, 07:14
RE: Processing KNX Addresses - by AISystem - 29.05.2023, 08:55
RE: Processing KNX Addresses - by admin - 29.05.2023, 09:41
RE: Processing KNX Addresses - by AISystem - 29.05.2023, 10:33
RE: Processing KNX Addresses - by admin - 29.05.2023, 10:58
RE: Processing KNX Addresses - by AISystem - 29.05.2023, 11:23
RE: Processing KNX Addresses - by admin - 29.05.2023, 11:48

Forum Jump: