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.2.0.tar.gz (9.3 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.2.0-py3-none-any.whl (8.7 kB view details)

Uploaded Python 3

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

Hashes for switchbotble-0.2.0.tar.gz
Algorithm Hash digest
SHA256 cd48a4019a6338fa4489d1111500642cf281ddfb930cfd9fe4c80e6da7715fdd
MD5 48ef820c0172d45dd69833f5d79b608a
BLAKE2b-256 e33c6c3e67def642c5cd542805409f08d01c9464113712852deb490d89a4b3b8

See more details on using hashes here.

Provenance

The following attestation bundles were made for switchbotble-0.2.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.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

Hashes for switchbotble-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 dc5720b284e3da119a502d38af659657011e2f4806551a9687dbefbc49d16af4
MD5 bb040ac1f34bbed1a300c74668eb3360
BLAKE2b-256 61ba2039cd7943bb9e02ee002a62234de98158fac30e416a187e4ca7a2689793

See more details on using hashes here.

Provenance

The following attestation bundles were made for switchbotble-0.2.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