Condition false does not halt automation/script

Hi everybody,

In Conditions it says that

Conditions can be used within a script or automation to prevent further execution. When a condition evaluates true, the script or automation will be executed. If any other value is returned, the script or automation stops executing.

However, I have an automation where a false condition inside a ‘choose’ action will not halt the execution of the automation. I wonder whether it is a documentation bug, an execution bug or (probably) a lack of understanding on my part.

I would appreciate the help.

Here is the automation:

- id: activar_precalentamiento_dormitorio_padres
  alias: Activar Precalentamiento Dormitorio Padres
  description: Precalentar antes de hora el dormitorio de padres cuando hace mucho frio
  trace:
    stored_traces: 12
  triggers:
    - trigger: time
      at:
        - entity_id: sensor.wiser_dormitorio_next_schedule_change
          offset: "-00:30:00"
      id: "P30"
      variables:
        tiempo_precalentamiento: 30
    - trigger: time
      at:
        - entity_id: sensor.wiser_dormitorio_next_schedule_change
          offset: "-01:00:00"
      id: "P60"
      variables:
        tiempo_precalentamiento: 60
    - trigger: time
      at:
        - entity_id: sensor.wiser_dormitorio_next_schedule_change
          offset: "-01:30:00"
      id: "P90"
      variables:
        tiempo_precalentamiento: 90
    - trigger: time
      at:
        - entity_id: sensor.wiser_dormitorio_next_schedule_change
          offset: "-02:00:00"
      id: "P120"
      variables:
        tiempo_precalentamiento: 120
    - trigger: time
      at:
        - entity_id: sensor.wiser_dormitorio_next_schedule_change
          offset: "-02:30:00"
      id: "P150"
      variables:
        tiempo_precalentamiento: 150
  actions:
    - alias: "Fijamos resto de variables"
      variables:
        velocidad_cambio_temp_30_min: 0.7
        temperatura_actual: "{{ state_attr('climate.wiser_dormitorio', 'current_temperature') }}"
        temperatura_siguiente: "{{ state_attr('climate.wiser_dormitorio', 'next_schedule_temp') }}"
        esta_precalentando: "{{ state_attr('climate.wiser_dormitorio', 'is_boosted') }}"
        tiempo_escrito: {'30': 'media hora', '60': 'una hora', '90': 'hora y media', '120': 'dos horas', '150': 'dos horas y media'}
    - alias: "Comprobamos que se cumplen las condiciones"
      choose:
        - alias: "Condiciones para el trigger P30"
          conditions:
            - condition: trigger
              id: "P30"
          sequence:
            - condition: and
              conditions:
                - alias: "Que la habitación no esté ya en precalentamiento"
                  condition: template
                  value_template: "{{ not esta_precalentando }}"
      default:
        - alias: "Condiciones para todos los triggers menos el P30"
          condition: and
          conditions:
            - alias: "Que el diferencial de temperatura sea igual o mayor que que la velocidad de cambio de temperatura"
              condition: template
              value_template: "{{ (temperatura_siguiente - temperatura_actual) >= (velocidad_cambio_temp_30_min * tiempo_precalentamiento / 30) }}"
            - alias: "Que la habitación no esté ya en precalentamiento"
              condition: template
              value_template: "{{ not esta_precalentando }}"
    - alias: "Precalentamos durante el tiempo establecido"
      action: script.execute_wiser_boost
      data:
        room: climate.wiser_dormitorio
        boost_time: "{{ tiempo_precalentamiento }}"
        temp_delta: "{{ (temperatura_siguiente - temperatura_actual) }}"
    - alias: "Activamos el deshumidificador"
      action: humidifier.turn_on
      data:
        entity_id: humidifier.dormitorio_padres
    - alias: "Notificamos al administrador del precalentamiento"
      action: notify.mobile_app_javier_movil
      data:
        message: "El Dormitorio de padres se precalentará durante {{ tiempo_escrito[tiempo_precalentamiento | string] }}"
        title: Feira

