kdvlr 0daad58567 Clarified the behavior of conditions. (#10461)
* Clarified the behavior of conditions. 

The current reading of the documentation indicates that if a condition evaluates to true it stops executing. Added additional context to the first line to describe the actual behavior.

* Updated docs to clarify conditions behavior

The current reading of the documentation indicates that if a condition evaluates to true it stops executing. Added additional context to the first line to describe the actual behavior.

* Renamed script to automation

* Changed to script or automation for consistency.
2019-09-28 09:37:15 +02:00

1.3 KiB

title description redirect_from
Automation Conditions Automations can test conditions when invoked. /getting-started/automation-condition/

Conditions are an optional part of an automation rule and can be used to prevent an action from happening when triggered. When a condition does not return true, the automation will stop executing. Conditions look very similar to triggers but are very different. A trigger will look at events happening in the system while a condition only looks at how the system looks right now. A trigger can observe that a switch is being turned on. A condition can only see if a switch is currently on or off.

The available conditions for an automation are the same as for the script syntax so see that page for a full list of available conditions.

Example of using condition:

automation:
- alias: 'Enciende Despacho'
  trigger:
    platform: state
    entity_id: sensor.mini_despacho
    to: 'on'
  condition:
    condition: or
    conditions:
      - condition: template
        value_template: '{% raw %}{{ state_attr('sun.sun', 'elevation') < 4 }}{% endraw %}'
      - condition: template
        value_template: '{% raw %}{{ states('sensor.sensorluz_7_0') < 10 }}{% endraw %}'
  action:
    - service: scene.turn_on
      entity_id: scene.DespiertaDespacho