Skip to main content

Forked Casambi Bluetooth client library with switch event support, use original if no special need. https://github.com/lkempf/casambi-bt

Project description

PyPI Discord

Casambi Bluetooth Revamped - Python library for Casambi networks

This is a customized fork of the original casambi-bt library with additional features and should only be used for special needs:

  • Switch event support - Receive button press/release/hold events from Casambi switches (wired + wireless)
  • Improved relay status handling - Better support for relay units
  • Bug fixes and improvements - Various fixes based on real-world usage

This library provides a bluetooth interface to Casambi-based lights. It is not associated with Casambi.

For Home Assistant integration using this library, see casambi-bt-hass.

Getting started

This library is available on PyPi:

pip install casambi-bt-revamped

Have a look at demo.py for a small example.

Switch Event Support

This library supports receiving physical switch events as a decoded stream of INVOCATION frames (ground truth from the official Android app).

Event types you can expect:

  • button_press
  • button_release
  • button_hold
  • button_release_after_hold
  • input_event (raw NotifyInput frame that may accompany presses/holds; useful for diagnostics and some wired devices)
from CasambiBt import Casambi

def handle_switch_event(event_data):
    print(
        "Switch event:",
        {
            "unit_id": event_data.get("unit_id"),
            "button": event_data.get("button"),
            "event": event_data.get("event"),
            # INVOCATION metadata (useful for debugging/correlation)
            "event_id": event_data.get("event_id"),
            "opcode": event_data.get("opcode"),
            "target_type": event_data.get("target_type"),
            "origin": event_data.get("origin"),
            "age": event_data.get("age"),
            # NotifyInput fields (target_type=0x12)
            "input_code": event_data.get("input_code"),
            "input_channel": event_data.get("input_channel"),
            "input_value16": event_data.get("input_value16"),
            "input_mapped_event": event_data.get("input_mapped_event"),
        },
    )

casa = Casambi()
# ... connect to network ...

# Register switch event handler
casa.registerSwitchEventHandler(handle_switch_event)

# Events will be received when buttons are pressed/released

Notes:

  • Wireless (battery) switches typically send a "button stream" (target_type 0x06) for press/release, and a NotifyInput stream (target_type 0x12) for hold/release-after-hold.
  • Wired switches often only send NotifyInput (target_type 0x12), so input_code is mapped into button_press/button_release/... when appropriate.
  • The library suppresses same-state retransmits at the protocol layer (edge detection), so Home Assistant-style time-window deduplication should generally not be necessary.

For the parsing details and field layout, see doc/PROTOCOL_PARSING.md.

MacOS

MacOS does not expose the Bluetooth MAC address via their official API, if you're running this library on MacOS, it will use an undocumented IOBluetooth API to get the MAC Address. Without the real MAC address the integration with Casambi will not work. If you're running into problems fetching the MAC address on MacOS, try it on a Raspberry Pi.

Casambi network setup

If you have problems connecting to the network please check that your network is configured appropriately before creating an issue. The network I test this with uses the Evoultion firmware and is configured as follows (screenshots are for the iOS app but the Android app should look very similar):

Gateway settings Network settings Performance settings

Development / Offline Testing

This repo includes log-driven unit tests for switch parsing:

cd casambi-bt
python -m unittest -v

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 Distribution

casambi_bt_revamped-0.3.12.dev1.tar.gz (44.4 kB view details)

Uploaded Source

Built Distribution

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

casambi_bt_revamped-0.3.12.dev1-py3-none-any.whl (43.3 kB view details)

Uploaded Python 3

File details

Details for the file casambi_bt_revamped-0.3.12.dev1.tar.gz.

File metadata

File hashes

Hashes for casambi_bt_revamped-0.3.12.dev1.tar.gz
Algorithm Hash digest
SHA256 d3bc71d1baead5763028f1f59f28432a9595f266598f0463e07f3ee78ebf0ddf
MD5 46cd0f1b015768c3fc98a61a5d70be61
BLAKE2b-256 fd62dad8d5313d7c440c32b7606d8f68f906a220afa6b74a7ac14a3d9248bf32

See more details on using hashes here.

File details

Details for the file casambi_bt_revamped-0.3.12.dev1-py3-none-any.whl.

File metadata

File hashes

Hashes for casambi_bt_revamped-0.3.12.dev1-py3-none-any.whl
Algorithm Hash digest
SHA256 dce03c88f7049085f48689bf22d9981518fcde3e20b62b400eba75a9ee1c1b6a
MD5 8de715644f5bffb68b93e7fdc4ed6291
BLAKE2b-256 59c580ea5044648f0818e39cd1cc86f536e91e6a56aa801ee367e0e2509c0b15

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