python-switchbot
A Python library to control SwitchBot devices connected to SwitchBot Hub
Requirements
- Python 3.7+
- A SwitchBot Token
Installation
pip install python-switchbot
Usage
Devices
from switchbot import SwitchBot
# To get the token and secret, please refer to https://github.com/OpenWonderLabs/SwitchBotAPI#getting-started
your_switch_bot_token = '98a6732b2ac256d40ffab7db31a82f518969f4d1a64eadff581d45e902327b7c577aa6ead517bda589c19b4ca0b2599b'
your_switch_bot_secret = '222cdc22f049d111c5d0071c131b8b77'
switchbot = SwitchBot(token=your_switch_bot_token, secret=your_switch_bot_secret)
# To list all devices
devices = switchbot.devices()
for device in devices:
print(device)
# Bot(id=CD0A18B1C291)
# Lock(id=CD0A1221C291)
# 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()
# For some device types like Lock:
lock = devices[1]
lock.lock()
lock.unlock()
lock.toggle()
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)
Scenes
# To list all infra red remotes
scenes = switchbot.scenes()
for scene in scenes:
print(scene)
# If you already know a remote id:
scene = switchbot.scene(id='')
# To execute scene
scene.execute()
Metadata
Release files for python-switchbot 2.3.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | |
|---|---|---|---|---|
| python-switchbot-2.3.1.tar.gz | 5.4 kB | Without provenance | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| python_switchbot-2.3.1-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 12.3 kB
Release files / python-switchbot-2.3.1.tar.gz
| Download URL | python-switchbot-2.3.1.tar.gz |
|---|---|
| Size | 5.4 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
b9f204df26abf227a5d3aca8e12b7c79ed6e4f58e5e1546ca4188393e85dca35
|
|
BLAKE2b-256 checksum How to use checksums |
894b987b4d6652a0eb4202c4c6c366f2836f8d25e638b58fe8a0ff942b097773
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.2 CPython/3.9.16
|
Release files / python_switchbot-2.3.1-py3-none-any.whl
| Download URL | python_switchbot-2.3.1-py3-none-any.whl |
|---|---|
| Size | 7.0 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
f014817313b8b67d370352f74ac4b4976255051ca4198ea84d3d90d219f39f17
|
|
BLAKE2b-256 checksum How to use checksums |
8ea5a8a1f6fd6eba73bf5ddb3391a554d8831e6e82b2d2eec86de1ca709d3194
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.2 CPython/3.9.16
|
Security for python-switchbot 2.3.1
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.