mirror of
https://github.com/home-assistant/home-assistant.io.git
synced 2025-07-13 20:36:52 +00:00
Move details to example section
This commit is contained in:
parent
52cdd35344
commit
e2c97d4941
@ -28,16 +28,14 @@ Configuration variables:
|
|||||||
|
|
||||||
- **resource** (*Required*): The resource or endpoint that contains the value.
|
- **resource** (*Required*): The resource or endpoint that contains the value.
|
||||||
- **name** (*Optional*): Name of the REST switch.
|
- **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_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/).
|
||||||
- **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.
|
- **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](/topics/templating/).
|
||||||
- **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`.
|
- **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 documentation. 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 .
|
||||||
|
|
||||||
|
|
||||||
<p class='note warning'>
|
<p class='note warning'>
|
||||||
Make sure that the URL matches exactly your endpoint or resource.
|
Make sure that the URL matches exactly your endpoint or resource.
|
||||||
</p>
|
</p>
|
||||||
|
|
||||||
|
|
||||||
## {% linkable_title Example %}
|
## {% linkable_title Example %}
|
||||||
|
|
||||||
### {% linkable_title Switch with templated value %}
|
### {% linkable_title Switch with templated value %}
|
||||||
@ -52,8 +50,11 @@ This example shows a switch that uses a [template](/topics/templating/) to allow
|
|||||||
```yaml
|
```yaml
|
||||||
switch:
|
switch:
|
||||||
- platform: rest
|
- platform: rest
|
||||||
resource: http://<address>/led_endpoint
|
resource: http://IP_ADDRESS/led_endpoint
|
||||||
body_on: '{"active": "true"}'
|
body_on: '{"active": "true"}'
|
||||||
body_off: '{"active": "false"}'
|
body_off: '{"active": "false"}'
|
||||||
is_on_template: '{% raw %}{{value_json.is_active}}{% endraw %}'
|
is_on_template: '{% raw %}{{value_json.is_active}}{% endraw %}'
|
||||||
```
|
```
|
||||||
|
|
||||||
|
`body_on` and `body_off` can also depend on the state of the system. For example, to enable a remote temperature sensor tracking on a radio thermostat, one has to send the current value of the remote temperature sensor. This can be achieved by using the template `'{"rem_temp":{{states.sensor.bedroom_temp.state}}}'`.
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user