Skip to main content

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())

Metadata

Release files for switchbotble 0.3.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for switchbotble 0.3.0
File Size Uploaded
switchbotble-0.3.0.tar.gz 10.1 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for switchbotble 0.3.0
File Interpreter ABI Platform
switchbotble-0.3.0-py3-none-any.whl Python 3 none any Details

Total release size: 21.4 kB

Release files / switchbotble-0.3.0.tar.gz

Download URL switchbotble-0.3.0.tar.gz
Size 10.1 kB
Tags Source
SHA-256 checksum
How to use checksums
e10db5b71f00fcda45ac0ecb6bf4c1575b599c48d4047ef3af4232150c04ca84
BLAKE2b-256 checksum
How to use checksums
3e7a5ef9cf50b5c5d8b80116a83de652b2da8ebd85334c6da751a3d1ad09c866
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.12.9

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.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Mar 9, 2025.

Transparency log

Release files / switchbotble-0.3.0-py3-none-any.whl

Download URL switchbotble-0.3.0-py3-none-any.whl
Size 11.3 kB
Tags Python 3
SHA-256 checksum
How to use checksums
ae93b358b40e9047782f59625d11e662255c0c4c29988aa65764775d28a39d76
BLAKE2b-256 checksum
How to use checksums
d472f8e022b6b758a21be1306301dcad2815fa94b90943b66eddb2cfe34b6779
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.12.9

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.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Mar 9, 2025.

Transparency log

Release history Release notifications | RSS feed

This release

0.3.0 This release

2 release files

0.2.0

2 release files

0.1.3

1 release file

0.1.2

3 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page