mirror of
https://github.com/home-assistant/home-assistant.io.git
synced 2025-07-13 20:36:52 +00:00
Add REST sensor/binary_sensor/switch templated headers & params (#20058)
This commit is contained in:
parent
87963b7694
commit
813be23edf
@ -124,7 +124,11 @@ password:
|
|||||||
headers:
|
headers:
|
||||||
description: The headers for the requests.
|
description: The headers for the requests.
|
||||||
required: false
|
required: false
|
||||||
type: [list, string]
|
type: [list, template]
|
||||||
|
params:
|
||||||
|
description: The query params for the requests.
|
||||||
|
required: false
|
||||||
|
type: [list, template]
|
||||||
{% endconfiguration %}
|
{% endconfiguration %}
|
||||||
|
|
||||||
## Examples
|
## Examples
|
||||||
@ -153,7 +157,9 @@ binary_sensor:
|
|||||||
|
|
||||||
### Accessing an HTTP authentication protected endpoint
|
### Accessing an HTTP authentication protected endpoint
|
||||||
|
|
||||||
The REST sensor supports HTTP authentication and customized headers.
|
The REST sensor supports HTTP authentication and template-enabled customized headers.
|
||||||
|
|
||||||
|
{% raw %}
|
||||||
|
|
||||||
```yaml
|
```yaml
|
||||||
binary_sensor:
|
binary_sensor:
|
||||||
@ -165,8 +171,12 @@ binary_sensor:
|
|||||||
headers:
|
headers:
|
||||||
User-Agent: Home Assistant
|
User-Agent: Home Assistant
|
||||||
Content-Type: application/json
|
Content-Type: application/json
|
||||||
|
X-Custom-Header: '{{ states("input_text.the_custom_header") }}'
|
||||||
```
|
```
|
||||||
|
|
||||||
|
{% endraw %}
|
||||||
|
|
||||||
|
|
||||||
The headers will contain all relevant details. This will also give
|
The headers will contain all relevant details. This will also give
|
||||||
you the ability to access endpoints that are protected by tokens.
|
you the ability to access endpoints that are protected by tokens.
|
||||||
|
|
||||||
|
@ -151,11 +151,11 @@ password:
|
|||||||
headers:
|
headers:
|
||||||
description: The headers for the requests.
|
description: The headers for the requests.
|
||||||
required: false
|
required: false
|
||||||
type: [string, list]
|
type: [list, template]
|
||||||
params:
|
params:
|
||||||
description: The query params for the requests.
|
description: The query params for the requests.
|
||||||
required: false
|
required: false
|
||||||
type: [string, list]
|
type: [list, template]
|
||||||
sensor:
|
sensor:
|
||||||
description: A list of [RESTful Sensor](/integrations/sensor.rest) to create from the shared data. All configuration settings that the supported by [RESTful Sensor](/integrations/sensor.rest#configuration-variables) not listed above can be used here.
|
description: A list of [RESTful Sensor](/integrations/sensor.rest) to create from the shared data. All configuration settings that the supported by [RESTful Sensor](/integrations/sensor.rest#configuration-variables) not listed above can be used here.
|
||||||
required: false
|
required: false
|
||||||
|
@ -41,6 +41,12 @@ or a template based request:
|
|||||||
sensor:
|
sensor:
|
||||||
- platform: rest
|
- platform: rest
|
||||||
resource_template: http://IP_ADDRESS/{{ now().strftime('%Y-%m-%d') }}
|
resource_template: http://IP_ADDRESS/{{ now().strftime('%Y-%m-%d') }}
|
||||||
|
headers:
|
||||||
|
Authorization: >
|
||||||
|
Bearer {{ states("input_text.my_access_token") }}
|
||||||
|
params:
|
||||||
|
start_date: >
|
||||||
|
{{ (now() - timedelta(days = 1)).strftime('%Y-%m-%d') }}
|
||||||
```
|
```
|
||||||
|
|
||||||
{% endraw %}
|
{% endraw %}
|
||||||
@ -109,11 +115,11 @@ password:
|
|||||||
headers:
|
headers:
|
||||||
description: The headers for the requests.
|
description: The headers for the requests.
|
||||||
required: false
|
required: false
|
||||||
type: [string, list]
|
type: [template, list]
|
||||||
params:
|
params:
|
||||||
description: The query params for the requests.
|
description: The query params for the requests.
|
||||||
required: false
|
required: false
|
||||||
type: [string, list]
|
type: [template, list]
|
||||||
json_attributes:
|
json_attributes:
|
||||||
description: A list of keys to extract values from a JSON dictionary result and then set as sensor attributes. If the endpoint returns XML with the "text/xml", "application/xml" or "application/xhtml+xml" content type, it will automatically be converted to JSON according to this [specification](https://www.xml.com/pub/a/2006/05/31/converting-between-xml-and-json.html)
|
description: A list of keys to extract values from a JSON dictionary result and then set as sensor attributes. If the endpoint returns XML with the "text/xml", "application/xml" or "application/xhtml+xml" content type, it will automatically be converted to JSON according to this [specification](https://www.xml.com/pub/a/2006/05/31/converting-between-xml-and-json.html)
|
||||||
required: false
|
required: false
|
||||||
|
@ -74,7 +74,11 @@ password:
|
|||||||
headers:
|
headers:
|
||||||
description: The headers for the request.
|
description: The headers for the request.
|
||||||
required: false
|
required: false
|
||||||
type: [string, list]
|
type: [list, template]
|
||||||
|
params:
|
||||||
|
description: The query params for the requests.
|
||||||
|
required: false
|
||||||
|
type: [list, template]
|
||||||
verify_ssl:
|
verify_ssl:
|
||||||
description: Verify the SSL certificate of the endpoint.
|
description: Verify the SSL certificate of the endpoint.
|
||||||
required: false
|
required: false
|
||||||
@ -97,6 +101,7 @@ This example shows a switch that uses a [template](/topics/templating/) to allow
|
|||||||
```
|
```
|
||||||
|
|
||||||
{% raw %}
|
{% raw %}
|
||||||
|
|
||||||
```yaml
|
```yaml
|
||||||
switch:
|
switch:
|
||||||
- platform: rest
|
- platform: rest
|
||||||
@ -106,8 +111,10 @@ switch:
|
|||||||
is_on_template: "{{ value_json.is_active }}"
|
is_on_template: "{{ value_json.is_active }}"
|
||||||
headers:
|
headers:
|
||||||
Content-Type: application/json
|
Content-Type: application/json
|
||||||
|
X-Custom-Header: '{{ states("input_text.the_custom_header") }}'
|
||||||
verify_ssl: true
|
verify_ssl: true
|
||||||
```
|
```
|
||||||
|
|
||||||
{% endraw %}
|
{% 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 `{% raw %}'{"rem_temp":{{states('sensor.bedroom_temp')}}}'{% 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 `{% raw %}'{"rem_temp":{{states('sensor.bedroom_temp')}}}'{% endraw %}`.
|
||||||
|
Loading…
x
Reference in New Issue
Block a user