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
template:
- sensor:
- name: Average temperature
unit_of_measurement: °C
- name: "Average temperature"
unit_of_measurement: "°C"
state: >
{% set bedroom = states.sensor.bedroom_temperature.state | float %}
{% set kitchen = states.sensor.kitchen_temperature.state | float %}
{% set bedroom = states('sensor.bedroom_temperature') | float %}
{% set kitchen = states('sensor.kitchen_temperature') | float %}
{{ ((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
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 %}
```yaml
template:
- binary_sensor:
- name: Has Unavailable States
- name: "Has Unavailable States"
state: "{{ states | selectattr('state', 'in', ['unavailable', 'unknown', 'none']) | list | count }}"
```
{% 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 %}
```yaml
template:
- binary_sensor:
- name: Has Unavailable States
- name: "Has Unavailable States"
state: "{{ states.sensor | selectattr('state', 'in', ['unavailable', 'unknown', 'none']) | list | count }}"
```
@ -423,20 +423,20 @@ template:
- binary_sensor:
- name: My Device
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"
attributes:
latitude: >
{% if is_state('device_tracker.my_device_nmap','home') %}
{{ state_attr('zone.home','latitude') }}
{% if is_state('device_tracker.my_device_nmap', 'home') %}
{{ state_attr('zone.home', 'latitude') }}
{% else %}
{{ state_attr('device_tracker.my_device_gps','latitude') }}
{{ state_attr('device_tracker.my_device_gps', 'latitude') }}
{% endif %}
longitude: >
{% if is_state('device_tracker.my_device_nmap','home') %}
{{ state_attr('zone.home','longitude') }}
{% if is_state('device_tracker.my_device_nmap', 'home') %}
{{ state_attr('zone.home', 'longitude') }}
{% else %}
{{ state_attr('device_tracker.my_device_gps','longitude') }}
{{ state_attr('device_tracker.my_device_gps', 'longitude') }}
{% endif %}
```
@ -479,8 +479,7 @@ binary_sensor:
sensors:
sun_up:
friendly_name: "Sun is up"
value_template: >
{{ state_attr('sun.sun', 'elevation')|float > 0 }}
value_template: {{ state_attr('sun.sun', 'elevation') > 0 }}
```
{% endraw %}

View File

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