Send date/time to KNX

Send date/time to KNX #

Task #

Send date and time from LogicMachine to KNX group addresses 1/1/1 and 1/1/2 respectively.

Resident script #

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

-- get current date as table
now ='*t')

-- write to bus
grp.write('1/1/1', now,
grp.write('1/1/2', now, dt.time)

Updated script to handle KNX 19.001 datatype #

-- get current data as table
now ='*t')

-- system week day starts from sunday, convert it to knx format
wday = now.wday == 1 and 7 or now.wday - 1

--- full date bits
OCT08 = now.year - 1900
OCT07 = now.month
OCT06 =
OCT05 = bit.bor(bit.lshift(wday, 5), now.hour)
OCT04 = now.min
OCT03 = now.sec
OCT02 = 0 -- subfields like working day and dst not specified in this sample
OCT01 = 0 -- subfields like quality of clock not specified in this sample

-- write to bus
date_time = string.char(OCT08, OCT07, OCT06, OCT05, OCT04, OCT03, OCT02, OCT01)
grp.write('1/1/3', date_time)