File: example_sensor.py

package info (click to toggle)
python-xknx 3.6.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 4,012 kB
  • sloc: python: 39,710; javascript: 8,556; makefile: 27; sh: 12
file content (37 lines) | stat: -rw-r--r-- 875 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
"""Example for Sensor device. See docs/sensor.md and docs/binary_sensor.md for a detailed explanation."""

import asyncio

from xknx import XKNX
from xknx.devices import BinarySensor, Sensor


async def main() -> None:
    """Connect to KNX/IP device and read the value of a temperature and a motion sensor."""
    xknx = XKNX()
    await xknx.start()

    sensor1 = BinarySensor(
        xknx,
        "DiningRoom.Motion.Sensor",
        group_address_state="6/0/2",
    )
    xknx.devices.async_add(sensor1)
    await sensor1.sync(wait_for_result=True)
    print(sensor1)

    sensor2 = Sensor(
        xknx,
        "DiningRoom.Temperature.Sensor",
        group_address_state="6/2/1",
        value_type="temperature",
    )
    xknx.devices.async_add(sensor2)

    await sensor2.sync(wait_for_result=True)
    print(sensor2)

    await xknx.stop()


asyncio.run(main())