Using BLE to control a Casambi-based home lighting system via a web interface.
Project description
Casambi Web Controller
This document outlines the local Casambi lighting control system utilizing a web API interface.
System Architecture
The application functions as middleware. It employs the FastAPI framework to convert standard HTTP requests into Casambi network commands. The connection lifecycle and device interactions are managed via the casambi-bt library.
Limitations
The system currently supports only a single Casambi network.
Supported devices are exclusively lighting units capable of dimming.
Requirements
Python
Required libraries: fastapi, uvicorn, CasambiBt
Execution
Execute the main Python script. The terminal will prompt for the Casambi network password. The system will automatically discover the network, establish a connection, and initialize the web server on port 8000.
Logical Bridge Concept
The system introduces the concept of a "Logical Bridge". This is an abstraction layer that maps physical Casambi lighting hardware to virtual nodes.
Instead of hardcoding device-specific commands into external platforms (such as a Matter controller), the Logical Bridge exposes a standardized JSON metadata schema. Each virtual unit within this schema encapsulates its operational events (e.g., turn_on, turn_off, set_level, get_state) with directly executable Python scripts.
This architectural choice ensures high interoperability, allowing any external process with a Python interpreter to dynamically interact with the local HTTP APIs without requiring prior knowledge of the Casambi protocol.
API Endpoints
Get all lights
-
URL:
/api/lights -
Method: GET
-
Description: Retrieves the complete list of available units in the network alongside their current dimmer values.
-
Sample Response:
[ { "name": "Ceiling Light", "dimmer": 255 }, { "name": "Desk Lamp", "dimmer": 0 } ]
Get specific light status
-
URL:
/api/status -
Method: GET
-
Parameters:
name(string, required): The exact assigned name of the device.
-
Description: Retrieves the current dimmer state of a specifically named unit. Returns an HTTP 404 error if the unit is not found.
-
Sample Response:
{ "name": "Ceiling Light", "dimmer": 128 }
Control light intensity
-
URL:
/api/set -
Method: GET
-
Parameters:
-
name(string, required): The exact assigned name of the target device. -
dimmer(integer, required): The target brightness level, strictly constrained between 0 and 255.
-
-
Description: Transmits a command to adjust the target device to the specified dimmer level. Returns a success confirmation. Returns an HTTP 400 error if the dimmer value is invalid.
-
Sample Response:
{ "status": "success" }
Get logical bridge metadata
-
URL:
/api/metadata -
Method: GET
-
Description: Dynamically detects the incoming client request context to resolve the host IP and port. It outputs a JSON payload describing the network as a logical bridge. The payload embeds executable Python scripts mapped to standard lighting events (turn_on, turn_off, set_level, get_state) for automated HTTP integration.
-
Sample Response:
{
"bridge": {
"id": "casambi_bridge_http",
"type": "dimmable_lighting_controller",
"network_host": "192.168.1.220",
"network_port": 8000
},
"devices": [
{
"node_id": "casambi_ceiling_light",
"name": "Ceiling Light",
"hardware_type": "dimmable_light",
"events": {
"turn_on": {
"trigger": "on_off_cluster",
"script": "import urllib.request\n# Execute GET request to set dimmer to maximum\nurllib.request.urlopen('[http://192.168.1.220:8000/api/set?name=Ceiling%20Light&dimmer=255](http://192.168.1.220:8000/api/set?name=Ceiling%20Light&dimmer=255)')"
}
}
}
]
}
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
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file casambi_web_controller-0.3.0.tar.gz.
File metadata
- Download URL: casambi_web_controller-0.3.0.tar.gz
- Upload date:
- Size: 5.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
01b61c68de3a0bb7962982114fe5fb692263d428a9309cc942a86828c118cab3
|
|
| MD5 |
35fd826c3f37ed2f7eef70569156f976
|
|
| BLAKE2b-256 |
c4d8bec7c99bcf6dd23e2f539c6ba9a51243e18c4c3a002c2c8e0d2a5535e90f
|
Provenance
The following attestation bundles were made for casambi_web_controller-0.3.0.tar.gz:
Publisher:
python-publish.yml on dongnh/casambi_webcontrol
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
casambi_web_controller-0.3.0.tar.gz -
Subject digest:
01b61c68de3a0bb7962982114fe5fb692263d428a9309cc942a86828c118cab3 - Sigstore transparency entry: 1008360966
- Sigstore integration time:
-
Permalink:
dongnh/casambi_webcontrol@d7022344430a334c94893ce12ba51f410940ae3c -
Branch / Tag:
refs/tags/v0.3.0 - Owner: https://github.com/dongnh
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
python-publish.yml@d7022344430a334c94893ce12ba51f410940ae3c -
Trigger Event:
release
-
Statement type:
File details
Details for the file casambi_web_controller-0.3.0-py3-none-any.whl.
File metadata
- Download URL: casambi_web_controller-0.3.0-py3-none-any.whl
- Upload date:
- Size: 5.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
7eb5c849b7b2db3c8b000d5935bdf6f749263a6feefad81788ddbf2db29304a1
|
|
| MD5 |
b59556b807a0fe9f3533c6190b05a9f1
|
|
| BLAKE2b-256 |
d61fbf5e7ebca68ed20b79f8daf0e0384374f0c51716f3e21db9172c48286c04
|
Provenance
The following attestation bundles were made for casambi_web_controller-0.3.0-py3-none-any.whl:
Publisher:
python-publish.yml on dongnh/casambi_webcontrol
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
casambi_web_controller-0.3.0-py3-none-any.whl -
Subject digest:
7eb5c849b7b2db3c8b000d5935bdf6f749263a6feefad81788ddbf2db29304a1 - Sigstore transparency entry: 1008360969
- Sigstore integration time:
-
Permalink:
dongnh/casambi_webcontrol@d7022344430a334c94893ce12ba51f410940ae3c -
Branch / Tag:
refs/tags/v0.3.0 - Owner: https://github.com/dongnh
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
python-publish.yml@d7022344430a334c94893ce12ba51f410940ae3c -
Trigger Event:
release
-
Statement type: