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
#3
This would lead to the possibility of many errors, can't it be done with a resident script that monitors states and processes events? I tried to write something similar, but apparently I don't understand the system's workings very well and it doesn't work for me.
Code:
local function object_exists(obj_address)
  local obj = grp.find(obj_address)
  return obj ~= nil
end

-- table with the addresses of function_one
local function_one = {}
for i = 1, 60 do
  for j = 11, 241, 10 do
    local function_one_address = i .. "/2/" .. j
    if object_exists(function_one_address) then
      function_one[(i - 1) * 24 + (j - 11) / 10 + 1] = function_one_address
    end
  end
end

-- table with the addresses of group_numbers
local group_numbers = {}
for i = 1, 60 do
  for j = 11, 241, 10 do
    local group_numbers_address = i .. "/3/" .. j
    if object_exists(group_numbers_address) then
      group_numbers[(i - 1) * 24 + (j - 11) / 10 + 1] = group_numbers_address
    end
  end
end

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

local function update_group_numbers_for_group(group_number)
  local has_true_function_one = false
  for j, function_one_item in ipairs(function_one) do
    if tonumber(function_one_item:match("(%d+)/2/%d+")) == group_number then
      if grp.getvalue(function_one_item) == 1 then
        has_true_function_one = true
        break
      end
    end
  end

  for j, group_number_item in ipairs(group_numbers) do
    if tonumber(group_number_item:match("(%d+)/3/%d+")) == group_number then
      local current_group_number_state = grp.getvalue(group_number_item)
      if has_true_function_one and current_group_number_state == 1 then
        grp.write(group_number_item, 0)
      elseif not has_true_function_one and current_group_number_state == 0 then
        grp.write(group_number_item, 1)
      end
    end
  end
end

-- set function to handle events from group addresses
client:sethandler('groupwrite', function(event)
  local address = event.dst
  local value = tonumber(event.datahex, 16) or 0

  -- check if the address is in the list of function_one addresses
  for i, function_one_item in ipairs(function_one) do
    if address == function_one_item then
      local group_number = tonumber(function_one_item:match("(%d+)/2/%d+"))
      update_group_numbers_for_group(group_number)
      break
    end
  end
end)

-- start the client for data exchange on the local bus
client:loop(1)
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: