RESTful Command
This integrationIntegrations connect and integrate Home Assistant with your devices, services, and more. [Learn more] can expose regular REST commands as actions. Actions can be called from a script or in automation.
To use this integrationIntegrations connect and integrate Home Assistant with your devices, services, and more. [Learn more], add the following lines to your configuration.yaml
The configuration.yaml file is the main configuration file for Home Assistant. It lists the integrations to be loaded and their specific configurations. In some cases, the configuration needs to be edited manually directly in the configuration.yaml file. Most integrations can be configured in the UI. [Learn more] file.
After changing the configuration.yaml
The configuration.yaml file is the main configuration file for Home Assistant. It lists the integrations to be loaded and their specific configurations. In some cases, the configuration needs to be edited manually directly in the configuration.yaml file. Most integrations can be configured in the UI. [Learn more] file, restart Home Assistant to apply the changes.
Configuration Variables
The name used to expose the action. E.g., in the above example, it would be ‘rest_command.example_request’.
The URL (supports template) for sending request.
A string/template to send with request.
Examples
Basic example which uses PUT method and payload encoded as form data
This example implements 2 REST commands to add actions for the missing shuffle functionality of the iTunes integration.
Using REST command Response in automations
REST commands provide an action response in a dictionary containing status
(containing the HTTP response code) and content
containing the response body as text or JSON. This response can be accessed in automations using response_variable
.
The following example shows how the REST command response may be used in automations. In this case, checking the Traefik API
Using templates to change the payload based on entities
The commands can be dynamic, using templates to insert values of other entities. Actions support variables for doing things with templates.
In this example, uses templates for dynamic parameters.
How to test your new REST command
Call the new action from developer tools in the sidebar with some data
like: