From af45b0fc5d0e9ab42f1f6dc2fd5c7bff4915aaf6 Mon Sep 17 00:00:00 2001 From: Adam Starbuck Date: Wed, 25 Jul 2018 10:37:23 -0500 Subject: [PATCH 1/2] Added example for using templates Also added example automation with using templates and some sample headers in the configuration. --- source/_components/rest_command.markdown | 43 ++++++++++++++++++++++++ 1 file changed, 43 insertions(+) diff --git a/source/_components/rest_command.markdown b/source/_components/rest_command.markdown index 962d92e3c432..6869e7d207e0 100644 --- a/source/_components/rest_command.markdown +++ b/source/_components/rest_command.markdown @@ -41,3 +41,46 @@ Configuration variables: The commands can be dynamic, using templates to insert values of other entities. Service call support variables for template stuff. + + +```yaml +# Example configuration.yaml entry +rest_command: + my_request: + url: https://slack.com/api/users.profile.set + method: POST + headers: + authorization: !secret rest_headers_secret + accept: 'application/json, text/html' + payload: '{"profile":{"status_text": "{{ status }}","status_emoji": "{{ emoji }}"}}' + content_type: 'application/json; charset=utf-8' +``` + +In this example entry, you can see some simple [templates] in use for dynamic parameters. + +[templates]: /docs/configuration/templating/ + +Call the new service from [developer tools] in the sidebar with some `data` like: + +[developer tools]: /docs/tools/dev-tools/ + +```json +{"status":"My Status Goes Here", +"emoji":":plex:"} +``` +Or in an example `automation` + +```yaml +automation: +- alias: 'Arrive at Work' + trigger: + platform: zone + entity_id: device_tracker.my_device + zone: zone.work + event: enter + action: + - service: rest_command.my_request + data: + status: "At Work" + emoji: ":calendar:" +``` From 12ae59ebd996d7f560a3ecee63416529cf9b1b55 Mon Sep 17 00:00:00 2001 From: Fabian Affolter Date: Thu, 26 Jul 2018 11:39:16 +0200 Subject: [PATCH 2/2] Minor changes --- source/_components/rest_command.markdown | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/source/_components/rest_command.markdown b/source/_components/rest_command.markdown index 6869e7d207e0..4e4ef8fb6f50 100644 --- a/source/_components/rest_command.markdown +++ b/source/_components/rest_command.markdown @@ -39,10 +39,11 @@ Configuration variables: - **timeout** (*Optional*): Timeout for requests. Defaults to 10 seconds. - **content_type** (*Optional*): Content type for the request. -The commands can be dynamic, using templates to insert values of other entities. -Service call support variables for template stuff. +## {% linkable_title Examples %} +The commands can be dynamic, using templates to insert values of other entities. Service call support variables for doing things with templates. +{% raw %} ```yaml # Example configuration.yaml entry rest_command: @@ -55,18 +56,17 @@ rest_command: payload: '{"profile":{"status_text": "{{ status }}","status_emoji": "{{ emoji }}"}}' content_type: 'application/json; charset=utf-8' ``` +{% endraw %} -In this example entry, you can see some simple [templates] in use for dynamic parameters. +In this example entry, you can see some simple [templates](/docs/configuration/templating/) in use for dynamic parameters. -[templates]: /docs/configuration/templating/ - -Call the new service from [developer tools] in the sidebar with some `data` like: - -[developer tools]: /docs/tools/dev-tools/ +Call the new service from [developer tools](/docs/tools/dev-tools/) in the sidebar with some `data` like: ```json -{"status":"My Status Goes Here", -"emoji":":plex:"} +{ + "status":"My Status Goes Here", + "emoji":":plex:" +} ``` Or in an example `automation`