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
- Classic protocol (experimental) - Basic unit control for Classic (legacy) firmware networks
- 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).
Semantic event types supported by the capture-derived switch decoder:
button_pressbutton_release(short press;press_duration_msis set when reported by the switch itself)button_hold(long press threshold reached)button_release_after_holdinput_event(NotifyInput frame with an unknown code; diagnostics only)
Every event also carries source (button_event = the switch's own ButtonEvent stream,
notify_input = NotifyInput stream) and held (True for hold / release-after-hold).
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 send a "button stream" (target_type
0x06) for press/release with the press duration; a mains unit additionally reports the same action as NotifyInput (target_type0x12), which is also the only carrier of hold. - Wired switches often only send NotifyInput (target_type
0x12); itsinput_codeis mapped intobutton_press/button_release/.... - Mesh copies are suppressed by invocation identity for at least 3 seconds, extended to the declared lifetime when longer. The legacy switch API also pairs ButtonEvent and NotifyInput reports by count within 3 seconds. That heuristic can consume a real event when rapid clicks have complementary losses across the two sources. Its 500 ms long-press threshold and four-gang button labels are capture-derived assumptions.
Selecting a GATT node
Pass a node's BLEDevice to connect and set networkAddress to the original
network MAC address. Cloud access and cached keys continue to use that network
identity while the Bluetooth connection uses the selected node. Omitting
networkAddress preserves the existing connection behavior.
Network Events
registerNetworkEventHandler exposes profile-driven state changes and type 7 protocol observations for the whole connected network. The type 7 path preserves ButtonEvent and NotifyInput separately, including their raw indices, flags, origin/target, optional origin handle, packet sequence and input fields. It does not apply the legacy switch API's cross-source pairing or inferred long-press threshold.
The local Mac viewer uses WebSocket updates, preserves expanded details, supports optional LAN listeners and saves event history across restarts. See Network Events for the API, protocol evidence and demo commands.
For the parsing details and field layout, see doc/PROTOCOL_PARSING.md.
Classic (Legacy Firmware) Support (Experimental)
This library can also connect to Classic Casambi networks and send unit control commands.
How it works (ground truth: the bundled Android app sources):
- Classic devices expose a CMAC-signed data channel (
ca51/ca52) or a "Classic conformant" signed channel on the EVO UUID. - The cloud network JSON exposes
visitorKey/managerKey(hex strings) instead of an EVOkeyStore. - Commands are signed with AES-CMAC and sent as Classic "command records" (see
doc/PROTOCOL_PARSING.md).
Environment flags:
CASAMBI_BT_DISABLE_CLASSIC=1to refuse Classic connections (fail fast)CASAMBI_BT_CLASSIC_USE_MANAGER=1to sign with the 16-byte manager signature (default is visitor/4-byte prefix)CASAMBI_BT_LOG_RAW_NOTIFIES=1to enable very verbose per-notify hexdumps (mainly for Classic debugging)
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):
Development / Offline Testing
This repo includes log-driven unit tests for switch parsing:
cd casambi-bt
python -m unittest -v
Metadata
Release files for casambi-bt-revamped 0.4.2
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| casambi_bt_revamped-0.4.2.tar.gz | 90.1 kB | Without provenance | Details for casambi_bt_revamped-0.4.2.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| casambi_bt_revamped-0.4.2-py3-none-any.whl | Python 3 | none | any | Details for casambi_bt_revamped-0.4.2-py3-none-any.whl |
Total release size: 166.4 kB
Release files / casambi_bt_revamped-0.4.2.tar.gz
| Download URL | casambi_bt_revamped-0.4.2.tar.gz |
|---|---|
| Size | 90.1 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
15461c3a7824985d27337bbd6769701f3b2bb398402b2f861a26903fbaef5837
|
|
BLAKE2b-256 checksum How to use checksums |
c341fc9a47c38128f52629071ea874684d1c038d780951e6a434c0d3079d5569
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.14.7
|
Release files / casambi_bt_revamped-0.4.2-py3-none-any.whl
| Download URL | casambi_bt_revamped-0.4.2-py3-none-any.whl |
|---|---|
| Size | 76.2 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
38621e675669f099e0b55d09f04fa945fe4ab8b1562885c74911ba8be6b8f9e7
|
|
BLAKE2b-256 checksum How to use checksums |
4c4fc5e4e77a4c1c0328af3753d36b5ac3faf9607af3921b1e32d7098f4f46f7
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.14.7
|
Security for casambi-bt-revamped 0.4.2
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.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.