WebSocket /api/ws
See Supported Devices for more information.
The HomeWizard Energy API v2 and its documentation are in beta and subject to change.
The HomeWizard Energy WebSocket API allows you to receive real-time updates from the device. The WebSocket lets you subscribe to specific topics and receive updates when data changes.
Structure
All data packages, in both directions, are formatted in JSON and contain a type
field and an optional data
field. The data type can be any valid JSON format.
{ "type": "authentication_requested", "data": { "api_version": "2.0.0" } }
{ "type": "subscribe", "data": "device" }
When no data needs to be sent, the data field can be omitted.
{ "type": "identify" }
Commands
Connect and Authorize
To connect to the WebSocket, you must obtain an authorization token. Refer to this page for instructions.
The WebSocket is accessible at wss://<IP ADDRESS>/api/ws
. The connection is secured with the same certificate as the HTTPS connection. Once connected, you must send the authorization token within 40 seconds, or the connection will close.
// Connect to the server
→ {"type": "authorization_requested", "data": {"api_version": "2.0.0"}}
// Send a token within 40 seconds
{"type": "authorization", "data": "<TOKEN>"}
→ {"type": "authorized"}
Subscribe
After authentication, you can subscribe to topics. Topics correspond to available endpoints, with the data matching that returned by the endpoint. Once subscribed, the device sends the latest values and updates when data changes. The type
field consist of the topic name, and the data
field contains the data from the endpoint.
*
- Subscribe to all topicsdevice
- Subscribe to device information updatesuser
- Subscribe to user list updatesmeasurement
- Subscribe to measurement updatessystem
- Subscribe to system updates. Onlycloud_enabled
andstatus_led_brightness_pct
are updated in real time.
{"type": "subscribe", "data": "system"}
→ {"type":"system", "data": {"wifi_ssid": "My WiFi", "wifi_rssi_db": -70, "cloud_enabled": true, "uptime_s": 42, "status_led_brightness_pct": 100}}
→ {"type":"system", "data": {"wifi_ssid": "My WiFi", "wifi_rssi_db": -70, "cloud_enabled": true, "uptime_s": 42, "status_led_brightness_pct": 70}}
Unsubscribe
To unsubscribe from a topic, send an unsubscribe message. The data field should contain the topic name, as described in the subscribe section.
{ "type": "unsubscribe", "data": "system" }
Polling Data
If you only need data once (for example, just a single system
update), you can send a request to the WebSocket for the latest data. The device will respond with the latest values.
{"type": "system"}
→ {"type":"system", "data": {"wifi_ssid": "My WiFi", "wifi_rssi_db": -70, "cloud_enabled": true, "uptime_s": 42, "status_led_brightness_pct": 70}}
Setting Data
Writable parameters, such as system/cloud_enabled
, are also controllable via the WebSocket. The device will respond with the new value.
{ "type": "system", "data": { "cloud_enabled": false } }
→ {"type":"system", "data": {"wifi_ssid": "My WiFi", "wifi_rssi_db": -70, "cloud_enabled": false, "uptime_s": 42, "status_led_brightness_pct": 70}}
Identify
To blink the device LED, send an identify command. The LED will blink for a few seconds.
{ "type": "identify" }
Error Handling
When an error occurs, the device sends an error message. The message contains an error
field with a description of the error, matching the error structure of the v2 API errors.
{"type": "system", "data": {"status_led_brightness_pct": 200}}
→ {"type":"error","data":{"message":"json:parameter-invalid-type:status_led_brightness_pct"}}