add icon_template to command_line switch documentation (#20548)

This commit is contained in:
Marius 2021-12-03 19:13:17 +01:00 committed by GitHub
parent 133ebe6381
commit 13a289f346
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -56,6 +56,10 @@ switches:
description: The name used to display the switch in the frontend.
required: false
type: string
icon:
description: Defines a template for the icon of the entity.
required: false
type: template
command_timeout:
description: Defines number of seconds for command timeout.
required: false
@ -81,6 +85,34 @@ See aREST device below for an example.
In this section you find some real-life examples of how to use this switch.
### Change the icon when a state changes
This example demonstrates how to use template to change the icon as its state changes. This icon is referencing its own state.
{% raw %}
```yaml
switch:
- platform: command_line
switches:
driveway_sensor_motion:
friendly_name: Driveway buiten sensor
command_on: >
curl -X PUT -d '{"on":true}' "http://ip_address/api/sensors/27/config/"
command_off: >
curl -X PUT -d '{"on":false}' "http://ip_address/api/sensors/27/config/"
command_state: curl http://ip_address/api/sensors/27/
value_template: >
{{value_json.config.on}}
icon_template: >
{% if value_json.config.on == true %} mdi:toggle-switch
{% else %} mdi:toggle-switch-off
{% endif %}
```
{% endraw %}
### aREST device
The example below is doing the same as the