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, 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 for Windows/Linux
kitchen = '00:00:5E:00:53:C7'
bedroom = '00:00:5E:00:53:22'
if platform.system() == "Darwin":
    # uses 128bit UUID for MacOS
    kitchen = '01234567-89AB-CDEF-0123-456789ABCDC7'
    bedroom = '01234567-89AB-CDEF-0123-456789ABCD22'

@motion.connect_via(kitchen)
def kitchen_on(address, **kwargs):
    subprocess.Popen(['google', 'Turn on devices in kitchen'])

@no_motion.connect_via(kitchen)
def kitchen_off(address, **kwargs):
    subprocess.Popen(['google', 'Turn off devices 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.1.2.tar.gz (7.7 kB view details)

Uploaded Source

Built Distributions

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

switchbotble-0.1.2-py3-none-any.whl (7.6 kB view details)

Uploaded Python 3

switchbotble-0.1.2-py2.py3-none-any.whl (7.6 kB view details)

Uploaded Python 2Python 3

File details

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

File metadata

  • Download URL: switchbotble-0.1.2.tar.gz
  • Upload date:
  • Size: 7.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.9.9

File hashes

Hashes for switchbotble-0.1.2.tar.gz
Algorithm Hash digest
SHA256 b4608309381ae564b07d06d3d2aca3ae16d12cf7af6d75158ce73d159b6db06b
MD5 2cfdd29854c25eea9d929e941cb9ceef
BLAKE2b-256 b099d97b1c521a89b90b37bc9cb5ab95535e0b03e4e45498706331e9cf3a6875

See more details on using hashes here.

File details

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

File metadata

  • Download URL: switchbotble-0.1.2-py3-none-any.whl
  • Upload date:
  • Size: 7.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.9.9

File hashes

Hashes for switchbotble-0.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 c13f7a66aa27afb66e6c4b287871da60990bc22ec0e5cabb9c7906c5d05a54ab
MD5 0eebb2f462513bb485c0dca39c209a1c
BLAKE2b-256 e071af83e177613f919583829ff1d4b40832860d8c72458525e5d9c9ca9a9733

See more details on using hashes here.

File details

Details for the file switchbotble-0.1.2-py2.py3-none-any.whl.

File metadata

  • Download URL: switchbotble-0.1.2-py2.py3-none-any.whl
  • Upload date:
  • Size: 7.6 kB
  • Tags: Python 2, Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.9.9

File hashes

Hashes for switchbotble-0.1.2-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 b8f1767c2352fa067832f8037c0e74b435ebbd885bcce5a03dde0216a34daa5d
MD5 5e588046dfa07e396c623a4f66a4bbd0
BLAKE2b-256 3169f55e358f442e430f446637a8bacee0398b0b165531d1ee53fcd86e2f245a

See more details on using hashes here.

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