From 0ea561ae9d673ff83c7f0a13b5a5dd6467a2df6d Mon Sep 17 00:00:00 2001 From: Franck Nijhof Date: Mon, 7 Sep 2020 16:36:49 +0200 Subject: [PATCH] Support 'for' without setting the 'to'-state in automation state trigger (#14423) --- source/_docs/automation/trigger.markdown | 44 ++++++++++++++++++++++-- 1 file changed, 41 insertions(+), 3 deletions(-) diff --git a/source/_docs/automation/trigger.markdown b/source/_docs/automation/trigger.markdown index 5658838c4e9..7c68d27bf30 100644 --- a/source/_docs/automation/trigger.markdown +++ b/source/_docs/automation/trigger.markdown @@ -158,6 +158,9 @@ automation: You can use `for` to have the state trigger only fire if the state holds for some time. +This example fires, when the entity state changed to `"on"` and holds that +state for 30 seconds: + ```yaml automation: trigger: @@ -168,14 +171,49 @@ automation: for: "00:00:30" ``` +You can also fire the trigger when the state value changed from a specific +state, but hasn't returned to that state value for the specified time. + +This can be useful, e.g., checking if a media player hasn't turned "off" for +the time specified, but doesn't care about "playing" or "paused". + ```yaml automation: trigger: platform: state entity_id: media_player.kitchen - # Not "playing" for 30 seconds - from: "playing" - for: "00:00:30" + # Not "off" for 30 minutes + from: "off" + for: "00:30:00" +``` + +Please note, that when using `from`, `to` and `for`, only the value of the +`to` option is considered for the time specified. + +In this example, the trigger fires if the state value of the entity remains the +same for `for` the time specified, regardless of the current state value. + +```yaml +automation: + trigger: + platform: state + entity_id: media_player.kitchen + # The media player remained in its current state for 1 hour + for: "01:00:00" +``` + +When the `attribute` option is specified, all of the above works, but only +applies to the specific state value of that attribute. + +For example, this trigger only fires if the boiler was heating for 10 minutes: + +```yaml +automation: + trigger: + platform: state + entity_id: climate.living_room + attribute: hvac_action + state: "heating" ``` You can also use templates in the `for` option.