Automated action until

Hi,

I’m trying to create an automation and I would like the action to execute UNTIL one OR more conditions are met. I simplified it, but I want my garage ventilation fan to turn on to cool down my garage until either :

  1. the difference between the outside and inside temperature is less than 5 degrees; or
  2. the temperature in the garage has fallen to less than 24 degrees

If I follow the syntax documented at: https://www.home-assistant.io/docs/scripts/conditions/ , I should get something like this

- id: '123'
  alias: Garage Heat Fan
  mode: single
  trigger:
    - platform: template
      value_template: "{{ (states.sensor.garage_temperature.state - states.sensor.weather_temperature.state) > 5 }}"
  condition:
    - condition: template
      value_template: "{{ (states.sensor.garage_temp.state)|float > 24 }}"
  action:
    - service: fan.turn_on
      entity_id: fan.garage_fan_control_switch_level
    - repeat:
        sequence:
          - delay:
              minutes: 1
        until:
          condition:
            condition: or
            conditions:
              - condition: template
                value_template: "{{ (states.sensor.garage_temp.state - states.sensor.weather_temperature.state) < 5 }}"
              - condition: template
                value_template: "{{ (states.sensor.garage_temp.state)|float < 24 }}"
    - service: fan.turn_off
      entity_id: fan.garage_fan_control_switch_level

But that does not pass validation. How do I format the conditions within the UNTIL statement? Note that if I only put one condition within the UNTIL statement, the automation works correctly.

You probably want a wait_template not an until loop. You don’t want to repeat an action until some condition is met, you want to execute the next action (turn off the fan) once the condition is met

1 Like

2 ways:

remove the first condition: line that you had.

        until:
          - condition: or
            conditions:
              - condition: template
                value_template: "{{ ( states('sensor.garage_temp') | float - states('sensor.weather_temperature') | float ) < 5 }}"
              - condition: template
                value_template: "{{ states('sensor.garage_temp') | float < 24 }}"

or combine the templates

        until:
              - condition: template
                value_template: >
                  {% set v1 = ( states('sensor.garage_temp') | float - states('sensor.weather_temperature') | float ) < 5 %}
                  {% set v2 =  states('sensor.garage_temp') | float < 24 %}
                  {{ v1 or v2 }}

The main mistake you are making is the extra ‘condition:’ line.

EDIT: Also adjusted your templates because the first one was wrong. You can’t subtract strings.

1 Like

I agree with @Burningstone, you’ve over-complicated the automation. A wait_template is a much simpler and better solution. Not only that, since you’re effectively sampling every minute, it’s possible to miss a state that should have turned off the fan.

2 Likes

Great, thanks all. I had never used wait_template. I replaced all my repeat sequence with this:

    - wait_template: "{{ (((states.sensor.garage_temp.state)|float - (states.sensor.weather_temperature.state)|float) < (states.input_number.garage_heat_fan_setpoint_difference.state)|float) or ((states.sensor.garage_temp.state)|float < 24) }}"

Much simpler. Testing it now… Thanks again.

1 Like