A generic Home Assistant integration that enables any authenticated WebSocket client to dynamically create and update entities. It is fully decoupled from specific hardware or protocols (e.g., BLE, Zigbee); as long as the client conforms to the defined communication protocol, it works out of the box.
🐞 Found a bug? Let us know via an Issue.
💡 Have a question or suggestion? Join the Discussion!
- No Additional Brokers/Ports: Communicates directly using Home Assistant's standard WebSocket API (
/api/websocket) and a Long-Lived Access Token. No need to run an MQTT broker or expose extra TCP ports. - Dynamic Entity Provisioning: Entities are created instantly in Home Assistant as soon as the client declares them via JSON messages over the WebSocket connection.
- Client-based Device Grouping: Each client (identified by
gateway_id) is registered as a parent device (Gateway) in Home Assistant. All devices/entities declared by that client are grouped as child devices (via_device) under it for clean organization. - Bi-directional Command Routing: Supports control components including
switch,number,select, andbutton. Control events (command) triggered by the HA UI or automations are routed back exclusively to the originating client. - Connection State Tracking (LWT): If the client's WebSocket connection drops, all child devices and entities registered by that client are automatically set to
unavailableto prevent stale states. - Connected Clients Diagnostic Sensor: Provides a diagnostic sensor that reports the number of currently connected WebSocket clients (
gateway_id) in real time.
graph TD
subgraph Clients [WebSocket Clients]
A[BLE Gateway App]
B[Custom ESP32 Device]
end
subgraph Home Assistant [Home Assistant Core]
HA_WS[Standard WebSocket API]
Bridge[WebSocket Bridge Integration]
Entities[Dynamic Entities]
end
A <-->|ws:// or wss:// & Long-lived Token| HA_WS
B <-->|ws:// or wss:// & Long-lived Token| HA_WS
HA_WS <--> Bridge
Bridge <--> Entities
| Platform | Direction | Description / Supported Attributes |
|---|---|---|
sensor |
Read | Numerical state data (unit_of_measurement, device_class, state_class) |
binary_sensor |
Read | On/Off boolean states (device_class) |
switch |
Control | Power toggle control (turn_on, turn_off) |
number |
Control | Range value control (set_value, min, max, step) |
select |
Control | Option selection control (select_option, options) |
button |
Control | Execution trigger (press, stateless) |
- Navigate to HACS in your Home Assistant sidebar.
- Click the three dots in the top right corner and select Custom repositories.
- Enter
https://github.com/eigger/hass-ws-bridgeas the repository URL, set the category to Integration, and click Add. - Install the integration, then restart Home Assistant.
- Download the
custom_components/ws_bridgefolder from this repository. - Copy it into your Home Assistant configuration directory under
custom_components/.- Target path:
config/custom_components/ws_bridge/
- Target path:
- Restart Home Assistant.
- Add Integration in HA:
- Navigate to Settings -> Devices & Services -> Add Integration.
- Search for WebSocket Bridge and add it. (It will initialize instantly without requiring any UI configuration.)
- Generate Long-Lived Access Token:
- Go to your Home Assistant user profile page, scroll to the bottom, and click Create Token. Copy the token value.
- Configure Client:
- Enter the Home Assistant WebSocket URL (e.g.,
ws://192.168.1.100:8123/api/websocket) and the generated token in your client application/device.
- Enter the Home Assistant WebSocket URL (e.g.,
For the detailed JSON message formats exchanged between clients and the bridge, see:
- English Protocol Specification (docs/PROTOCOL.md)
- Korean Protocol Specification (docs/PROTOCOL_ko.md)
- Session Registration:
{"type": "ws_bridge/connect", "gateway_id": "..."} - Entity Declaration:
{"type": "ws_bridge/entity", "unique_id": "...", "platform": "sensor", ...} - State Update:
{"type": "ws_bridge/state", "states": [{"unique_id": "...", "value": 25.4}]} - Device Availability:
{"type": "ws_bridge/availability", "device_id": "...", "online": true} - Remove:
{"type": "ws_bridge/remove", "unique_id": "..."}/{"device_id": "..."}/{}(entire gateway) - Control Event: HA pushes
{"kind": "command", "unique_id": "...", "action": "turn_on"}events to the client.
This project is licensed under the MIT License - see the LICENSE file for details.