RESTful Command

This integration can expose regular REST commands as services. Services can be called from a script or in automation.

To use this integration, add the following lines to your configuration.yaml file:

# Example configuration.yaml entry
    url: ""

Configuration Variables

service_name map Required

The name used to expose the service. E.g., in the above example, it would be ‘rest_command.example_request’.

url template Required

The URL (supports template) for sending request.

method string (Optional, default: get)

HTTP method to use (get, patch, post, put, or delete).

headers map (Optional)

The headers for the requests.

payload template (Optional)

A string/template to send with request.

username string (Optional)

The username for basic HTTP authentication (digest is not supported).

password string (Optional)

The password for basic HTTP authentication (digest is not supported).

timeout string (Optional, default: 10)

Timeout for requests in seconds.

content_type string (Optional)

Content type for the request.

verify_ssl boolean (Optional, default: true)

Verify the SSL certificate of the endpoint.


Basic example which uses PUT method and payload encoded as form data

This example implements 2 REST commands to add service calls for the missing shuffle functionality of the iTunes integration.

    url: "http://YOUR_ITUNES-API_SERVER_IP:8181/shuffle"
    method: put
    content_type: "application/x-www-form-urlencoded"
    payload: "mode=songs"
    url: "http://YOUR_ITUNES-API_SERVER_IP:8181/shuffle"
    method: put
    content_type: "application/x-www-form-urlencoded"
    payload: "mode=off"

Using templates to change the payload based on entities

The commands can be dynamic, using templates to insert values of other entities. Service call support variables for doing things with templates.

In this example, uses templates for dynamic parameters.

# Example configuration.yaml entry
    method: POST
      authorization: !secret rest_headers_secret
      accept: "application/json, text/html"
      user-agent: 'Mozilla/5.0 {{ useragent }}'
    payload: '{"profile":{"status_text": "{{ status }}","status_emoji": "{{ emoji }}"}}'
    content_type:  'application/json; charset=utf-8'
    verify_ssl: true

How to test your new REST command

Call the new service from developer tools in the sidebar with some data like:

  "status":"My Status Goes Here",

Using a REST command as an action in an automation

- alias: "Arrive at Work"
    platform: zone
    entity_id: device_tracker.my_device
    event: enter
    - service: rest_command.my_request
        status: "At Work"
        emoji: ":calendar:"