Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/bene/homebridge-websocket
Forwards events from HomeBridge to your device to quickly build accessories without worrying about communication.
https://github.com/bene/homebridge-websocket
homebridge homebridge-plugin homekit homekit-accessory smarthome
Last synced: about 1 month ago
JSON representation
Forwards events from HomeBridge to your device to quickly build accessories without worrying about communication.
- Host: GitHub
- URL: https://github.com/bene/homebridge-websocket
- Owner: bene
- Created: 2022-12-21T01:43:37.000Z (about 2 years ago)
- Default Branch: main
- Last Pushed: 2022-12-22T14:54:37.000Z (about 2 years ago)
- Last Synced: 2024-11-01T08:42:09.240Z (3 months ago)
- Topics: homebridge, homebridge-plugin, homekit, homekit-accessory, smarthome
- Language: TypeScript
- Homepage:
- Size: 384 KB
- Stars: 2
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# HomeBridge-WebSocket
Forwards events from HomeBridge to your device to quickly build accessories
without worrying about communication.## Usage
To get started the `HomeBridge-WebSocket` server must be hosted. You can host it
in the cloud for simplicity or locally for shorter response times and higher
privacy.### Register an accessory in your plugin config
After hosting s server and installing the plugin in HomeBridge, add an accessory
to the config.```json
{
"apiUrl": "wss://home.bene.dev",
"name": "HomeBridgeWebSocket",
"platform": "HomeBridgeWebSocket",
"accessories": [
{
"service": "Switch",
"id": "Switch-000",
"token": "SOME_RANDOM_TOKEN",
"name": "PiSwitch"
}
]
}
```### Implement a client
To receive events on your client (e.g. Raspberry Pi) use the TypeScript SDK.
```typescript
import Client from "@homebridge-ws/sdk";
import { SwitchState } from "@homebridge-ws/types";const client = new Client("wss://home.bene.dev");
let isOn = true;
function onSetState(state: SwitchState) {
console.log("SetState", state);
isOn = state.on;
// Example: Set GPIO on Raspberry Pi
}function onGetState(): SwitchState {
console.log("GetState", { on: isOn });
return { on: isOn };
}client.subscribe(
"Switch",
"Switch-000",
"SOME_RANDOM_TOKEN",
onSetState,
onGetState,
);
```## Supported service types
See [here](./SUPPORT.md) which service types are supported.