diff --git a/source/_docs/automation/templating.markdown b/source/_docs/automation/templating.markdown index 2b80dfc5d5e..1e2a3129db9 100644 --- a/source/_docs/automation/templating.markdown +++ b/source/_docs/automation/templating.markdown @@ -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 diff --git a/source/_docs/automation/trigger.markdown b/source/_docs/automation/trigger.markdown index 8eec3a91f3b..9c839689dfe 100644 --- a/source/_docs/automation/trigger.markdown +++ b/source/_docs/automation/trigger.markdown @@ -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.