Example: DALI lamp status on KNX bus through LogicMachine

Task

The DALI bus is a fieldbus which is designed to control DALI objects from one location. In case DALI sensors or switches are used, you might need to see the current light level of DALI ballast. In this case, additionally to DALI to KNX mapper, you have to add a resident script which will communicate with a specific DALI ballast, retrieve the current light level and write it into KNX group address (DALI ballast status object).

Resident script

Add the following script. It will connect to DALI ballast with address 0 and write its status into grp address 5/0/1. Do not use the same object for control and status as it might create an endless loop.

Source code    
  1. require('user.dali')
  2. res = dalicmd('internal', 'queryactual', { addrtype = 'short', address = 0 })
  3.  
  4. if res then
  5. curr = res:byte()
  6. if curr ~= prev then
  7. grp.update('5/0/3', math.floor(curr / 2.54))
  8. prev = curr
  9. end
  10. end