Skip to main content

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

switchbotble-0.3.0.tar.gz (10.1 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

switchbotble-0.3.0-py3-none-any.whl (11.3 kB view details)

Uploaded Python 3

File details

Details for the file switchbotble-0.3.0.tar.gz.

File metadata

  • Download URL: switchbotble-0.3.0.tar.gz
  • Upload date:
  • Size: 10.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for switchbotble-0.3.0.tar.gz
Algorithm Hash digest
SHA256 e10db5b71f00fcda45ac0ecb6bf4c1575b599c48d4047ef3af4232150c04ca84
MD5 51d997be1eb63339d842572d939ffa8a
BLAKE2b-256 3e7a5ef9cf50b5c5d8b80116a83de652b2da8ebd85334c6da751a3d1ad09c866

See more details on using hashes here.

Provenance

The following attestation bundles were made for switchbotble-0.3.0.tar.gz:

Publisher: deploy.yml on hnw/switchbotble

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file switchbotble-0.3.0-py3-none-any.whl.

File metadata

  • Download URL: switchbotble-0.3.0-py3-none-any.whl
  • Upload date:
  • Size: 11.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for switchbotble-0.3.0-py3-none-any.whl
Algorithm Hash digest
SHA256 ae93b358b40e9047782f59625d11e662255c0c4c29988aa65764775d28a39d76
MD5 1fa414cd29d495818b79b7fd7c372ebb
BLAKE2b-256 d472f8e022b6b758a21be1306301dcad2815fa94b90943b66eddb2cfe34b6779

See more details on using hashes here.

Provenance

The following attestation bundles were made for switchbotble-0.3.0-py3-none-any.whl:

Publisher: deploy.yml on hnw/switchbotble

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page