Example: Write LM2 data/time to KNX group addresses

Task

Send date and time from Logic Machine 2 to KNX group addresses 1/1/1 and 1/1/2 respectively

Resident program

Add the following code in the resident script with specific time interval after which you want to update date and time values on the bus.

Source code    
  1. -- get current data as table
  2. now = os.date('*t')
  3.  
  4. -- system week day starts from sunday, convert it to knx format
  5. wday = now.wday == 1 and 7 or now.wday - 1
  6.  
  7. -- time table
  8. time = {
  9. day = wday,
  10. hour = now.hour,
  11. minute = now.min,
  12. second = now.sec,
  13. }
  14.  
  15. -- date table
  16. date = {
  17. day = now.day,
  18. month = now.month,
  19. year = now.year,
  20. }
  21.  
  22. -- write to bus
  23. grp.write('1/1/2', time, dt.time)
  24. grp.write('1/1/1', date, dt.date)

Updated script to handle KNX 19.001 datatype

Source code    
  1. -- get current data as table
  2. now = os.date('*t')
  3.  
  4. -- system week day starts from sunday, convert it to knx format
  5. wday = now.wday == 1 and 7 or now.wday - 1
  6.  
  7. -- time table
  8. time = {
  9. day = wday,
  10. hour = now.hour,
  11. minute = now.min,
  12. second = now.sec,
  13. }
  14.  
  15. -- date table
  16. date = {
  17. day = now.day,
  18. month = now.month,
  19. year = now.year,
  20. }
  21.  
  22. -- write to bus
  23. --grp.write('1/1/2', time, dt.time)
  24. --grp.write('1/1/1', date, dt.date)
  25.  
  26. myyear = (now.year-1900)
  27. -- source http://www.knx.org/fileadmin/template/documents/downloads_support_menu/KNX_tutor_seminar_page/Advanced_documentation/05_Interworking_E1209.pdf
  28.  
  29. -- byte 6
  30. --F (msb) -- fault
  31. --WD -- workday (requires a calendar..)
  32. --NWD - workday not valid
  33. --NY --no year
  34. --ND -- no day
  35. --NDoW -- no dayof week
  36. --NT - notime
  37. --SUTI (lsb)-- summertime
  38. byte7 = bit.lshift(1,5)
  39.  
  40. if now.isdst then
  41. byte7 = byte7 + 1
  42. end
  43.  
  44. -- byte 7
  45. --CLQ (msb)-- 1 = clock with extern sync
  46. byte8 = bit.lshift(1,7)
  47.  
  48. -- year (1900 = 0, 2155 = 255), month, dayofmonths, dayofweek