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'
bedroom = '00:00:5E:00:53:22'
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
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 Distributions
No source distribution files available for this release.See tutorial on generating distribution archives.
Built Distribution
Close
Hashes for switchbotble-0.1.3-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | c075d6234853e14121ddc7495f373652f33405b1f36cd2e36b462fcc42e760b5 |
|
MD5 | d26e2a5cdcefd5d47893955e27b4c02b |
|
BLAKE2b-256 | e3bb30ac32786feb3d38a1e4e6172f65b7bb9cc77535a305c78ea0d190a53af2 |