From 548c014edc0f515f90aefb92e957ceed3a376f2f Mon Sep 17 00:00:00 2001 From: Fabian Affolter Date: Fri, 1 Jun 2018 00:44:04 +0200 Subject: [PATCH] Move raw --- source/_docs/automation/trigger.markdown | 22 +++++++++++++++------- 1 file changed, 15 insertions(+), 7 deletions(-) diff --git a/source/_docs/automation/trigger.markdown b/source/_docs/automation/trigger.markdown index 02db1fb64ed..124ef453aa4 100644 --- a/source/_docs/automation/trigger.markdown +++ b/source/_docs/automation/trigger.markdown @@ -13,6 +13,7 @@ redirect_from: /getting-started/automation-trigger/ Triggers are what starts the processing of an automation rule. It is possible to specify multiple triggers for the same rule. Once a trigger starts, Home Assistant will validate the conditions, if any, and call the action. ### {% linkable_title Event trigger %} + Triggers when an event is being processed. Events are the raw building blocks of Home Assistant. You can match events on just the event name or also require specific event data to be present. Events can be fired by components or via the API. There is no limitation to the types. A list of built-in events can be found [here](/docs/configuration/events/). @@ -44,6 +45,7 @@ automation: ``` ### {% linkable_title MQTT trigger %} + Triggers when a specific message is received on given topic. Optionally can match on the payload being sent over the topic. ```yaml @@ -56,15 +58,17 @@ automation: ``` ### {% linkable_title Numeric state trigger %} + Triggers when numeric value of an entity's state crosses a given threshold. On state change of a specified entity, attempts to parse the state as a number and triggers once if value is changing from above to below or from below to above the given threshold. +{% raw %} ```yaml automation: trigger: platform: numeric_state entity_id: sensor.temperature # Optional - value_template: '{% raw %}{{ state.attributes.battery }}{% endraw %}' + value_template: '{{ state.attributes.battery }}' # At least one of the following required above: 17 below: 25 @@ -75,6 +79,7 @@ automation: minutes: 10 seconds: 5 ``` +{% endraw %}

Listing above and below together means the numeric_state has to be between the two values. @@ -107,6 +112,7 @@ automation:

### {% linkable_title Sun trigger %} + Triggers when the sun is setting or rising. An optional time offset can be given to have it trigger a set time before or after the sun event (i.e. 45 minutes before sunset, when dusk is setting in). ```yaml @@ -121,34 +127,37 @@ automation: Sometimes you may want more granular control over an automation based on the elevation of the sun. This can be used to layer automations to occur as the sun lowers on the horizon or even after it is below the horizon. This is also useful when the "sunset" event is not dark enough outside and you would like the automation to run later at a precise solar angle instead of the time offset such as turning on exterior lighting. +{% raw %} ```yaml automation: alias: "Exterior Lighting on when dark outside" trigger: platform: numeric_state entity_id: sun.sun - value_template: "{% raw %}{{ state.attributes.elevation }}{% endraw %}" + value_template: "{{ state.attributes.elevation }" # Can be a positive or negative number below: -4.0 action: service: switch.turn_on entity_id: switch.exterior_lighting ``` +}{% endraw %} + The US Naval Observatory has a [tool](http://aa.usno.navy.mil/data/docs/AltAz.php) that will help you estimate what the solar angle will be at any specific time. ### {% linkable_title Template trigger %} -Template triggers work by evaluating a [template] on every state change for all of the recognized entities. The trigger will fire if the state change caused the template to render 'true'. This is achieved by having the template result in a true boolean expression (`{% raw %}{{ is_state('device_tracker.paulus', 'home') }}{% endraw %}`) or by having the template render 'true' (example below). +Template triggers work by evaluating a [template](/docs/configuration/templating/) on every state change for all of the recognized entities. The trigger will fire if the state change caused the template to render 'true'. This is achieved by having the template result in a true boolean expression (`{% raw %}{{ is_state('device_tracker.paulus', 'home') }}{% endraw %}`) or by having the template render 'true' (example below). With template triggers you can also evaluate attribute changes by using is_state_attr (`{% raw %}{{ is_state_attr('climate.living_room', 'away_mode', 'off') }}{% endraw %}`) +{% raw %} ```yaml automation: trigger: platform: template - value_template: "{% raw %}{% if is_state('device_tracker.paulus', 'home') %}true{% endif %}{% endraw %}" + value_template: "{% if is_state('device_tracker.paulus', 'home') %}true{% endif %}" ``` - -[template]: /docs/configuration/templating/ +{% endraw %} ### {% linkable_title Time trigger %} @@ -194,7 +203,6 @@ automation: event: enter # or "leave" ``` - ### {% linkable_title Multiple triggers %} When your want your automation rule to have multiple triggers, just prefix the first line of each trigger with a dash (-) and indent the next lines accordingly. Whenever one of the triggers fires, your rule is executed.