From 64e800447d3bcba8064c9ffc0e64c4b915945bd6 Mon Sep 17 00:00:00 2001 From: Sean Straus Date: Thu, 13 Aug 2020 12:13:06 +0200 Subject: [PATCH] =?UTF-8?q?Added=20a=20more=20basic=20example=20as=20the?= =?UTF-8?q?=20template=20ones=20are=20tough=20to=20use=20as=20s=E2=80=A6?= =?UTF-8?q?=20(#14223)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Franck Nijhof --- source/_integrations/rest_command.markdown | 26 ++++++++++++++++++++-- 1 file changed, 24 insertions(+), 2 deletions(-) diff --git a/source/_integrations/rest_command.markdown b/source/_integrations/rest_command.markdown index 29772718572..6105f75bc8d 100644 --- a/source/_integrations/rest_command.markdown +++ b/source/_integrations/rest_command.markdown @@ -71,8 +71,30 @@ service_name: ## Examples +### 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. + +```yaml +rest_command: + shuffle_on: + url: "http://YOUR_ITUNES-API_SERVER_IP:8181/shuffle" + method: put + content_type: "application/x-www-form-urlencoded" + payload: "mode=songs" + shuffle_off: + 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](/docs/configuration/templating/) for dynamic parameters. + {% raw %} ```yaml # Example configuration.yaml entry @@ -90,7 +112,7 @@ rest_command: ``` {% endraw %} -In this example entry, you can see some simple [templates](/docs/configuration/templating/) in use for dynamic parameters. +### How to test your new REST command Call the new service from [developer tools](/docs/tools/dev-tools/) in the sidebar with some `data` like: @@ -100,7 +122,7 @@ Call the new service from [developer tools](/docs/tools/dev-tools/) in the sideb "emoji":":plex:" } ``` -Or in an example `automation` +### Using a REST command as an action in an automation ```yaml automation: