Add template support to numeric_state trigger's for option (#9781)

This commit is contained in:
Phil Bruckner 2019-07-10 05:39:08 -05:00 committed by Franck Nijhof
parent 0cf680ca13
commit f955c61226
2 changed files with 25 additions and 0 deletions

View File

@ -118,6 +118,7 @@ The following tables show the available trigger data per platform.
| `trigger.above` | The above threshold, if any.
| `trigger.from_state` | The previous [state object] of the entity.
| `trigger.to_state` | The new [state object] that triggered trigger.
| `trigger.for` | Timedelta object how long state has met above/below criteria, if any.
### state

View File

@ -106,6 +106,30 @@ automation:
```
{% endraw %}
You can also use templates in the `for` option.
{% raw %}
```yaml
automation:
trigger:
platform: numeric_state
entity_id:
- sensor.temperature_1
- sensor.temperature_2
above: 80
for:
minutes: "{{ states('input_number.high_temp_min')|int }}"
seconds: "{{ states('input_number.high_temp_sec')|int }}"
action:
service: persistent_notification.create
data_template:
message: >
{{ trigger.to_state.name }} too high for {{ trigger.for }}!
```
{% endraw %}
The `for` template(s) will be evaluated when an entity changes as specified.
### State trigger
Triggers when the state of a given entity changes. If only `entity_id` is given trigger will activate for all state changes, even if only state attributes change.