mirror of
https://github.com/home-assistant/home-assistant.io.git
synced 2025-07-21 08:16:53 +00:00
Updating documentation for REST switch with template example (#2713)
* fixing typo in rest switch template example * adding example with template to docs * adding generic info about response JSON * making requested changes * changing file mode, removing response parsing information * updating docs with generic info and link to specific topic * fixing file permissions
This commit is contained in:
parent
7ec135ee9a
commit
52cdd35344
@ -30,10 +30,30 @@ Configuration variables:
|
||||
- **name** (*Optional*): Name of the REST switch.
|
||||
- **body_on** (*Optional*): The body of the POST request that commands the switch to become enabled. Default is "ON". This value can be a [template](/topics/templating/), which is useful if the POST request needs to depend on the state of the system. For example, to enable remote-temperature-sensor tracking on a radio thermostat, one has to send the current value of the remote temperature sensor. On can achieve this using the template `'{"rem_temp":{{states.sensor.bedroom_temp.state}}}'`.
|
||||
- **body_off** (*Optional*): The body of the POST request that commands the switch to become disabled. Default is "OFF". This value can also be a template.
|
||||
- **is_on_template** (*Optional*): A [template](/topics/templating/) that determines the state of the switch from the value returned by the GET request on the resource url. This template should compute to a boolean (True or False). Default is equivalent to `'{% raw %}{{ value.json == body_on }}{% endraw %}'`. This means that by default, the state of the switch is on if and only if the response to the GET request matches `body_on`.
|
||||
- **is_on_template** (*Optional*): A [template](/topics/templating/) that determines the state of the switch from the value returned by the GET request on the resource url. This template should compute to a boolean (True or False). If the value is valid JSON, it will be available in the template as the variable value_json. See [this example](/docs/configuration/templating/#processing-incoming-data) in the template docs. Default is equivalent to `'{% raw %}{{ value_json == body_on }}{% endraw %}'`. This means that by default, the state of the switch is on if and only if the response to the GET request matches `body_on`.
|
||||
|
||||
|
||||
<p class='note warning'>
|
||||
Make sure that the URL matches exactly your endpoint or resource.
|
||||
</p>
|
||||
|
||||
|
||||
## {% linkable_title Example %}
|
||||
|
||||
### {% linkable_title Switch with templated value %}
|
||||
|
||||
This example shows a switch that uses a [template](/topics/templating/) to allow Home Assistant to determine its state. In this example the REST endpoint returns this JSON response with true indicating the switch is on.
|
||||
|
||||
```json
|
||||
{"is_active": "true"}
|
||||
```
|
||||
|
||||
|
||||
```yaml
|
||||
switch:
|
||||
- platform: rest
|
||||
resource: http://<address>/led_endpoint
|
||||
body_on: '{"active": "true"}'
|
||||
body_off: '{"active": "false"}'
|
||||
is_on_template: '{% raw %}{{value_json.is_active}}{% endraw %}'
|
||||
```
|
||||
|
Loading…
x
Reference in New Issue
Block a user