File: example_light_dimm.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 (31 lines) | stat: -rw-r--r-- 651 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
"""Example for switching a light on and off."""

import asyncio

from xknx import XKNX
from xknx.devices import Light


async def main() -> None:
    """Connect to KNX/IP bus, slowly dimm on light, set it off again afterwards."""
    xknx = XKNX()
    await xknx.start()

    light = Light(
        xknx,
        name="TestLight2",
        group_address_switch="1/0/12",
        group_address_brightness="1/0/14",
    )
    xknx.devices.async_add(light)

    for i in [0, 31, 63, 95, 127, 159, 191, 223, 255]:
        await light.set_brightness(i)
        await asyncio.sleep(1)

    await light.set_off()

    await xknx.stop()


asyncio.run(main())