Address comments for template integration docs (#17581)

This commit is contained in:
Paulus Schoutsen 2021-04-25 02:51:39 -07:00 committed by GitHub
parent 38ef73da6a
commit df0a4d7cd5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 17 additions and 17 deletions

View File

@ -51,11 +51,11 @@ For example, you can have a template that takes the averages of two sensors. Hom
```yaml ```yaml
template: template:
- sensor: - sensor:
- name: Average temperature - name: "Average temperature"
unit_of_measurement: °C unit_of_measurement: "°C"
state: > state: >
{% set bedroom = states.sensor.bedroom_temperature.state | float %} {% set bedroom = states('sensor.bedroom_temperature') | float %}
{% set kitchen = states.sensor.kitchen_temperature.state | float %} {% set kitchen = states('sensor.kitchen_temperature') | float %}
{{ ((bedroom + kitchen) / 2) | round(1) }} {{ ((bedroom + kitchen) / 2) | round(1) }}
``` ```
@ -207,27 +207,27 @@ time any state changed event happens if any part of the state is accessed. When
is only re-rendered when a state is added or removed from the system. On busy systems with many entities or hundreds of is only re-rendered when a state is added or removed from the system. On busy systems with many entities or hundreds of
thousands state changed events per day, templates may re-render more than desirable. thousands state changed events per day, templates may re-render more than desirable.
In the below example, re-renders are limited to once per minute: In the below example, re-renders are limited to once per minute because we iterate over all available entities:
{% raw %} {% raw %}
```yaml ```yaml
template: template:
- binary_sensor: - binary_sensor:
- name: Has Unavailable States - name: "Has Unavailable States"
state: "{{ states | selectattr('state', 'in', ['unavailable', 'unknown', 'none']) | list | count }}" state: "{{ states | selectattr('state', 'in', ['unavailable', 'unknown', 'none']) | list | count }}"
``` ```
{% endraw %} {% endraw %}
In the below example, re-renders are limited to once per second: In the below example, re-renders are limited to once per second because we iterate over all entities in a single domain (sensor):
{% raw %} {% raw %}
```yaml ```yaml
template: template:
- binary_sensor: - binary_sensor:
- name: Has Unavailable States - name: "Has Unavailable States"
state: "{{ states.sensor | selectattr('state', 'in', ['unavailable', 'unknown', 'none']) | list | count }}" state: "{{ states.sensor | selectattr('state', 'in', ['unavailable', 'unknown', 'none']) | list | count }}"
``` ```
@ -423,20 +423,20 @@ template:
- binary_sensor: - binary_sensor:
- name: My Device - name: My Device
state: > state: >
{{ is_state('device_tracker.my_device_nmap','home') or is_state('device_tracker.my_device_gps','home') }} {{ is_state('device_tracker.my_device_nmap', 'home') or is_state('device_tracker.my_device_gps', 'home') }
device_class: "presence" device_class: "presence"
attributes: attributes:
latitude: > latitude: >
{% if is_state('device_tracker.my_device_nmap','home') %} {% if is_state('device_tracker.my_device_nmap', 'home') %}
{{ state_attr('zone.home','latitude') }} {{ state_attr('zone.home', 'latitude') }}
{% else %} {% else %}
{{ state_attr('device_tracker.my_device_gps','latitude') }} {{ state_attr('device_tracker.my_device_gps', 'latitude') }}
{% endif %} {% endif %}
longitude: > longitude: >
{% if is_state('device_tracker.my_device_nmap','home') %} {% if is_state('device_tracker.my_device_nmap', 'home') %}
{{ state_attr('zone.home','longitude') }} {{ state_attr('zone.home', 'longitude') }}
{% else %} {% else %}
{{ state_attr('device_tracker.my_device_gps','longitude') }} {{ state_attr('device_tracker.my_device_gps', 'longitude') }}
{% endif %} {% endif %}
``` ```
@ -479,8 +479,7 @@ binary_sensor:
sensors: sensors:
sun_up: sun_up:
friendly_name: "Sun is up" friendly_name: "Sun is up"
value_template: > value_template: {{ state_attr('sun.sun', 'elevation') > 0 }}
{{ state_attr('sun.sun', 'elevation')|float > 0 }}
``` ```
{% endraw %} {% endraw %}

View File

@ -1072,6 +1072,7 @@
/integrations/air_quality.xiaomi_miio /integrations/xiaomi_miio /integrations/air_quality.xiaomi_miio /integrations/xiaomi_miio
/integrations/alarm_control_panel.xiaomi_miio /integrations/xiaomi_miio /integrations/alarm_control_panel.xiaomi_miio /integrations/xiaomi_miio
/integrations/binary_sensor.modbus /integrations/modbus /integrations/binary_sensor.modbus /integrations/modbus
/integrations/binary_sensor.template /integrations/template
/integrations/climate.modbus /integrations/modbus /integrations/climate.modbus /integrations/modbus
/integrations/cover.modbus /integrations/modbus /integrations/cover.modbus /integrations/modbus
/integrations/fan.xiaomi_miio /integrations/xiaomi_miio /integrations/fan.xiaomi_miio /integrations/xiaomi_miio