An event-driven SwitchBot sensor library using BLE
Project description
Switchbotble is an event-driven SwitchBot sensor library using BLE written in Python.
Installation
$ pip install switchbotble
Features
- Scans all nearby SwitchBot devices with BLE, and publishes events if the sensor value changed.
- Supports BLE on Windows 10, Linux, OS X/macOS (provided by BLE library Bleak)
- Supporting Switchbot sensors:
- Contact sensor
- Motion sensor
- Supporting sensor events:
- Movement detection (Contact sensor, Motion sensor)
- Light detection (Contact sensor, Motion sensor)
- Door open/close detection (Contact sensor)
- Button press detection (Contact sensor)
Usage
import subprocess
import platform
import asyncio
from switchbotble import SwitchBotBLE, motion, no_motion, closed
# uses 48bit MAC address on Windows/Linux
kitchen = '00:00:5E:00:53:C7' # Mac Address for motion sensor
bedroom = '00:00:5E:00:53:22' # Mac Address for contact sensor
if platform.system() == "Darwin":
# uses 128bit UUID on MacOS
kitchen = 'ECFAB3FC-FAE2-11EC-A7F7-00005E0053C7'
bedroom = 'ECFAB3FC-FAE2-11EC-A7F7-00005E005322'
@motion.connect_via(kitchen)
def kitchen_on(address, **kwargs):
subprocess.Popen(['google', 'Turn on all lights in kitchen'])
@no_motion.connect_via(kitchen)
def kitchen_off(address, **kwargs):
subprocess.Popen(['google', 'Turn off all lights in kitchen'])
@closed.connect_via(bedroom)
def all_off(address, **kwargs):
subprocess.Popen(['google', 'Turn off all devices'])
async def main():
ble = SwitchBotBLE(motion_timeout = 180)
while True:
await ble.start()
await asyncio.sleep(2.0)
await ble.stop()
asyncio.run(main())
Project details
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 switchbotble-0.2.0.tar.gz.
File metadata
- Download URL: switchbotble-0.2.0.tar.gz
- Upload date:
- Size: 9.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
cd48a4019a6338fa4489d1111500642cf281ddfb930cfd9fe4c80e6da7715fdd
|
|
| MD5 |
48ef820c0172d45dd69833f5d79b608a
|
|
| BLAKE2b-256 |
e33c6c3e67def642c5cd542805409f08d01c9464113712852deb490d89a4b3b8
|
Provenance
The following attestation bundles were made for switchbotble-0.2.0.tar.gz:
Publisher:
deploy.yml on hnw/switchbotble
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
switchbotble-0.2.0.tar.gz -
Subject digest:
cd48a4019a6338fa4489d1111500642cf281ddfb930cfd9fe4c80e6da7715fdd - Sigstore transparency entry: 179075883
- Sigstore integration time:
-
Permalink:
hnw/switchbotble@2e8572e4a387a11b2abc4ca12b69d73adbdcb7b7 -
Branch / Tag:
refs/tags/v0.2.0 - Owner: https://github.com/hnw
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
deploy.yml@2e8572e4a387a11b2abc4ca12b69d73adbdcb7b7 -
Trigger Event:
push
-
Statement type:
File details
Details for the file switchbotble-0.2.0-py3-none-any.whl.
File metadata
- Download URL: switchbotble-0.2.0-py3-none-any.whl
- Upload date:
- Size: 8.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
dc5720b284e3da119a502d38af659657011e2f4806551a9687dbefbc49d16af4
|
|
| MD5 |
bb040ac1f34bbed1a300c74668eb3360
|
|
| BLAKE2b-256 |
61ba2039cd7943bb9e02ee002a62234de98158fac30e416a187e4ca7a2689793
|
Provenance
The following attestation bundles were made for switchbotble-0.2.0-py3-none-any.whl:
Publisher:
deploy.yml on hnw/switchbotble
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
switchbotble-0.2.0-py3-none-any.whl -
Subject digest:
dc5720b284e3da119a502d38af659657011e2f4806551a9687dbefbc49d16af4 - Sigstore transparency entry: 179075884
- Sigstore integration time:
-
Permalink:
hnw/switchbotble@2e8572e4a387a11b2abc4ca12b69d73adbdcb7b7 -
Branch / Tag:
refs/tags/v0.2.0 - Owner: https://github.com/hnw
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
deploy.yml@2e8572e4a387a11b2abc4ca12b69d73adbdcb7b7 -
Trigger Event:
push
-
Statement type: