Condition (1 AND 2) OR (3 AND 4)

Rather than write multiple automations I’d like to be able to switch on a light base on conditions (1 AND 2) OR (3 AND 4), but can’t seem to get it right.

So for example I want a condition where if it’s Monday and It’s after 19:00 switch on the light, or if it’s Tuesday and it’s after 20:00.

What is the magic combination of

- condition: or
      conditions:
- condition: and
       conditions:

do I need?

Any assistance would be greatly appreciated.

    - condition: or
      conditions:
        - condition: and
          conditions:
            - condition:
            - condition:
        - condition: and
          conditions:
            - condition:
            - condition:

Or use a template,

    - condition: template
      value_template: "{{ (condition1 and condition2) or (condition3 and condition4) }}"
1 Like

Thanks for the help. That looks so logical now. Agh!

Whilst looking for a solution I saw someone saying that value_template 's are bad as conditions since they are evaluated “at least every second”. Any idea if this is true?

That is probably referring to using templates as automation triggers. The condition will only be tested when the automation is triggered.

As a Template Trigger, it would need a time-based entity in order to be evaluated at that frequency.

Thanks all for the clarification.

HA changes a lot over time, some of the things that once used to be true are no longer true.

1 Like