diff --git a/source/_docs/scripts.markdown b/source/_docs/scripts.markdown index a04eeb290dc..7c5813f1dfb 100644 --- a/source/_docs/scripts.markdown +++ b/source/_docs/scripts.markdown @@ -610,6 +610,64 @@ automation: {% endraw %} + +More `choose` can be used together. This is the case of an IF-IF. + +The following example shows how a single automation can control entities that aren't related to each other but have in common the same trigger. + +When the sun goes below the horizon, the `porch` and `garden` lights must turn on. If someone is watching the TV in the living room, there is a high chance that someone is in that room, therefore the living room lights have to turn on too. The same concept applies to the `studio` room. + +{% raw %} + +```yaml +# Example with "if" and "if" +automation: + - alias: "Turn lights on when the sun gets dim and if some room is occupied" + trigger: + - platform: numeric_state + entity_id: sun.sun + attribute: elevation + below: 4 + action: + # This must always apply + - service: light.turn_on + data: + brightness: 255 + color_temp: 366 + target: + entity_id: + - light.porch + - light.garden + # IF a entity is ON + - choose: + - conditions: + - condition: state + entity_id: binary_sensor.livingroom_tv + state: "on" + sequence: + - service: light.turn_on + data: + brightness: 255 + color_temp: 366 + target: + entity_id: light.livingroom + # IF another entity not related to the previous, is ON + - choose: + - conditions: + - condition: state + entity_id: binary_sensor.studio_pc + state: "on" + sequence: + - service: light.turn_on + data: + brightness: 255 + color_temp: 366 + target: + entity_id: light.studio +``` + +{% endraw %} + [Script component]: /integrations/script/ [automations]: /getting-started/automation-action/ [Alexa/Amazon Echo]: /integrations/alexa/