A Python library to control SwitchBot devices connected to SwitchBot Hub
Project description
python-switchbot
A Python library to control SwitchBot devices connected to SwitchBot Hub
Requirements
- Python 3.8+
- A SwitchBot Token
Installation
pip install python-switchbot
Usage
Devices
from switchbot import SwitchBot
# To get the token, please refer to https://github.com/OpenWonderLabs/SwitchBotAPI#getting-started
your_switch_bot_token = '98a6732b2ac256d40ffab7db31a82f518969f4d1a64eadff581d45e902327b7c577aa6ead517bda589c19b4ca0b2599b'
switchbot = SwitchBot(token=your_switch_bot_token)
# To list all devices
devices = switchbot.devices()
for device in devices:
print(device)
# Bot(id=CD0A18B1C291)
# HubMini(id=4CAF08629A21)
# Bot(id=5F0B798AEF91)
# If you already know a device id:
device = switchbot.device(id='5F0B798AEF91')
# Device(id=5F0B798AEF91)
# To query a status of a device
print(device.status())
# {'power': 'off'}
# To command actions,
device.command('turn_on')
device.command('turn_off')
device.command('press')
device.command('set_position', parameter='0,ff,80')
# For some device types like Bot:
bot = devices[0]
bot.turn('on')
bot.turn('off')
bot.toggle()
bot.press()
Remotes
# To list all infra red remotes
remotes = switchbot.remotes()
for remote in remotes:
print(remote)
# If you already know a remote id:
remote = switchbot.remote(id='')
# Supported devices such as fans, air purifiers:
remote.turn('on')
remote.turn('off')
# To send supported commands,
remote.command('swing')
remote.command('low_speed')
# To send custom commands,
remote.command('MyCustomCommand', customize=True)
Contributors
Thanks to all contributors!
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file python-switchbot-2.1.0.tar.gz.
File metadata
- Download URL: python-switchbot-2.1.0.tar.gz
- Upload date:
- Size: 4.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.0 CPython/3.9.10
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
7a41d9a8634724adbca31888ed07a69f91434fd362bfaff291989de1acf9136f
|
|
| MD5 |
af343b817d375abba0f541e7bed9b4c7
|
|
| BLAKE2b-256 |
50dd4197dcde93688743ca54f753f5749ddad5d6311edcfacae6f491c1450d52
|
File details
Details for the file python_switchbot-2.1.0-py3-none-any.whl.
File metadata
- Download URL: python_switchbot-2.1.0-py3-none-any.whl
- Upload date:
- Size: 6.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.1 CPython/3.9.13
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
02c5768eb439a4eceb53654c4d66c91c2c6b49cb8e01f86ca2c1dbb429797506
|
|
| MD5 |
55192789046b500f48eb5342644c7add
|
|
| BLAKE2b-256 |
fe5745d2f30f704c3a635d02d3ff0eea31f511b2e950faea9dd10862ffb7bdd5
|