Time
Overview
XKNX provides the possibility to send the local time, date or both combined to the KNX bus in regular intervals. This can be used to display the time within KNX touch sensors or for KNX automation schemes programmed with the ETS.
Example
time_device = DateTime(
xknx, 'TimeTest',
group_address='1/2/3',
broadcast_type='TIME',
localtime=True
)
# `sync()` doesn't send a GroupValueRead when localtime is True but sends the current time to KNX bus
await xknx.devices['TimeTest'].sync()
xknxis the XKNX object.nameis the name of the object.group_addressis the KNX group address of the sensor device.broadcast_typedefines the value type that will be sent to the KNX bus. Valid attributes are: ‘time’, ‘date’ and ‘datetime’. Default:timelocaltimeIf setTruesync() and GroupValueRead requests always return the current local time. OnFalsethe set value will be sent. Default:Truedevice_updated_cbawaitable callback for each update.
Configuration via xknx.yaml
Time objects are usually configured via xknx.yaml:
groups:
time:
General.Time: {group_address: '2/1/2'}
Daemon mode
When XKNX is started in daemon mode, with START_STATE_UPDATER enabled, XKNX will automatically send the time to the KNX bus with the sync_state-loop.
import asyncio
from xknx import XKNX
from xknx.devices import DateTime
async def main():
async with XKNX(daemon_mode=True) as xknx:
time = DateTime(xknx, 'TimeTest', group_address='1/2/3')
print("Sending time to KNX bus every hour")
asyncio.run(main())
Interface
from xknx import XKNX
from xknx.devices import DateTime
xknx = XKNX()
time_device = DateTime(xknx, 'TimeTest', group_address='1/2/3', broadcast_type='time')
await xknx.start()
# Sending Time to KNX bus
await time_device.broadcast_localtime()