Home Assistant Generic WS
Node to interact with Home Assistant through the WebSocket API with generic operations
Overview
This node enables interaction with Home Assistant via its WebSocket API using generic operations. It allows users to send arbitrary commands (specified by a "Type") to Home Assistant, optionally including parameters in the request body, and optionally waiting for a response.
Common scenarios include:
- Triggering custom Home Assistant services or commands not covered by specialized nodes.
- Sending dynamic or complex commands where the exact payload varies.
- Integrating Home Assistant with other workflows that require flexible control over WebSocket messages.
Practical example:
- Sending a command to toggle a light entity by specifying the appropriate service call type and parameters.
- Querying the state of an entity by sending a request and waiting for the response.
Properties
| Name | Meaning |
|---|---|
| Type | The WebSocket message type or command to send to Home Assistant. |
| Has Response | Whether to wait for a response from Home Assistant after sending the request (true or false). |
| Has Parameters | Whether the request includes additional parameters in the body (true or false). |
| Specify Body | How to specify the request body if parameters are included: either as explicit key-value pairs ("Using Fields Below") or as a JSON object ("Using JSON"). |
| Body Parameters | When specifying body as key-value pairs, this is a collection of parameters with "Name" and "Value" fields representing the keys and values sent in the request body. |
| JSON | When specifying body as JSON, this field contains the raw JSON object to send as the request body. |
Output
The node outputs an array of JSON objects corresponding to the responses received from Home Assistant for each input item.
- If "Has Response" is true, the output JSON contains the data returned by Home Assistant in response to the sent command.
- If "Has Response" is false, the output JSON is an empty array since no response is awaited.
No binary data output is produced by this node.
Dependencies
- Requires a valid connection to a Home Assistant instance via its WebSocket API.
- Needs an API key credential for authentication with Home Assistant.
- The node depends on internal helper functions and utilities for parsing parameters and mapping results.
Troubleshooting
- Missing Type: The node throws an error if the "Type" property is not set, as it is required to define the WebSocket message to send.
- Connection Issues: Failure to connect to Home Assistant may occur if the host or API key credentials are incorrect or missing.
- Invalid Parameters: Incorrectly formatted parameters or JSON bodies can cause errors or unexpected behavior.
- No Response When Expected: If "Has Response" is true but no response arrives, verify network connectivity and that the Home Assistant server supports the requested command.
Links and References
- Home Assistant WebSocket API Documentation
- n8n Expressions Documentation (for parameter expressions)