and here is the trace

{
  "trace": {
    "last_step": "action/4",
    "run_id": "5ef00819728520484010f5e1c325d915",
    "state": "stopped",
    "script_execution": "finished",
    "timestamp": {
      "start": "2024-11-23T18:30:00.000924+00:00",
      "finish": "2024-11-23T18:30:02.270850+00:00"
    },
    "domain": "automation",
    "item_id": "activar_precalentamiento_dormitorio_padres",
    "trigger": "time set in sensor.wiser_dormitorio_next_schedule_change",
    "trace": {
      "trigger/2": [
        {
          "path": "trigger/2",
          "timestamp": "2024-11-23T18:30:00.001041+00:00",
          "changed_variables": {
            "this": {
              "entity_id": "automation.activar_precalentamiento_dormitorio_padres",
              "state": "on",
              "attributes": {
                "id": "activar_precalentamiento_dormitorio_padres",
                "last_triggered": "2024-11-23T18:00:00.000901+00:00",
                "mode": "single",
                "current": 0,
                "friendly_name": "Activar Precalentamiento Dormitorio Padres"
              },
              "last_changed": "2024-11-23T00:23:04.727183+00:00",
              "last_reported": "2024-11-23T18:00:03.453807+00:00",
              "last_updated": "2024-11-23T18:00:03.453807+00:00",
              "context": {
                "id": "01JDD2WF80TTKEWY5JS99D72NA",
                "parent_id": null,
                "user_id": null
              }
            },
            "trigger": {
              "id": "P90",
              "idx": "2",
              "alias": null,
              "platform": "time",
              "now": "2024-11-23T19:30:00+01:00",
              "description": "time set in sensor.wiser_dormitorio_next_schedule_change",
              "entity_id": "sensor.wiser_dormitorio_next_schedule_change"
            },
            "tiempo_precalentamiento": 90
          }
        }
      ],
      "action/0": [
        {
          "path": "action/0",
          "timestamp": "2024-11-23T18:30:00.001424+00:00",
          "changed_variables": {
            "context": {
              "id": "01JDD4KD20AT8R1B7BWSPSZKZ3",
              "parent_id": null,
              "user_id": null
            },
            "velocidad_cambio_temp_30_min": 0.7,
            "temperatura_actual": 20.1,
            "temperatura_siguiente": 20,
            "esta_precalentando": true,
            "tiempo_escrito": {
              "30": "media hora",
              "60": "una hora",
              "90": "hora y media",
              "120": "dos horas",
              "150": "dos horas y media"
            }
          }
        }
      ],
      "action/1": [
        {
          "path": "action/1",
          "timestamp": "2024-11-23T18:30:00.001900+00:00",
          "result": {
            "choice": "default"
          }
        }
      ],
      "action/1/choose/0": [
        {
          "path": "action/1/choose/0",
          "timestamp": "2024-11-23T18:30:00.001976+00:00",
          "result": {
            "result": false
          }
        }
      ],
      "action/1/choose/0/conditions/0": [
        {
          "path": "action/1/choose/0/conditions/0",
          "timestamp": "2024-11-23T18:30:00.002007+00:00",
          "result": {
            "result": false
          }
        }
      ],
      "action/1/default/0": [
        {
          "path": "action/1/default/0",
          "timestamp": "2024-11-23T18:30:00.002163+00:00",
          "result": {
            "result": false
          }
        }
      ],
      "action/1/default/0/conditions/0": [
        {
          "path": "action/1/default/0/conditions/0",
          "timestamp": "2024-11-23T18:30:00.002309+00:00",
          "result": {
            "result": false,
            "entities": []
          }
        }
      ],
      "action/2": [
        {
          "path": "action/2",
          "timestamp": "2024-11-23T18:30:00.002555+00:00",
          "child_id": {
            "domain": "script",
            "item_id": "execute_wiser_boost",
            "run_id": "4cdd7b2b210bf2585ce2593f1bf741cd"
          },
          "result": {
            "params": {
              "domain": "script",
              "service": "execute_wiser_boost",
              "service_data": {
                "room": "climate.wiser_dormitorio",
                "boost_time": 90,
                "temp_delta": -0.10000000000000142
              },
              "target": {}
            },
            "running_script": true
          }
        }
      ],
      "action/3": [
        {
          "path": "action/3",
          "timestamp": "2024-11-23T18:30:01.198699+00:00",
          "result": {
            "params": {
              "domain": "humidifier",
              "service": "turn_on",
              "service_data": {
                "entity_id": "humidifier.dormitorio_padres"
              },
              "target": {}
            },
            "running_script": false
          }
        }
      ],
      "action/4": [
        {
          "path": "action/4",
          "timestamp": "2024-11-23T18:30:01.199308+00:00",
          "result": {
            "params": {
              "domain": "notify",
              "service": "mobile_app_javier_movil",
              "service_data": {
                "message": "El Dormitorio de padres se precalentará durante hora y media",
                "title": "Feira"
              },
              "target": {}
            },
            "running_script": false
          }
        }
      ]
    },
    "config": {
      "id": "activar_precalentamiento_dormitorio_padres",
      "alias": "Activar Precalentamiento Dormitorio Padres",
      "description": "Precalentar antes de hora el dormitorio de padres cuando hace mucho frio",
      "trace": {
        "stored_traces": 12
      },
      "triggers": [
        {
          "trigger": "time",
          "at": [
            {
              "entity_id": "sensor.wiser_dormitorio_next_schedule_change",
              "offset": "-00:30:00"
            }
          ],
          "id": "P30",
          "variables": {
            "tiempo_precalentamiento": 30
          }
        },
        {
          "trigger": "time",
          "at": [
            {
              "entity_id": "sensor.wiser_dormitorio_next_schedule_change",
              "offset": "-01:00:00"
            }
          ],
          "id": "P60",
          "variables": {
            "tiempo_precalentamiento": 60
          }
        },
        {
          "trigger": "time",
          "at": [
            {
              "entity_id": "sensor.wiser_dormitorio_next_schedule_change",
              "offset": "-01:30:00"
            }
          ],
          "id": "P90",
          "variables": {
            "tiempo_precalentamiento": 90
          }
        },
        {
          "trigger": "time",
          "at": [
            {
              "entity_id": "sensor.wiser_dormitorio_next_schedule_change",
              "offset": "-02:00:00"
            }
          ],
          "id": "P120",
          "variables": {
            "tiempo_precalentamiento": 120
          }
        },
        {
          "trigger": "time",
          "at": [
            {
              "entity_id": "sensor.wiser_dormitorio_next_schedule_change",
              "offset": "-02:30:00"
            }
          ],
          "id": "P150",
          "variables": {
            "tiempo_precalentamiento": 150
          }
        }
      ],
      "actions": [
        {
          "alias": "Fijamos resto de variables",
          "variables": {
            "velocidad_cambio_temp_30_min": 0.7,
            "temperatura_actual": "{{ state_attr('climate.wiser_dormitorio', 'current_temperature') }}",
            "temperatura_siguiente": "{{ state_attr('climate.wiser_dormitorio', 'next_schedule_temp') }}",
            "esta_precalentando": "{{ state_attr('climate.wiser_dormitorio', 'is_boosted') }}",
            "tiempo_escrito": {
              "30": "media hora",
              "60": "una hora",
              "90": "hora y media",
              "120": "dos horas",
              "150": "dos horas y media"
            }
          }
        },
        {
          "alias": "Comprobamos que se cumplen las condiciones",
          "choose": [
            {
              "alias": "Condiciones para el trigger P30",
              "conditions": [
                {
                  "condition": "trigger",
                  "id": "P30"
                }
              ],
              "sequence": [
                {
                  "condition": "and",
                  "conditions": [
                    {
                      "alias": "Que la habitación no esté ya en precalentamiento",
                      "condition": "template",
                      "value_template": "{{ not esta_precalentando }}"
                    }
                  ]
                }
              ]
            }
          ],
          "default": [
            {
              "alias": "Condiciones para todos los triggers menos el P30",
              "condition": "and",
              "conditions": [
                {
                  "alias": "Que el diferencial de temperatura sea igual o mayor que que la velocidad de cambio de temperatura",
                  "condition": "template",
                  "value_template": "{{ (temperatura_siguiente - temperatura_actual) >= (velocidad_cambio_temp_30_min * tiempo_precalentamiento / 30) }}"
                },
                {
                  "alias": "Que la habitación no esté ya en precalentamiento",
                  "condition": "template",
                  "value_template": "{{ not esta_precalentando }}"
                }
              ]
            }
          ]
        },
        {
          "alias": "Precalentamos durante el tirmpo establecido",
          "action": "script.execute_wiser_boost",
          "data": {
            "room": "climate.wiser_dormitorio",
            "boost_time": "{{ tiempo_precalentamiento }}",
            "temp_delta": "{{ (temperatura_siguiente - temperatura_actual) }}"
          }
        },
        {
          "alias": "Activamos el deshumidificador",
          "action": "humidifier.turn_on",
          "data": {
            "entity_id": "humidifier.dormitorio_padres"
          }
        },
        {
          "alias": "Notificamos al administrador del precalentamiento",
          "action": "notify.mobile_app_javier_movil",
          "data": {
            "message": "El Dormitorio de padres se precalentará durante {{ tiempo_escrito[tiempo_precalentamiento | string] }}",
            "title": "Feira"
          }
        }
      ]
    },
    "blueprint_inputs": null,
    "context": {
      "id": "01JDD4KD20AT8R1B7BWSPSZKZ3",
      "parent_id": null,
      "user_id": null
    }
  },
  "logbookEntries": [
    {
      "name": "Activar Precalentamiento Dormitorio Padres",
      "message": "triggered by time set in sensor.wiser_dormitorio_next_schedule_change",
      "source": "time set in sensor.wiser_dormitorio_next_schedule_change",
      "entity_id": "automation.activar_precalentamiento_dormitorio_padres",
      "context_id": "01JDD4KD20AT8R1B7BWSPSZKZ3",
      "domain": "automation",
      "when": 1732386600.0011194
    },
    {
      "name": "Wiser Boosts",
      "message": "started",
      "entity_id": "script.execute_wiser_boost",
      "context_id": "01JDD4KD20AT8R1B7BWSPSZKZ3",
      "domain": "script",
      "when": 1732386600.0029066,
      "context_event_type": "automation_triggered",
      "context_domain": "automation",
      "context_name": "Activar Precalentamiento Dormitorio Padres",
      "context_message": "triggered by time set in sensor.wiser_dormitorio_next_schedule_change",
      "context_source": "time set in sensor.wiser_dormitorio_next_schedule_change",
      "context_entity_id": "automation.activar_precalentamiento_dormitorio_padres"
    },
    {
      "state": "on",
      "entity_id": "script.execute_wiser_boost",
      "icon": "mdi:script",
      "when": 1732386600.0030718,
      "context_event_type": "automation_triggered",
      "context_domain": "automation",
      "context_name": "Activar Precalentamiento Dormitorio Padres",
      "context_message": "triggered by time set in sensor.wiser_dormitorio_next_schedule_change",
      "context_source": "time set in sensor.wiser_dormitorio_next_schedule_change",
      "context_entity_id": "automation.activar_precalentamiento_dormitorio_padres"
    },
    {
      "state": "off",
      "entity_id": "script.execute_wiser_boost",
      "icon": "mdi:script",
      "when": 1732386601.1979072,
      "context_event_type": "automation_triggered",
      "context_domain": "automation",
      "context_name": "Activar Precalentamiento Dormitorio Padres",
      "context_message": "triggered by time set in sensor.wiser_dormitorio_next_schedule_change",
      "context_source": "time set in sensor.wiser_dormitorio_next_schedule_change",
      "context_entity_id": "automation.activar_precalentamiento_dormitorio_padres"
    }
  ]
}

