Remove warning and update samples (fixes #767) (#771)

This commit is contained in:
Fabian Affolter 2016-08-12 08:30:05 +02:00 committed by GitHub
parent 89fdc593f0
commit dfe9d13755
3 changed files with 119 additions and 117 deletions

View file

@ -18,14 +18,14 @@ To enable Template sensors in your installation, add the following to your `conf
```yaml
# Example configuration.yaml entry
sensor:
platform: template
sensors:
solar_angle:
value_template: {% raw %}'{{ states.sun.sun.attributes.elevation }}'{% endraw %}
friendly_name: 'Sun angle'
unit_of_measurement: 'degrees'
sunrise:
value_template: {% raw %}'{{ states.sun.sun.attributes.next_rising }}'{% endraw %}
- platform: template
sensors:
solar_angle:
value_template: {% raw %}'{{ states.sun.sun.attributes.elevation }}'{% endraw %}
friendly_name: 'Sun angle'
unit_of_measurement: 'degrees'
sunrise:
value_template: {% raw %}'{{ states.sun.sun.attributes.next_rising }}'{% endraw %}
```
Configuration variables:
@ -34,8 +34,7 @@ Configuration variables:
- **friendly_name** (*Optional*): Name to use in the Frontend.
- **unit_of_measurement** (*Optional*): Defines the units of measurement of the sensor, if any.
- **value_template** (*Optional*): Defines a [template](/topics/templating/) to extract a value from the payload.
- **warnings** (*Optional*): Turn off warnings (useful if the sensor is loaded before devices it depends on).
- **entity_id** (*Optional*): Add a list of entity_ids so the sensor only reacts to state changes of these entities. This will reduce the number of times the sensor will try to update it's state.
- **entity_id** (*Optional*): Add a list of entity IDs so the sensor only reacts to state changes of these entities. This will reduce the number of times the sensor will try to update it's state.
## {% linkable_title Examples %}
@ -48,12 +47,12 @@ This example shows the sun angle in the frontend.
```yaml
sensor:
platform: template
sensors:
solar_angle:
value_template: {% raw %}'{{ "%+.1f"|format(states.sun.sun.attributes.elevation) }}'{% endraw %}
friendly_name: 'Sun Angle'
unit_of_measurement: '°'
- platform: template
sensors:
solar_angle:
value_template: {% raw %}'{{ "%+.1f"|format(states.sun.sun.attributes.elevation) }}'{% endraw %}
friendly_name: 'Sun Angle'
unit_of_measurement: '°'
```
### {% linkable_title Renaming sensor output %}
@ -62,22 +61,22 @@ If you don't like the wording of a sensor output then the template sensor can he
```yaml
sensor:
platform: template
sensors:
sun_state:
value_template: {% raw %}'{% if is_state("sun.sun", "above_horizon") %}up{% else %}down{% endif %}'{% endraw %}
friendly_name: 'Sun state'
- platform: template
sensors:
sun_state:
value_template: {% raw %}'{% if is_state("sun.sun", "above_horizon") %}up{% else %}down{% endif %}'{% endraw %}
friendly_name: 'Sun state'
```
Processes monitored by the [System Monitor sensor](/components/sensor.systemmonitor/) show `on` or `off` if they are running or not. This example shows how the output of a monitored `glances` process can be renamed.
```yaml
sensor:
platform: template
sensors:
glances:
value_template: {% raw %}'{% if is_state("sensor.process_glances", "off") %}not running{% else %}running{% endif %}'{% endraw %}
friendly_name: 'Glances'
- platform: template
sensors:
glances:
value_template: {% raw %}'{% if is_state("sensor.process_glances", "off") %}not running{% else %}running{% endif %}'{% endraw %}
friendly_name: 'Glances'
```
By comparing the details published on the [template](/topics/templating/) page the same can be archived with a different approach:
@ -88,31 +87,34 @@ value_template: {% raw %}"{%if states.sensor.ENTITY_ID.state == 'on' %}running{%
The [Binary template sensor](/components/binary_sensor.template/) is the one in similar cases if you prefer to see an icon instead of text.
### {% linkable_title Multiline example with an if test (and warnings disabled) %}
### {% linkable_title Multiline example with an if test %}
This example shows a multiple line template with and if test. It looks at a sensing switch and shows on/off in the frontend. It disables warnings to avoid log messages where the switch it depends on isn't loaded yet.
This example shows a multiple line template with and if test. It looks at a sensing switch and shows on/off in the frontend.
```yaml
sensor:
platform: template
sensors:
kettle:
friendly_name: 'Kettle'
{% raw %}value_template: >-
{%- if is_state("switch.kettle", "off") %}
off
{% elif states.switch.kettle.attributes.kwh < 1000 %}
standby
{% elif is_state("switch.kettle", "on") %}
on
{% else %}
failed
{%- endif %}{% endraw %}
- platform: template
sensors:
kettle:
friendly_name: 'Kettle'
{% raw %}value_template: >-
{%- if is_state("switch.kettle", "off") %}
off
{% elif states.switch.kettle.attributes.kwh < 1000 %}
standby
{% elif is_state("switch.kettle", "on") %}
on
{% else %}
failed
{%- endif %}{% endraw %}
warnings: Off
next_sensor:
[...]
```
(please note the blank line to close the multi-line template)
<p class='note'>
Please note the blank line to close the multi-line template.
</p>
### {% linkable_title Change the unit of measurment %}
@ -120,15 +122,15 @@ With a template sensor it's easy to convert given values into others if the unit
```yaml
sensor:
platform: template
sensors:
transmission_down_speed_kbps:
value_template: {% raw %}'{{ states.sensor.transmission_down_speed.state | multiply(1024) }}'{% endraw %}
friendly_name: 'Transmission Down Speed'
unit_of_measurement: 'kB/s'
transmission_up_speed_kbps:
value_template: {% raw %}'{{ states.sensor.transmission_up_speed.state | multiply(1024) }}'{% endraw %}
friendly_name: 'Transmission Up Speed'
unit_of_measurement: 'kB/s'
- platform: template
sensors:
transmission_down_speed_kbps:
value_template: {% raw %}'{{ states.sensor.transmission_down_speed.state | multiply(1024) }}'{% endraw %}
friendly_name: 'Transmission Down Speed'
unit_of_measurement: 'kB/s'
transmission_up_speed_kbps:
value_template: {% raw %}'{{ states.sensor.transmission_up_speed.state | multiply(1024) }}'{% endraw %}
friendly_name: 'Transmission Up Speed'
unit_of_measurement: 'kB/s'
```