Nested conditions not passing config check

I am trying to add some conditions to an existing automation but the nesting isn’t passing the config checker. It doesn’t seem to like me having ‘and’ nested inside ‘or’, nested inside ’ and’…

This orignally worked fine so the only bit that doesn’t work is the middle part with the value_templates

Hopefully what I have below is enough to explain what I am trying to do, but basically I want the ‘start_time1’ and it’s ‘enable’ to be logic AND, then logic OR’d with ‘start_time2’ and it’s ‘enable’.

automation:
  - alias: Reticulation test code     # start program 1 at designated time if it is enabled and today is selected as a watering day
    initial_state: 'on'
    trigger:
      - platform: template
        value_template: "{{ states('sensor.time') == (states.input_datetime.retic_program1_start_time_1.attributes.timestamp | int | timestamp_custom('%H:%M', False)) }}"
      - platform: template
        value_template: "{{ states('sensor.time') == (states.input_datetime.retic_program1_start_time_2.attributes.timestamp | int | timestamp_custom('%H:%M', False)) }}"
    condition:
      - condition: state
        entity_id: input_boolean.retic_program1_enable
        state: 'on'
      - condition: state
        entity_id: sensor.retic_program1_watering_day
        state: 'True'
      - condition: or
        conditions:
          - condition: and
            conditions:
              - condition: template
                value_template: "{{ states('sensor.time') == (states.input_datetime.retic_program1_start_time_1.attributes.timestamp | int | timestamp_custom('%H:%M', False)) }}"
              - condition: state
                entity_id: input_boolean.retic_program1_start_time1_enable
          - condition: and
            conditions:
              - condition: template
                value_template: "{{ states('sensor.time') == (states.input_datetime.retic_program1_start_time_2.attributes.timestamp | int | timestamp_custom('%H:%M', False)) }}"
              - condition: state
                entity_id: input_boolean.retic_program1_start_time2_enable
      - condition: or
        conditions:
          - condition: state
            entity_id: input_boolean.retic_rain_parameters_met
            state: 'on'
          - condition: state
            entity_id: input_boolean.retic_rain_override
            state: 'on'
    action:
      - service: script.turn_on
        entity_id: script.retic_program1_run

can someone please help me as I can’t figure out why it won’t work this way… I’m guessing it’s indentation but have been playing around with it for a while now. :exploding_head:

The second AND conditions in both the first OR have state conditions but you haven’t specified a state. I suspect the error message would have told you you were missing a required key.

I can’t believe I missed that. I’ll fix it up and see what happens, thanks

1 Like

I read through the code and your explanation maybe 10 times over 10 minutes before I understood.
Well spotted, I can forgive Dave for not seeing that off the cuff.
I must admit that given the convoluted nature of the condition clauses for anything above basic, I just give up, draw a karnaugh map and write a template to do the logic ! :rofl:

It’s also a lot easier to fix later when I’ve got it wrong or ‘conditions’ change (pun intended) :crazy_face: