-
-
Notifications
You must be signed in to change notification settings - Fork 109
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add example for controlling a fan with step mode
- Loading branch information
Showing
1 changed file
with
33 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
"""Example for Fan device.""" | ||
import asyncio | ||
from xknx import XKNX | ||
from xknx.devices import Fan, FanSpeedMode | ||
|
||
async def main(): | ||
"""Connect to KNX/IP bus, control a fan, and turn it off afterwards.""" | ||
xknx = XKNX() | ||
await xknx.start() | ||
|
||
fan = Fan( | ||
xknx, | ||
name="TestFan", | ||
group_address_switch="1/0/12", | ||
group_address_speed="1/0/14", | ||
max_step=3, | ||
) | ||
|
||
# Turn on the fan | ||
await fan.turn_on() | ||
|
||
# Set fan speed in steps | ||
for step in range(1, fan.max_step + 1): | ||
await fan.set_speed(step) | ||
await asyncio.sleep(1) | ||
|
||
# Turn off the fan | ||
await fan.turn_off() | ||
|
||
await xknx.stop() | ||
|
||
asyncio.run(main()) | ||
|