Rewrites states.xxx -> states('xxx') (and similar) (#9736)

* Rewrites states.xxx -> states('xxx') (and similar)

* Adds template escaping on some places
This commit is contained in:
Franck Nijhof 2019-06-30 20:45:03 +02:00 committed by Paulus Schoutsen
parent 4cdc129f2f
commit 337b210cce
57 changed files with 128 additions and 118 deletions

View File

@ -159,7 +159,7 @@ binary_sensor:
- platform: template - platform: template
sensors: sensors:
motion_battery_low: motion_battery_low:
value_template: '{{ states.sensor.motion.attributes.battery < 15 }}' value_template: '{{ state_attr('sensor.motion', 'battery') < 15 }}'
friendly_name: 'Motion battery is low' friendly_name: 'Motion battery is low'
alert: alert:

View File

@ -32,7 +32,7 @@ binary_sensor:
sun_up: sun_up:
friendly_name: "Sun is up" friendly_name: "Sun is up"
value_template: >- value_template: >-
{{ states.sun.sun.attributes.elevation|float > 0 }} {{ state_attr('sun.sun', 'elevation')|float > 0 }}
``` ```
{% endraw %} {% endraw %}
@ -91,7 +91,7 @@ Template Binary Sensor may get an `unknown` state during startup. This results
in error messages in your log file until that platform has completed loading. in error messages in your log file until that platform has completed loading.
If you use `is_state()` function in your template, you can avoid this situation. If you use `is_state()` function in your template, you can avoid this situation.
For example, you would replace For example, you would replace
{% raw %}`{{ states.switch.source.state == 'on' }}`{% endraw %} {% raw %}`{{ is_state('switch.source', 'on') }}`{% endraw %}
with this equivalent that returns `true`/`false` and never gives an unknown with this equivalent that returns `true`/`false` and never gives an unknown
result: result:
{% raw %}`{{ is_state('switch.source', 'on') }}`{% endraw %} {% raw %}`{{ is_state('switch.source', 'on') }}`{% endraw %}

View File

@ -141,7 +141,7 @@ The requirement is that you have setup the [`xiaomi aqara` component](/component
- service: notify.html5 - service: notify.html5
data_template: data_template:
title: Gas alarm! title: Gas alarm!
message: 'Gas with a density of {% raw %}{{ states.binary_sensor.natgas_sensor_158dxxxxxxxxxx.attributes.density }}{% endraw %} detected.' message: 'Gas with a density of {% raw %}{{ state_attr('binary_sensor.natgas_sensor_158dxxxxxxxxxx', 'density') }}{% endraw %} detected.'
``` ```
#### {% linkable_title Xiaomi Wireless Button %} #### {% linkable_title Xiaomi Wireless Button %}
@ -268,11 +268,11 @@ The Aqara Wireless Switch is available as single-key and double-key version. Eac
entity_id: light.gateway_light_34xxxxxxxx13 entity_id: light.gateway_light_34xxxxxxxx13
data_template: data_template:
brightness: {% raw %}>- brightness: {% raw %}>-
{% if states.light.gateway_light_34xxxxxxxx13.attributes.brightness %} {% if state_attr('light.gateway_light_34xxxxxxxx13', 'brightness') %}
{% if states.light.gateway_light_34xxxxxxxx13.attributes.brightness - 60 >= 10 %} {% if state_attr('light.gateway_light_34xxxxxxxx13', 'brightness') - 60 >= 10 %}
{{states.light.gateway_light_34xxxxxxxx13.attributes.brightness - 60}} {{state_attr('light.gateway_light_34xxxxxxxx13', 'brightness') - 60}}
{% else %} {% else %}
{{states.light.gateway_light_34xxxxxxxx13.attributes.brightness}} {{state_attr('light.gateway_light_34xxxxxxxx13', 'brightness')}}
{% endif %} {% endif %}
{% else %} {% else %}
10 10
@ -290,11 +290,11 @@ The Aqara Wireless Switch is available as single-key and double-key version. Eac
entity_id: light.gateway_light_34xxxxxxxx13 entity_id: light.gateway_light_34xxxxxxxx13
data_template: data_template:
brightness: {% raw %}>- brightness: {% raw %}>-
{% if states.light.gateway_light_34xxxxxxxx13.attributes.brightness %} {% if state_attr('light.gateway_light_34xxxxxxxx13', 'brightness') %}
{% if states.light.gateway_light_34xxxxxxxx13.attributes.brightness + 60 <= 255 %} {% if state_attr('light.gateway_light_34xxxxxxxx13', 'brightness') + 60 <= 255 %}
{{states.light.gateway_light_34xxxxxxxx13.attributes.brightness + 60}} {{state_attr('light.gateway_light_34xxxxxxxx13', 'brightness') + 60}}
{% else %} {% else %}
{{states.light.gateway_light_34xxxxxxxx13.attributes.brightness}} {{state_attr('light.gateway_light_34xxxxxxxx13', 'brightness')}}
{% endif %} {% endif %}
{% else %} {% else %}
10 10

View File

@ -215,6 +215,6 @@ For example, the actions following this condition will only be executed for even
```yaml ```yaml
condition: condition:
condition: template condition: template
value_template: "{{states.calendar.calendar_name.attributes.message == 'vacation' }}" value_template: "{{is_state_attr('calendar.calendar_name', 'message', 'vacation') }}"
``` ```
{% endraw %} {% endraw %}

View File

@ -115,7 +115,7 @@ Template Cover may get an `unknown` state during startup. This results in error
messages in your log file until that platform has completed loading. messages in your log file until that platform has completed loading.
If you use `is_state()` function in your template, you can avoid this situation. If you use `is_state()` function in your template, you can avoid this situation.
For example, you would replace For example, you would replace
{% raw %}`{{ states.switch.source.state == 'on' }}`{% endraw %} {% raw %}`{{ is_state('switch.source', 'on') }}`{% endraw %}
with this equivalent that returns `true`/`false` and never gives an unknown with this equivalent that returns `true`/`false` and never gives an unknown
result: result:
{% raw %}`{{ is_state('switch.source', 'on') }}`{% endraw %} {% raw %}`{{ is_state('switch.source', 'on') }}`{% endraw %}

View File

@ -155,7 +155,7 @@ automation:
data_template: data_template:
entity_id: light.lamp entity_id: light.lamp
brightness: > brightness: >
{% set bri = states.light.lamp.attributes.brightness | int %} {% set bri = state_attr('light.lamp', 'brightness') | int %}
{{ [bri+30, 249] | min }} {{ [bri+30, 249] | min }}
- alias: 'Decrease brightness of lamp from dimmer' - alias: 'Decrease brightness of lamp from dimmer'
@ -171,7 +171,7 @@ automation:
data_template: data_template:
entity_id: light.lamp entity_id: light.lamp
brightness: > brightness: >
{% set bri = states.light.lamp.attributes.brightness | int %} {% set bri = state_attr('light.lamp', 'brightness') | int %}
{{ [bri-30, 0] | max }} {{ [bri-30, 0] | max }}
``` ```

View File

@ -52,7 +52,7 @@ sensor:
platform: template platform: template
sensors: sensors:
next_departure: next_departure:
value_template: '{% raw %}{{ states.sensor.munich_to_ulm.attributes.next }}{% endraw %}' value_template: '{% raw %}{{ state_attr('sensor.munich_to_ulm', 'next') }}{% endraw %}'
friendly_name: 'Next departure' friendly_name: 'Next departure'
``` ```

View File

@ -124,11 +124,11 @@ automation:
{% if is_state("sensor.phone", "idle") %} {% if is_state("sensor.phone", "idle") %}
Phone is idle Phone is idle
{% elif is_state("sensor.phone", "dialing") %} {% elif is_state("sensor.phone", "dialing") %}
Calling {{ states.sensor.phone.attributes.to_name }} ({{ states.sensor.phone.attributes.to }}) Calling {{ state_attr('sensor.phone', 'to_name') }} ({{ state_attr('sensor.phone', 'to') }})
{% elif is_state("sensor.phone", "ringing") %} {% elif is_state("sensor.phone", "ringing") %}
Incoming call from {{ states.sensor.phone.attributes.from_name }} ({{ states.sensor.phone.attributes.from }}) Incoming call from {{ state_attr('sensor.phone', 'from_name') }} ({{ state_attr('sensor.phone', 'from') }})
{% else %} {% else %}
Talking to {{ states.sensor.phone.attributes.with_name }} ({{ states.sensor.phone.attributes.with }}) Talking to {{ state_attr('sensor.phone', 'with_name') }} ({{ state_attr('sensor.phone', 'with') }})
{% endif %} {% endif %}
``` ```
{% endraw %} {% endraw %}

View File

@ -95,13 +95,13 @@ sensor:
sensors: sensors:
garage_door_status: garage_door_status:
friendly_name: 'State of the door' friendly_name: 'State of the door'
value_template: '{{ states.cover.garage_door.state }}' value_template: '{{ states('cover.garage_door') }}'
garage_door_time_in_state: garage_door_time_in_state:
friendly_name: 'Since' friendly_name: 'Since'
value_template: '{{ states.cover.garage_door.attributes.time_in_state }}' value_template: '{{ state_attr('cover.garage_door', 'time_in_state') }}'
garage_door_wifi_signal_strength: garage_door_wifi_signal_strength:
friendly_name: 'WiFi strength' friendly_name: 'WiFi strength'
value_template: '{{ states.cover.garage_door.attributes.wifi_signal_strength }}' value_template: '{{ state_attr('cover.garage_door', 'wifi_signal_strength') }}'
unit_of_measurement: 'dB' unit_of_measurement: 'dB'
group: group:

View File

@ -155,7 +155,7 @@ hangouts:
intent_script: intent_script:
Ping: Ping:
speech: speech:
text: I know {{ states.hangouts.conversations.state }} conversations text: I know {{ states('hangouts.conversations') }} conversations
``` ```
{% endraw %} {% endraw %}

View File

@ -225,10 +225,10 @@ sensor:
- platform: template - platform: template
sensors: sensors:
family_room: family_room:
value_template: '{{ states.remote.family_room.attributes.current_activity }}' value_template: '{{ state_attr('remote.family_room', 'current_activity') }}'
friendly_name: 'Family Room' friendly_name: 'Family Room'
bedroom: bedroom:
value_template: '{{ states.remote.bedroom.attributes.current_activity }}' value_template: '{{ state_attr('remote.bedroom', 'current_activity') }}'
friendly_name: 'bedroom' friendly_name: 'bedroom'
``` ```
{% endraw %} {% endraw %}

View File

@ -210,7 +210,7 @@ sensor:
- platform: template - platform: template
sensors: sensors:
bedroom_valve: bedroom_valve:
value_template: '{% raw %}{{ states.climate.leq123456.attributes.Valve }}{% endraw %}' value_template: '{% raw %}{{ state_attr('climate.leq123456', 'Valve') }}{% endraw %}'
entity_id: climate.leq123456 entity_id: climate.leq123456
friendly_name: 'Bedroom valve' friendly_name: 'Bedroom valve'
``` ```

View File

@ -107,7 +107,7 @@ automation (note that you will need a
automation: automation:
trigger: trigger:
platform: template platform: template
   value_template: "{{ states('sensor.time') == (states.input_datetime.bedroom_alarm_clock_time.attributes.timestamp | int | timestamp_custom('%H:%M', False)) }}"    value_template: "{{ states('sensor.time') == (state_attr('input_datetime.bedroom_alarm_clock_time', 'timestamp') | int | timestamp_custom('%H:%M', False)) }}"
 action:  action:
service: light.turn_on service: light.turn_on
entity_id: light.bedroom entity_id: light.bedroom

View File

@ -225,7 +225,7 @@ automation:
entity_id: switch.something entity_id: switch.something
to: 'on' to: 'on'
action: action:
- delay: '00:{{ states.input_number.minutes.state | int }}:{{ states.input_number.seconds.state | int }}' - delay: '00:{{ states('input_number.minutes') | int }}:{{ states('input_number.seconds') | int }}'
- service: switch.turn_off - service: switch.turn_off
entity_id: switch.something entity_id: switch.something
``` ```

View File

@ -64,7 +64,7 @@ the possibility to show the location of the ISS on OpenStreetMap.
camera: camera:
- platform: generic - platform: generic
name: ISS name: ISS
still_image_url: http://staticmap.openstreetmap.de/staticmap.php?center={{ states.binary_sensor.iss.attributes.lat }},{{ states.binary_sensor.iss.attributes.long }}&zoom=4&size=865x512&maptype=mapnik&markers={{ states.binary_sensor.iss.attributes.lat }},{{ states.binary_sensor.iss.attributes.long }},lightblue still_image_url: http://staticmap.openstreetmap.de/staticmap.php?center={{ state_attr('binary_sensor.iss', 'lat') }},{{ state_attr('binary_sensor.iss', 'long') }}&zoom=4&size=865x512&maptype=mapnik&markers={{ state_attr('binary_sensor.iss', 'lat') }},{{ state_attr('binary_sensor.iss', 'long') }},lightblue
limit_refetch_to_url_change: true limit_refetch_to_url_change: true
``` ```
{% endraw %} {% endraw %}

View File

@ -92,7 +92,7 @@ Template Light may get an `unknown` state during startup. This results
in error messages in your log file until that platform has completed loading. in error messages in your log file until that platform has completed loading.
If you use `is_state()` function in your template, you can avoid this situation. If you use `is_state()` function in your template, you can avoid this situation.
For example, you would replace For example, you would replace
{% raw %}`{{ states.switch.source.state == 'on' }}`{% endraw %} {% raw %}`{{ is_state('switch.source', 'on') }}`{% endraw %}
with this equivalent that returns `true`/`false` and never gives an unknown with this equivalent that returns `true`/`false` and never gives an unknown
result: result:
{% raw %}`{{ is_state('switch.source', 'on') }}`{% endraw %} {% raw %}`{{ is_state('switch.source', 'on') }}`{% endraw %}
@ -118,7 +118,7 @@ light:
friendly_name: "Receiver Volume" friendly_name: "Receiver Volume"
value_template: >- value_template: >-
{% if is_state('media_player.receiver', 'on') %} {% if is_state('media_player.receiver', 'on') %}
{% if states.media_player.receiver.attributes.is_volume_muted %} {% if state_attr('media_player.receiver', 'is_volume_muted') %}
off off
{% else %} {% else %}
on on
@ -143,7 +143,7 @@ light:
volume_level: "{{ (brightness / 255 * 100)|int / 100 }}" volume_level: "{{ (brightness / 255 * 100)|int / 100 }}"
level_template: >- level_template: >-
{% if is_state('media_player.receiver', 'on') %} {% if is_state('media_player.receiver', 'on') %}
{{ (states.media_player.receiver.attributes.volume_level|float * 255)|int }} {{ (state_attr('media_player.receiver', 'volume_level')|float * 255)|int }}
{% else %} {% else %}
0 0
{% endif %} {% endif %}
@ -163,7 +163,7 @@ light:
friendly_name: "Receiver Volume" friendly_name: "Receiver Volume"
value_template: >- value_template: >-
{% if is_state('media_player.receiver', 'on') %} {% if is_state('media_player.receiver', 'on') %}
{% if states.media_player.receiver.attributes.is_volume_muted %} {% if state_attr('media_player.receiver', 'is_volume_muted') %}
off off
{% else %} {% else %}
on on
@ -173,7 +173,7 @@ light:
{% endif %} {% endif %}
icon_template: >- icon_template: >-
{% if is_state('media_player.receiver', 'on') %} {% if is_state('media_player.receiver', 'on') %}
{% if states.media_player.receiver.attributes.is_volume_muted %} {% if state_attr('media_player.receiver', 'is_volume_muted') %}
mdi:lightbulb-off mdi:lightbulb-off
{% else %} {% else %}
mdi:lightbulb-on mdi:lightbulb-on
@ -207,7 +207,7 @@ light:
friendly_name: "Receiver Volume" friendly_name: "Receiver Volume"
value_template: >- value_template: >-
{% if is_state('media_player.receiver', 'on') %} {% if is_state('media_player.receiver', 'on') %}
{% if states.media_player.receiver.attributes.is_volume_muted %} {% if state_attr('media_player.receiver', 'is_volume_muted') %}
off off
{% else %} {% else %}
on on
@ -217,7 +217,7 @@ light:
{% endif %} {% endif %}
icon_template: >- icon_template: >-
{% if is_state('media_player.receiver', 'on') %} {% if is_state('media_player.receiver', 'on') %}
{% if states.media_player.receiver.attributes.is_volume_muted %} {% if state_attr('media_player.receiver', 'is_volume_muted') %}
/local/lightbulb-off.png /local/lightbulb-off.png
{% else %} {% else %}
/local/lightbulb-on.png /local/lightbulb-on.png

View File

@ -72,7 +72,7 @@ lock:
## {% linkable_title Considerations %} ## {% linkable_title Considerations %}
If you are using the state of a platform that takes extra time to load, the Template Lock may get an `unknown` state during startup. This results in error messages in your log file until that platform has completed loading. If you use `is_state()` function in your template, you can avoid this situation. For example, you would replace {% raw %}`{{ states.switch.source.state == 'on' }}`{% endraw %} with this equivalent that returns `true`/`false` and never gives an unknown result: {% raw %}`{{ is_state('switch.source', 'on') }}`{% endraw %} If you are using the state of a platform that takes extra time to load, the Template Lock may get an `unknown` state during startup. This results in error messages in your log file until that platform has completed loading. If you use `is_state()` function in your template, you can avoid this situation. For example, you would replace {% raw %}`{{ is_state('switch.source', 'on') }}`{% endraw %} with this equivalent that returns `true`/`false` and never gives an unknown result: {% raw %}`{{ is_state('switch.source', 'on') }}`{% endraw %}
## {% linkable_title Examples %} ## {% linkable_title Examples %}

View File

@ -72,11 +72,11 @@ To explore the data available within the `data` attribute of a sensor use the `d
sensors: sensors:
updated: updated:
friendly_name: 'Updated' friendly_name: 'Updated'
value_template: {% raw %}'{{states.sensor.merton.attributes.updated}}'{% endraw %} value_template: {% raw %}'{{state_attr('sensor.merton', 'updated')}}'{% endraw %}
merton_pm10: merton_pm10:
friendly_name: 'Merton PM10' friendly_name: 'Merton PM10'
value_template: {% raw %}'{{states.sensor.merton.attributes.data[0].pollutants[0].summary}}'{% endraw %} value_template: {% raw %}'{{state_attr('sensor.merton', 'data')[0].pollutants[0].summary}}'{% endraw %}
westminster_s02: westminster_s02:
friendly_name: 'Westminster S02' friendly_name: 'Westminster S02'
value_template: {% raw %}'{{states.sensor.westminster.attributes.data[0].pollutants[3].summary}}'{% endraw %} value_template: {% raw %}'{{state_attr('sensor.westminster', 'data')[0].pollutants[3].summary}}'{% endraw %}
``` ```

View File

@ -23,9 +23,9 @@ This sensor is an alternative to the [template sensor](/components/sensor.templa
{% raw %} {% raw %}
```yaml ```yaml
{{ ((float(states.sensor.kitchen_temperature.state) + {{ ((float(states('sensor.kitchen_temperature')) +
float(states.sensor.living_room_temperature.state) + float(states('sensor.living_room_temperature')) +
float(states.sensor.office_temperature.state)) / 3) | round(2) float(states('sensor.office_temperature'))) / 3) | round(2)
}} }}
``` ```
{% endraw %} {% endraw %}

View File

@ -83,7 +83,7 @@ automation:
action: action:
service: notify.notify service: notify.notify
data: data:
message: 'Call from {{ states.sensor.modem_callerid.attributes.cid_name }} at {{ states.sensor.modem_callerid.attributes.cid_number }} ' message: 'Call from {{ state_attr('sensor.modem_callerid', 'cid_name') }} at {{ state_attr('sensor.modem_callerid', 'cid_number') }} '
- alias: Notify CallerID webui - alias: Notify CallerID webui
trigger: trigger:
platform: state platform: state
@ -93,7 +93,7 @@ automation:
service: persistent_notification.create service: persistent_notification.create
data: data:
title: "Call from" title: "Call from"
message: '{{ states.sensor.modem_callerid.attributes.cid_time.strftime("%I:%M %p") }} {{ states.sensor.modem_callerid.attributes.cid_name }} {{ states.sensor.modem_callerid.attributes.cid_number }} ' message: '{{ state_attr('sensor.modem_callerid', 'cid_time').strftime("%I:%M %p") }} {{ state_attr('sensor.modem_callerid', 'cid_name') }} {{ state_attr('sensor.modem_callerid', 'cid_number') }} '
- alias: Say CallerID - alias: Say CallerID
trigger: trigger:
platform: state platform: state
@ -102,6 +102,6 @@ automation:
action: action:
service: tts.google_say service: tts.google_say
data_template: data_template:
message: 'Call from {{ states.sensor.modem_callerid.attributes.cid_name }}' message: 'Call from {{ state_attr('sensor.modem_callerid', 'cid_name') }}'
``` ```
{% endraw %} {% endraw %}

View File

@ -93,5 +93,5 @@ sensor:
``` ```
The first sensor will return S-Bahn departures to Munich Airport or Markt Schwaben that are at least 2 minutes away. The first sensor will return S-Bahn departures to Munich Airport or Markt Schwaben that are at least 2 minutes away.
The second sensor returns U2 and U8 departures from Sendlinger Tor and stores a total of 5 departures in attributes. To retrieve the time until the second departure, you would use states.sensor.ENTITY_NAME.attributes.departures[1].time. The second sensor returns U2 and U8 departures from Sendlinger Tor and stores a total of 5 departures in attributes. To retrieve the time until the second departure, you would use state_attr('sensor.ENTITY_NAME', 'departures')[1].time.
The third sensor returns all south-bound U-Bahn trains from Scheidplatz. The third sensor returns all south-bound U-Bahn trains from Scheidplatz.

View File

@ -218,6 +218,6 @@ sensor:
power: power:
friendly_name: "Current Power" friendly_name: "Current Power"
unit_of_measurement: "W" unit_of_measurement: "W"
value_template: "{{ states.switch.office.attributes.current_power_w }}" value_template: "{{ state_attr('switch.office', 'current_power_w') }}"
``` ```
{% endraw %} {% endraw %}

View File

@ -105,7 +105,7 @@ sensor:
garage_car_present: garage_car_present:
friendly_name: 'Honda in Garage' friendly_name: 'Honda in Garage'
value_template: {% raw %}'{% if states.cover.honda %} value_template: {% raw %}'{% if states.cover.honda %}
{% if states.cover.honda.state == "open" %} {% if is_state('cover.honda', 'open') %}
n/a n/a
{% elif ((states.cover.honda.attributes["distance_sensor"] > 40) and (states.cover.honda.attributes["distance_sensor"] < 100)) %} {% elif ((states.cover.honda.attributes["distance_sensor"] > 40) and (states.cover.honda.attributes["distance_sensor"] < 100)) %}
Yes Yes

View File

@ -60,19 +60,19 @@ sensor:
- platform: template - platform: template
sensors: sensors:
power_consumption: power_consumption:
value_template: {% raw %}'{% if is_state_attr("sensor.pvoutput", "power_consumption", "NaN") %}0{% else %}{{ states.sensor.pvoutput.attributes.power_consumption }}{% endif %}'{% endraw %} value_template: {% raw %}'{% if is_state_attr("sensor.pvoutput", "power_consumption", "NaN") %}0{% else %}{{ state_attr('sensor.pvoutput', 'power_consumption') }}{% endif %}'{% endraw %}
friendly_name: 'Using' friendly_name: 'Using'
unit_of_measurement: 'Watt' unit_of_measurement: 'Watt'
energy_consumption: energy_consumption:
value_template: {% raw %}'{{ "%0.1f"|format(states.sensor.pvoutput.attributes.energy_consumption|float/1000) }}'{% endraw %} value_template: {% raw %}'{{ "%0.1f"|format(state_attr('sensor.pvoutput', 'energy_consumption')|float/1000) }}'{% endraw %}
friendly_name: 'Used' friendly_name: 'Used'
unit_of_measurement: 'kWh' unit_of_measurement: 'kWh'
power_generation: power_generation:
value_template: {% raw %}'{% if is_state_attr("sensor.pvoutput", "power_generation", "NaN") %}0{% else %}{{ states.sensor.pvoutput.attributes.power_generation }}{% endif %}'{% endraw %} value_template: {% raw %}'{% if is_state_attr("sensor.pvoutput", "power_generation", "NaN") %}0{% else %}{{ state_attr('sensor.pvoutput', 'power_generation') }}{% endif %}'{% endraw %}
friendly_name: 'Generating' friendly_name: 'Generating'
unit_of_measurement: 'Watt' unit_of_measurement: 'Watt'
energy_generation: energy_generation:
value_template: {% raw %}'{% if is_state_attr("sensor.pvoutput", "energy_generation", "NaN") %}0{% else %}{{ "%0.2f"|format(states.sensor.pvoutput.attributes.energy_generation|float/1000) }}{% endif %}'{% endraw %} value_template: {% raw %}'{% if is_state_attr("sensor.pvoutput", "energy_generation", "NaN") %}0{% else %}{{ "%0.2f"|format(state_attr('sensor.pvoutput', 'energy_generation')|float/1000) }}{% endif %}'{% endraw %}
friendly_name: 'Generated' friendly_name: 'Generated'
unit_of_measurement: 'kWh' unit_of_measurement: 'kWh'
``` ```

View File

@ -263,22 +263,22 @@ sensor:
- platform: template - platform: template
sensors: sensors:
owm_weather: owm_weather:
value_template: '{{ states.sensor.owm_report.attributes.weather[0]["description"].title() }}' value_template: '{{ state_attr('sensor.owm_report', 'weather')[0]["description"].title() }}'
entity_picture_template: '{{ "http://openweathermap.org/img/w/"+states.sensor.owm_report.attributes.weather[0]["icon"].lower()+".png" }}' entity_picture_template: '{{ "http://openweathermap.org/img/w/"+state_attr('sensor.owm_report', 'weather')[0]["icon"].lower()+".png" }}'
entity_id: sensor.owm_report entity_id: sensor.owm_report
owm_temp: owm_temp:
friendly_name: 'Outside temp' friendly_name: 'Outside temp'
value_template: '{{ states.sensor.owm_report.attributes.main["temp"]-273.15 }}' value_template: '{{ state_attr('sensor.owm_report', 'main')["temp"]-273.15 }}'
unit_of_measurement: "°C" unit_of_measurement: "°C"
entity_id: sensor.owm_report entity_id: sensor.owm_report
owm_pressure: owm_pressure:
friendly_name: 'Outside pressure' friendly_name: 'Outside pressure'
value_template: '{{ states.sensor.owm_report.attributes.main["pressure"] }}' value_template: '{{ state_attr('sensor.owm_report', 'main')["pressure"] }}'
unit_of_measurement: "hP" unit_of_measurement: "hP"
entity_id: sensor.owm_report entity_id: sensor.owm_report
owm_humidity: owm_humidity:
friendly_name: 'Outside humidity' friendly_name: 'Outside humidity'
value_template: '{{ states.sensor.owm_report.attributes.main["humidity"] }}' value_template: '{{ state_attr('sensor.owm_report', 'main')["humidity"] }}'
unit_of_measurement: "%" unit_of_measurement: "%"
entity_id: sensor.owm_report entity_id: sensor.owm_report
``` ```

View File

@ -118,14 +118,16 @@ downloader:
Then you can use the following `action` in your automation (this will save the video file under `<config>/downloads/ring_<camera_name>/`): Then you can use the following `action` in your automation (this will save the video file under `<config>/downloads/ring_<camera_name>/`):
{% raw %}
```yaml ```yaml
action: action:
- service: downloader.download_file - service: downloader.download_file
data_template: data_template:
url: "{{ states.camera.front_door.attributes.video_url }}" url: "{{ state_attr('camera.front_door', 'video_url') }}"
subdir: "{{states.camera.front_door.attributes.friendly_name}}" subdir: "{{state_attr('camera.front_door', 'friendly_name')}}"
filename: "{{states.camera.front_door.attributes.friendly_name}}" filename: "{{state_attr('camera.front_door', 'friendly_name')}}"
``` ```
{% endraw %}
If you want to use `python_script`, enable it your `configuration.yaml` file first: If you want to use `python_script`, enable it your `configuration.yaml` file first:

View File

@ -118,6 +118,6 @@ sensor:
The first sensor will return S-Bahn, bus, RB and RE trains departures from Frankfurt Hauptbahnhof to Frankfurt Airport or Stadium that are at least 5 minutes away. The first sensor will return S-Bahn, bus, RB and RE trains departures from Frankfurt Hauptbahnhof to Frankfurt Airport or Stadium that are at least 5 minutes away.
The second sensor returns bus departures from Wiesbaden Hauptbahnhof going to Dernsches Gelände and Mainz Hauptbahnhof. To retrieve the time of the second departure, you would use `states.sensor.ENTITY_NAME.attributes.departures[1].time`. The second sensor returns bus departures from Wiesbaden Hauptbahnhof going to Dernsches Gelände and Mainz Hauptbahnhof. To retrieve the time of the second departure, you would use `state_attr('sensor.ENTITY_NAME', 'departures')[1].time`.
The third sensor returns all S-Bahn trains from Mainz Hauptbahnhof for line S8. The third sensor returns all S-Bahn trains from Mainz Hauptbahnhof for line S8.

View File

@ -98,9 +98,9 @@ automation:
at: '19:00:00' at: '19:00:00'
condition: condition:
- condition: template - condition: template
value_template: "{% if (as_timestamp(states.sensor.rova_garbage_gft.state) - as_timestamp(now())) < 43200 %}true{% endif %}" value_template: "{% if (as_timestamp(states('sensor.rova_garbage_gft')) - as_timestamp(now())) < 43200 %}true{% endif %}"
- condition: template - condition: template
value_template: "{% if (as_timestamp(states.sensor.rova_garbage_gft.state) - as_timestamp(now())) > 0 %}true{% endif %}" value_template: "{% if (as_timestamp(states('sensor.rova_garbage_gft')) - as_timestamp(now())) > 0 %}true{% endif %}"
action: action:
- service: NOTIFICATION_SERVICE - service: NOTIFICATION_SERVICE
data: data:

View File

@ -28,7 +28,7 @@ rss_feed_template:
title: "Garden {% raw %}{{ as_timestamp(now())|timestamp_custom('%H:%M', True) }}{% endraw %}" title: "Garden {% raw %}{{ as_timestamp(now())|timestamp_custom('%H:%M', True) }}{% endraw %}"
items: items:
- title: "Outside temperature" - title: "Outside temperature"
description: "{% raw %}{% if is_state('sensor.temp_outside','unknown') %}---{% else %}{{states.sensor.temp_outside.state}} °C{% endif %}{% endraw %}" description: "{% raw %}{% if is_state('sensor.temp_outside','unknown') %}---{% else %}{{states('sensor.temp_outside')}} °C{% endif %}{% endraw %}"
``` ```
{% configuration %} {% configuration %}

View File

@ -26,7 +26,7 @@ script:
# This is Home Assistant Script Syntax # This is Home Assistant Script Syntax
- service: notify.notify - service: notify.notify
data_template: data_template:
         message: Current temperature is {% raw %}{{ states.sensor.temperature.state }}{% endraw %}          message: Current temperature is {% raw %}{{ states('sensor.temperature') }}{% endraw %}
``` ```
<p class='note'> <p class='note'>
Script names (e.g., `message_temperature` in the example above) are not allowed to contain capital letters, or dash (minus) characters, i.e. `-`. The preferred way to separate words for better readability is to use underscore (`_`) characters. Script names (e.g., `message_temperature` in the example above) are not allowed to contain capital letters, or dash (minus) characters, i.e. `-`. The preferred way to separate words for better readability is to use underscore (`_`) characters.

View File

@ -96,13 +96,13 @@ sensor:
- platform: template - platform: template
sensors: sensors:
sensehat_temperature: sensehat_temperature:
value_template: '{{ states.sensor.temperature.state | round(1) }}' value_template: '{{ states('sensor.temperature') | round(1) }}'
unit_of_measurement: '°C' unit_of_measurement: '°C'
sensehat_pressure: sensehat_pressure:
value_template: '{{ states.sensor.pressure.state | round(1) }}' value_template: '{{ states('sensor.pressure') | round(1) }}'
unit_of_measurement: 'mb' unit_of_measurement: 'mb'
sensehat_humidity: sensehat_humidity:
value_template: '{{ states.sensor.humidity.state | round(1) }}' value_template: '{{ states('sensor.humidity') | round(1) }}'
unit_of_measurement: '%' unit_of_measurement: '%'
``` ```

View File

@ -185,7 +185,7 @@ sensor:
sensor: sensor:
- platform: command_line - platform: command_line
name: wind direction name: wind direction
command: 'sh /home/pi/.homeassistant/scripts/wind_direction.sh {{ states.sensor.wind_direction.state }}' command: 'sh /home/pi/.homeassistant/scripts/wind_direction.sh {{ states('sensor.wind_direction') }}'
unit_of_measurement: "Direction" unit_of_measurement: "Direction"
``` ```
{% endraw %} {% endraw %}

View File

@ -146,7 +146,7 @@ sensor:
- platform: template - platform: template
sensors: sensors:
power_meter: power_meter:
value_template: '{{ states.image_processing.sevensegment_ocr_seven_segments.state }}' value_template: '{{ states('image_processing.sevensegment_ocr_seven_segments') }}'
friendly_name: 'Ampere' friendly_name: 'Ampere'
unit_of_measurement: 'A' unit_of_measurement: 'A'
``` ```

View File

@ -61,6 +61,6 @@ input_number:
{% raw %} {% raw %}
shell_command: shell_command:
set_ac_to_slider: 'irsend SEND_ONCE DELONGHI AC_{{ states.input_number.ac_temperature.state }}_AUTO' set_ac_to_slider: 'irsend SEND_ONCE DELONGHI AC_{{ states('input_number.ac_temperature') }}_AUTO'
{% endraw %} {% endraw %}
``` ```

View File

@ -131,6 +131,6 @@ sensors:
platform: template platform: template
sensors: sensors:
solaredge_energy_this_year_template: solaredge_energy_this_year_template:
value_template: '{{(states.sensor.solaredge_energy_this_year.state | float / 1000) | round(2)}}' value_template: '{{(states('sensor.solaredge_energy_this_year') | float / 1000) | round(2)}}'
``` ```
{% endraw %} {% endraw %}

View File

@ -69,6 +69,6 @@ sensors:
platform: template platform: template
sensors: sensors:
solaredge_energy_this_year_template: solaredge_energy_this_year_template:
value_template: '{{(states.sensor.solaredge_energy_this_year.state | float / 1000) | round(2)}}' value_template: '{{(states('sensor.solaredge_energy_this_year') | float / 1000) | round(2)}}'
``` ```
{% endraw %} {% endraw %}

View File

@ -108,4 +108,4 @@ switch:
``` ```
{% 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.state}}}'{% 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 %}`.

View File

@ -82,7 +82,7 @@ switch:
## {% linkable_title Considerations %} ## {% linkable_title Considerations %}
If you are using the state of a platform that takes extra time to load, the Template Switch may get an `unknown` state during startup. This results in error messages in your log file until that platform has completed loading. If you use `is_state()` function in your template, you can avoid this situation. For example, you would replace {% raw %}`{{ states.switch.source.state == 'on' }}`{% endraw %} with this equivalent that returns `true`/`false` and never gives an unknown result: {% raw %}`{{ is_state('switch.source', 'on') }}`{% endraw %} If you are using the state of a platform that takes extra time to load, the Template Switch may get an `unknown` state during startup. This results in error messages in your log file until that platform has completed loading. If you use `is_state()` function in your template, you can avoid this situation. For example, you would replace {% raw %}`{{ is_state('switch.source', 'on') }}`{% endraw %} with this equivalent that returns `true`/`false` and never gives an unknown result: {% raw %}`{{ is_state('switch.source', 'on') }}`{% endraw %}
## {% linkable_title Examples %} ## {% linkable_title Examples %}

View File

@ -85,7 +85,7 @@ sensor:
### {% linkable_title Startup %} ### {% linkable_title Startup %}
If you are using the state of a platform that takes extra time to load, the Template Sensor may get an `unknown` state during startup. To avoid this (and the resulting error messages in your log file), you can use `is_state()` function in your template. For example, you would replace {% raw %}`{{ states.switch.source.state == 'on' }}`{% endraw %} with this equivalent that returns `true`/`false` and never gives an `unknown` result: If you are using the state of a platform that takes extra time to load, the Template Sensor may get an `unknown` state during startup. To avoid this (and the resulting error messages in your log file), you can use `is_state()` function in your template. For example, you would replace {% raw %}`{{ is_state('switch.source', 'on') }}`{% endraw %} with this equivalent that returns `true`/`false` and never gives an `unknown` result:
{% raw %}`{{ is_state('switch.source', 'on') }}`{% endraw %} {% raw %}`{{ is_state('switch.source', 'on') }}`{% endraw %}

View File

@ -25,7 +25,7 @@ It's an alternative to the template binary sensor's `value_template:` to get the
{% raw %} {% raw %}
```yaml ```yaml
{{ states.sensor.furnace.state > 2.5 }} {{ states('sensor.furnace') > 2.5 }}
``` ```
{% endraw %} {% endraw %}

View File

@ -90,13 +90,13 @@ The electricity price can be used to make automations. The sensor has a `max_pri
minutes: 1 minutes: 1
condition: condition:
condition: template condition: template
value_template: '{{ float(states.sensor.electricity_price_hamretunet_10.state) > 0.9 * float(states.sensor.electricity_price_hamretunet_10.attributes.max_price) }}' value_template: '{{ float(states('sensor.electricity_price_hamretunet_10')) > 0.9 * float(state_attr('sensor.electricity_price_hamretunet_10', 'max_price')) }}'
action: action:
- service: notify.pushbullet - service: notify.pushbullet
data: data:
title: "Electricity price" title: "Electricity price"
target: "device/daniel_telefon_cat" target: "device/daniel_telefon_cat"
message: "The electricity price is now {{ states.sensor.electricity_price_hamretunet_10.state }}" message: "The electricity price is now {{ states('sensor.electricity_price_hamretunet_10') }}"
``` ```
{% endraw %} {% endraw %}

View File

@ -100,7 +100,7 @@ The sensor returns n/a if no stop event is found within the next 24h. A `templat
{% if is_state_attr('sensor.bus', 'due', 'n/a') %} {% if is_state_attr('sensor.bus', 'due', 'n/a') %}
No schedule found No schedule found
{% else %} {% else %}
{{ states.sensor.bus.attributes.route }} in {{ states.sensor.bus.attributes.due }}m ({{ states.sensor.bus.attributes.delay }}) {{ state_attr('sensor.bus', 'route') }} in {{ state_attr('sensor.bus', 'due') }}m ({{ state_attr('sensor.bus', 'delay') }})
{% endif %} {% endif %}
``` ```
{% endraw %} {% endraw %}

View File

@ -90,19 +90,19 @@ Attributes can be accessed using the [template sensor](/components/sensor.templa
sensors: sensors:
next_train_status: next_train_status:
friendly_name: 'Next train status' friendly_name: 'Next train status'
value_template: {% raw %}'{{states.sensor.next_train_to_wat.attributes.next_trains[0].status}}'{% endraw %} value_template: {% raw %}'{{state_attr('sensor.next_train_to_wat', 'next_trains')[0].status}}'{% endraw %}
next_trains_origin: next_trains_origin:
friendly_name: 'Next train origin' friendly_name: 'Next train origin'
value_template: {% raw %}'{{states.sensor.next_train_to_wat.attributes.next_trains[0].origin_name}}'{% endraw %} value_template: {% raw %}'{{state_attr('sensor.next_train_to_wat', 'next_trains')[0].origin_name}}'{% endraw %}
next_trains_estimated: next_trains_estimated:
friendly_name: 'Next train estimated' friendly_name: 'Next train estimated'
value_template: {% raw %}'{{states.sensor.next_train_to_wat.attributes.next_trains[0].estimated}}'{% endraw %} value_template: {% raw %}'{{state_attr('sensor.next_train_to_wat', 'next_trains')[0].estimated}}'{% endraw %}
next_trains_scheduled: next_trains_scheduled:
friendly_name: 'Next train scheduled' friendly_name: 'Next train scheduled'
value_template: {% raw %}'{{states.sensor.next_train_to_wat.attributes.next_trains[0].scheduled}}'{% endraw %} value_template: {% raw %}'{{state_attr('sensor.next_train_to_wat', 'next_trains')[0].scheduled}}'{% endraw %}
next_trains_platform: next_trains_platform:
friendly_name: 'Next train platform' friendly_name: 'Next train platform'
value_template: {% raw %}'{{states.sensor.next_train_to_wat.attributes.next_trains[0].platform}}'{% endraw %} value_template: {% raw %}'{{state_attr('sensor.next_train_to_wat', 'next_trains')[0].platform}}'{% endraw %}
``` ```
Bus sensors require as their `origin` a bus stop ATCO code which can be found by browsing OpenStreetMap data as Bus sensors require as their `origin` a bus stop ATCO code which can be found by browsing OpenStreetMap data as
@ -138,16 +138,16 @@ And the template sensor for viewing the next bus attributes.
sensors: sensors:
next_bus_route: next_bus_route:
friendly_name: 'Next bus route' friendly_name: 'Next bus route'
value_template: {% raw %}'{{states.sensor.next_bus_to_wantage.attributes.next_buses[0].route}}'{% endraw %} value_template: {% raw %}'{{state_attr('sensor.next_bus_to_wantage', 'next_buses')[0].route}}'{% endraw %}
next_bus_direction: next_bus_direction:
friendly_name: 'Next bus direction' friendly_name: 'Next bus direction'
value_template: {% raw %}'{{states.sensor.next_bus_to_wantage.attributes.next_buses[0].direction}}'{% endraw %} value_template: {% raw %}'{{state_attr('sensor.next_bus_to_wantage', 'next_buses')[0].direction}}'{% endraw %}
next_bus_scheduled: next_bus_scheduled:
friendly_name: 'Next bus scheduled' friendly_name: 'Next bus scheduled'
value_template: {% raw %}'{{states.sensor.next_bus_to_wantage.attributes.next_buses[0].scheduled}}'{% endraw %} value_template: {% raw %}'{{state_attr('sensor.next_bus_to_wantage', 'next_buses')[0].scheduled}}'{% endraw %}
next_bus_estimated: next_bus_estimated:
friendly_name: 'Next bus estimated' friendly_name: 'Next bus estimated'
value_template: {% raw %}'{{states.sensor.next_bus_to_wantage.attributes.next_buses[0].estimated}}'{% endraw %} value_template: {% raw %}'{{state_attr('sensor.next_bus_to_wantage', 'next_buses')[0].estimated}}'{% endraw %}
``` ```
## {% linkable_title Managing API requests %} ## {% linkable_title Managing API requests %}

View File

@ -119,6 +119,7 @@ Start the cleaning operation in the areas selected for the number of repeats ind
Example of `vacuum.xiaomi_clean_zone` use: Example of `vacuum.xiaomi_clean_zone` use:
Inline array: Inline array:
{% raw %}
```yaml ```yaml
automation: automation:
- alias: Test vacuum zone3 - alias: Test vacuum zone3
@ -130,10 +131,13 @@ automation:
- service: vacuum.xiaomi_clean_zone - service: vacuum.xiaomi_clean_zone
data_template: data_template:
entity_id: vacuum.xiaomi_vacuum entity_id: vacuum.xiaomi_vacuum
repeats: '{{states.input_number.vacuum_passes.state|int}}' repeats: '{{states('input_number.vacuum_passes')|int}}'
zone: [[30914,26007,35514,28807], [20232,22496,26032,26496]] zone: [[30914,26007,35514,28807], [20232,22496,26032,26496]]
``` ```
{% endraw %}
Array with inline zone: Array with inline zone:
{% raw %}
```yaml ```yaml
automation: automation:
- alias: Test vacuum zone3 - alias: Test vacuum zone3
@ -145,11 +149,13 @@ automation:
- service: vacuum.xiaomi_clean_zone - service: vacuum.xiaomi_clean_zone
data_template: data_template:
entity_id: vacuum.xiaomi_vacuum entity_id: vacuum.xiaomi_vacuum
repeats: '{{states.input_number.vacuum_passes.state|int}}' repeats: '{{states('input_number.vacuum_passes')|int}}'
zone: zone:
- [30914,26007,35514,28807] - [30914,26007,35514,28807]
- [20232,22496,26032,26496] - [20232,22496,26032,26496]
``` ```
{% endraw %}
Array mode: Array mode:
```yaml ```yaml
automation: automation:

View File

@ -202,6 +202,7 @@ icon:
A possible automation could be: A possible automation could be:
{% raw %}
```yaml ```yaml
# Example configuration.yaml entry # Example configuration.yaml entry
automation: automation:
@ -213,8 +214,9 @@ automation:
action: action:
service: notify.livingroom_tv service: notify.livingroom_tv
data: data:
message: "You should open a window! (Livingroom Co2: {{ states.sensor.netatmo_livingroom_co2.state }}ppm)" message: "You should open a window! (Livingroom Co2: {{ states('sensor.netatmo_livingroom_co2') }}ppm)"
``` ```
{% endraw %}
The icon can be overridden for individual notifications by providing a path to an alternative icon image to use: The icon can be overridden for individual notifications by providing a path to an alternative icon image to use:

View File

@ -73,16 +73,16 @@ automation:
- condition: numeric_state - condition: numeric_state
entity_id: light.livingroom_ec entity_id: light.livingroom_ec
# if light is off, force a 0, otherwise use the brightness value # if light is off, force a 0, otherwise use the brightness value
value_template: {% raw %}'{% if states.light.livingroom_ec.state == "on" %}{{ states.light.livingroom_ec.attributes.brightness }}{% else %}0{% endif %}'{% endraw %} value_template: {% raw %}'{% if is_state('light.livingroom_ec', 'on') %}{{ state_attr('light.livingroom_ec', 'brightness') }}{% else %}0{% endif %}'{% endraw %}
# brightness below 50% (255 = 100%) # brightness below 50% (255 = 100%)
below: 128 below: 128
- condition: numeric_state - condition: numeric_state
entity_id: light.kitchen_bar entity_id: light.kitchen_bar
value_template: {% raw %}'{% if states.light.kitchen_bar.state == "on" %}{{ states.light.kitchen_bar.attributes.brightness }}{% else %}0{% endif %}'{% endraw %} value_template: {% raw %}'{% if is_state('light.kitchen_bar', 'on') %}{{ state_attr('light.kitchen_bar', 'brightness') }}{% else %}0{% endif %}'{% endraw %}
below: 128 below: 128
- condition: numeric_state - condition: numeric_state
entity_id: light.kitchen_ceiling entity_id: light.kitchen_ceiling
value_template: {% raw %}'{% if states.light.kitchen_ceiling.state == "on" %}{{ states.light.kitchen_ceiling.attributes.brightness }}{% else %}0{% endif %}'{% endraw %} value_template: {% raw %}'{% if is_state('light.kitchen_ceiling', 'on') %}{{ state_attr('light.kitchen_ceiling', 'brightness') }}{% else %}0{% endif %}'{% endraw %}
below: 128 below: 128
# Trigger a scene # Trigger a scene

View File

@ -115,7 +115,7 @@ script:
data_template: data_template:
entity_id: light.YOUR_LIGHT entity_id: light.YOUR_LIGHT
brightness: >- brightness: >-
{% raw %}{% set current = states.light.YOUR_LIGHT.attributes.brightness|default(0)|int %} {% raw %}{% set current = state_attr('light.YOUR_LIGHT', 'brightness')|default(0)|int %}
{% set step = states('input_number.light_step')|int %} {% set step = states('input_number.light_step')|int %}
{% set next = current + step %} {% set next = current + step %}
{% if next > states('input_number.light_maximum')|int %} {% if next > states('input_number.light_maximum')|int %}
@ -124,7 +124,7 @@ script:
{{ next }}{% endraw %} {{ next }}{% endraw %}
- service_template: > - service_template: >
{% raw %}{% if states.light.YOUR_LIGHT.attributes.brightness|default(0)|int < states('input_number.light_maximum')|int %} {% raw %}{% if state_attr('light.YOUR_LIGHT', 'brightness')|default(0)|int < states('input_number.light_maximum')|int %}
script.turn_on script.turn_on
{% else %} {% else %}
script.turn_off script.turn_off
@ -146,7 +146,7 @@ script:
data_template: data_template:
entity_id: light.YOUR_LIGHT entity_id: light.YOUR_LIGHT
brightness: >- brightness: >-
{% raw %}{% set current = states.light.YOUR_LIGHT.attributes.brightness|default(0)|int %} {% raw %}{% set current = state_attr('light.YOUR_LIGHT', 'brightness')|default(0)|int %}
{% set step = states('input_number.light_step')|int %} {% set step = states('input_number.light_step')|int %}
{% set next = current - step %} {% set next = current - step %}
{% if next < states('input_number.light_minimum')|int %} {% if next < states('input_number.light_minimum')|int %}
@ -155,7 +155,7 @@ script:
{{ next }}{% endraw %} {{ next }}{% endraw %}
- service_template: > - service_template: >
{% raw %}{% if states.light.YOUR_LIGHT.attributes.brightness|default(0)|int > states('input_number.light_minimum')|int %} {% raw %}{% if state_attr('light.YOUR_LIGHT', 'brightness')|default(0)|int > states('input_number.light_minimum')|int %}
script.turn_on script.turn_on
{% else %} {% else %}
script.turn_off script.turn_off

View File

@ -22,7 +22,7 @@ It also leverages the `limit_refetch_to_url_change` option to ensure that we do
camera: camera:
name: Paulus name: Paulus
platform: generic platform: generic
still_image_url: {% raw %}https://maps.googleapis.com/maps/api/staticmap?center={{ states.device_tracker.demo_paulus.attributes.latitude }},{{ states.device_tracker.demo_paulus.attributes.longitude }}&zoom=13&size=500x500&maptype=roadmap&markers=color:blue%7Clabel:P%7C{{ states.device_tracker.demo_paulus.attributes.latitude }},{{ states.device_tracker.demo_paulus.attributes.longitude }}{% endraw %}&key=YOUR_API_KEY still_image_url: {% raw %}https://maps.googleapis.com/maps/api/staticmap?center={{ state_attr('device_tracker.demo_paulus', 'latitude') }},{{ state_attr('device_tracker.demo_paulus', 'longitude') }}&zoom=13&size=500x500&maptype=roadmap&markers=color:blue%7Clabel:P%7C{{ state_attr('device_tracker.demo_paulus', 'latitude') }},{{ state_attr('device_tracker.demo_paulus', 'longitude') }}{% endraw %}&key=YOUR_API_KEY
limit_refetch_to_url_change: true limit_refetch_to_url_change: true
``` ```

View File

@ -49,6 +49,6 @@ automation:
data_template: data_template:
title: 'New Home Assistant Release' title: 'New Home Assistant Release'
target: 'YOUR_TARGET_HERE' #See Pushbullet integration for usage target: 'YOUR_TARGET_HERE' #See Pushbullet integration for usage
message: "Home Assistant {% raw %} {{ states.updater.updater.state }} {% endraw %} is now available." message: "Home Assistant {% raw %} {{ states('updater.updater') }} {% endraw %} is now available."
``` ```

View File

@ -29,7 +29,7 @@ automation:
service: notify.mypushbullet service: notify.mypushbullet
data_template: data_template:
title: "Furnace fan is running" title: "Furnace fan is running"
message: "Fan running because current is {% raw %}{{ states.sensor.furnace.state }}{% endraw %} amps" message: "Fan running because current is {% raw %}{{ states('sensor.furnace') }}{% endraw %} amps"
``` ```
If you also want a notification when it drops back down below that limit, you could add this as well: If you also want a notification when it drops back down below that limit, you could add this as well:
@ -44,5 +44,5 @@ If you also want a notification when it drops back down below that limit, you co
service: notify.mypushbullet service: notify.mypushbullet
data_template: data_template:
title: "Furnace fan is stopped" title: "Furnace fan is stopped"
message: "Fan stopped because current is {% raw %}{{ states.sensor.furnace.state }}{% endraw %} amps" message: "Fan stopped because current is {% raw %}{{ states('sensor.furnace') }}{% endraw %} amps"
``` ```

View File

@ -23,10 +23,10 @@ sensor:
friendly_name: iPhone Battery friendly_name: iPhone Battery
unit_of_measurement: '%' unit_of_measurement: '%'
value_template: >- value_template: >-
{%- if states.device_tracker.iphone.attributes.battery %} {%- if state_attr('device_tracker.iphone', 'battery') %}
{{ states.device_tracker.iphone.attributes.battery|round }} {{ state_attr('device_tracker.iphone', 'battery')|round }}
{% else %} {% else %}
{{ states.sensor.battery_iphone.state }} {{ states('sensor.battery_iphone') }}
{%- endif %} {%- endif %}
device_class: battery device_class: battery
``` ```

View File

@ -61,9 +61,9 @@ automation:
- condition: or - condition: or
conditions: conditions:
- condition: template - condition: template
value_template: '{% raw %}{{ states.sun.sun.attributes.elevation < 4 }}{% endraw %}' value_template: '{% raw %}{{ state_attr('sun.sun', 'elevation') < 4 }}{% endraw %}'
- condition: template - condition: template
value_template: '{% raw %}{{ states.sensor.sensorluz_7_0.state < 10 }}{% endraw %}' value_template: '{% raw %}{{ states('sensor.sensorluz_7_0') < 10 }}{% endraw %}'
- service: scene.turn_on - service: scene.turn_on
entity_id: scene.DespiertaDespacho entity_id: scene.DespiertaDespacho
``` ```

View File

@ -27,9 +27,9 @@ automation:
condition: or condition: or
conditions: conditions:
- condition: template - condition: template
value_template: '{% raw %}{{ states.sun.sun.attributes.elevation < 4 }}{% endraw %}' value_template: '{% raw %}{{ state_attr('sun.sun', 'elevation') < 4 }}{% endraw %}'
- condition: template - condition: template
value_template: '{% raw %}{{ states.sensor.sensorluz_7_0.state < 10 }}{% endraw %}' value_template: '{% raw %}{{ states('sensor.sensorluz_7_0') < 10 }}{% endraw %}'
action: action:
- service: scene.turn_on - service: scene.turn_on
entity_id: scene.DespiertaDespacho entity_id: scene.DespiertaDespacho

View File

@ -80,7 +80,7 @@ The next two statements result in the same value if the state exists. The second
{% raw %} {% raw %}
```text ```text
{{ states('device_tracker.paulus') }} {{ states('device_tracker.paulus') }}
{{ states.device_tracker.paulus.state }} {{ states('device_tracker.paulus') }}
``` ```
{% endraw %} {% endraw %}

View File

@ -136,7 +136,7 @@ You can also get the script to abort after the timeout by using `continue_on_tim
{% raw %} {% raw %}
```yaml ```yaml
# Wait until a valve is < 10 or abort after 1 minute. # Wait until a valve is < 10 or abort after 1 minute.
- wait_template: "{{ states.climate.kitchen.attributes.valve|int < 10 }}" - wait_template: "{{ state_attr('climate.kitchen', 'valve')|int < 10 }}"
timeout: '00:01:00' timeout: '00:01:00'
continue_on_timeout: 'false' continue_on_timeout: 'false'
``` ```

View File

@ -150,15 +150,15 @@ condition:
condition: and # 'twilight' condition: dusk and dawn, in typical locations condition: and # 'twilight' condition: dusk and dawn, in typical locations
conditions: conditions:
- condition: template - condition: template
value_template: {% raw %}'{{ states.sun.sun.attributes.elevation < 0 }}'{% endraw %} value_template: {% raw %}'{{ state_attr('sun.sun', 'elevation') < 0 }}'{% endraw %}
- condition: template - condition: template
value_template: {% raw %}'{{ states.sun.sun.attributes.elevation > -6 }}'{% endraw %} value_template: {% raw %}'{{ state_attr('sun.sun', 'elevation') > -6 }}'{% endraw %}
``` ```
```yaml ```yaml
condition: condition:
condition: template # 'night' condition: from dusk to dawn, in typical locations condition: template # 'night' condition: from dusk to dawn, in typical locations
value_template: {% raw %}'{{ states.sun.sun.attributes.elevation < -6 }}'{% endraw %} value_template: {% raw %}'{{ state_attr('sun.sun', 'elevation') < -6 }}'{% endraw %}
``` ```
#### {% linkable_title Sunset/sunrise condition %} #### {% linkable_title Sunset/sunrise condition %}

View File

@ -49,7 +49,7 @@ You can use [templating] support to dynamically choose which service to call. Fo
```yaml ```yaml
service_template: > service_template: >
{% raw %}{% if states.sensor.temperature.state | float > 15 %} {% raw %}{% if states('sensor.temperature') | float > 15 %}
switch.turn_on switch.turn_on
{% else %} {% else %}
switch.turn_off switch.turn_off