Thanks

Javier.

The Choose action shown has no Actions in either of the sequences i.e. Option 1 and Default.

Thanks for replying.

Well, they both have ‘condition actions’. And the condition in the default sequence is the one that is evaluated to false. Should not that halt the automation?

Javier

No, it would stop further actions within the Choose from happening, but the other actions are outside the Choose.

Ok. Would it be considered then a documentation bug? As I stated in the initial post, the documentation says that a condition evaluated false stops the script.

Thanks.

Javier

I wouldn’t consider it a documentation issue, I think you just misunderstand how the Choose action works.

Understood. Thank you for explaining.

Javier

Instead of Choose, you would use the conditions directly in the action block or move the variables to their own block and move the conditions to the conditions block.

Since the automation really isn’t using the trigger.id in a significant way, you can compact the automation a bit if you use a single trigger and use data stored in the trigger variable to define tiempo_precalentamiento. The automation shown below assumes that sensor.wiser_dormitorio_next_schedule_change holds both date and time. If that is not the case, changes will be necessary.

  triggers:
    - trigger: time
      at:
        - entity_id: sensor.wiser_dormitorio_next_schedule_change
          offset: "-00:30:00"
        - entity_id: sensor.wiser_dormitorio_next_schedule_change
          offset: "-01:00:00"
        - entity_id: sensor.wiser_dormitorio_next_schedule_change
          offset: "-01:30:00"
        - entity_id: sensor.wiser_dormitorio_next_schedule_change
          offset: "-02:00:00"
        - entity_id: sensor.wiser_dormitorio_next_schedule_change
          offset: "-02:30:00"
  variables:
    tiempo_precalentamiento: >-
      {{ ((states('sensor.wiser_dormitorio_next_schedule_change')|as_datetime|as_local - trigger.now|as_datetime).total_seconds() // 60)|int }}
    velocidad_cambio_temp_30_min: 0.7
    temperatura_actual: "{{ state_attr('climate.wiser_dormitorio', 'current_temperature') }}"
    temperatura_siguiente: "{{ state_attr('climate.wiser_dormitorio', 'next_schedule_temp') }}"
    tiempo_escrito: 
      '30': 'media hora'
      '60': 'una hora'
      '90': 'hora y media'
      '120': 'dos horas'
      '150': 'dos horas y media'
  conditions:    
    - alias: "Que la habitación no esté ya en precalentamiento"
      condition: template
      value_template: "{{ not state_attr('climate.wiser_dormitorio', 'is_boosted') }}"
    - alias: "Comprobamos que se cumplen las condiciones"
      condition: or
      conditions:
        - condition: template
          value_template: "{{ tiempo_precalentamiento == 30 }}"
        - condition: template
          value_template: "{{ (temperatura_siguiente - temperatura_actual) >= (velocidad_cambio_temp_30_min * tiempo_precalentamiento / 30) }}"
  actions:  
    - alias: "Precalentamos durante el tiempo establecido"
      action: script.execute_wiser_boost
      data:
        room: climate.wiser_dormitorio
        boost_time: "{{ tiempo_precalentamiento }}"
        temp_delta: "{{ (temperatura_siguiente - temperatura_actual) }}"
    - alias: "Activamos el deshumidificador"
      action: humidifier.turn_on
      data:
        entity_id: humidifier.dormitorio_padres
    - alias: "Notificamos al administrador del precalentamiento"
      action: notify.mobile_app_javier_movil
      data:
        message: "El Dormitorio de padres se precalentará durante {{ tiempo_escrito[tiempo_precalentamiento | string] }}"
        title: Feira
1 Like

Wonderful. You just saved me a lot of hassle.

Thank you very much!!!

Javier

Hi JavierC.

The Docs are right. You are not considering the scope of the conditions:.

In the top key level it will stop everything. Inside a choose it will stop that segment of the choose that is within it’s scope.