Asynchronous Python Library for KNX
XKNX is an Asynchronous Python library for reading and writing KNX/IP packets.
Overview
XKNX…
- … does cooperative multitasking via asyncio and is 100% thread safe.
- … provides support for KNX/IP routing and tunneling devices.
- … supports KNX IP Secure - via tunneling or routing.
- … supports KNX Data Secure group communication.
- … has strong coverage with unit tests.
- … automatically updates and synchronizes all devices in the background periodically.
- … listens for all updates of all devices on the KNX bus and updates the corresponding internal objects.
- … has a clear abstraction of data/network/logic-layer.
- … does clean connect and disconnect requests to the tunneling device and reconnects if KNX/IP connection failed.
- … ships with Home Assistant.
Installation
XKNX depends on Python >= 3.10
You can install XKNX as Python package via pip:
pip install xknx
Hello World
import asyncio
from xknx import XKNX
from xknx.tools import group_value_write
async def main():
async with XKNX() as xknx:
# send a binary Telegram
group_value_write(xknx, "1/2/3", True)
# send a generic 1-byte Telegram
group_value_write(xknx, "1/2/4", [0x80])
# send a Telegram with an encoded value
group_value_write(xknx, "1/2/4", 50, value_type="percent")
asyncio.run(main())
For more examples please check out the examples page
Getting Help
For questions, feature requests, bugreports either join the XKNX chat on Discord, open an issue at GitHub or write an email.
Attributions
Many thanks to MDT technologies GmbH and Weinzierl Engineering GmbH for providing us each an IP Secure Router to support testing and development of xknx.