Condition Mixed AND / OR

Was hoping someone could let me know what is wrong with this code. I am getting a “extra keys not allowed” message when attempting to save the automation. I am fairly sure I am following the documentation, but apparently something is amiss. :slight_smile:

What I am attempting to do is:

if the light is on
and
(it is 23:45 on a sun, mon, tues, wed, thu
or
it is 01:00 on a fri, sat)

condition:
  condition: and
  conditions:
    - condition: template
      value_template: '{{ is_state(''light.front_porch'',''on'')  }}'
    - condition: or
      conditions: 
        - condition: time
          at: '23:45:00'
          weekday:
            - sun
            - mon
            - tue
            - wed
            - thu
        - condition: time
          at: '01:00:00'
          weekday:
            - fri
            - sat

Thanks in advance!

Other than using a template condition where a simple state condition would do, and realising that conditions are AND by default, what you have looks ok. Try this:

condition:
  - condition: state
    entity_id: light.front_porch
    state: 'on'
  - condition: or
    conditions: 
      - condition: time
        at: '23:45:00'
        weekday:
          - sun
          - mon
          - tue
          - wed
          - thu
      - condition: time
        at: '01:00:00'
        weekday:
          - fri
          - sat

So the light must be on and it must be one of your time conditions for subsequent actions to occur.

However your triggers must occur at exactly those times for this to pass. If this is not the case you may be better off with a range of times, e.g.

      - condition: time
        after: '00:55:00'
        before: '01:05:00'
        weekday:
          - fri
          - sat

Still getting the “extra keys not allowed” message with the removal of the template usage… :frowning:

Because a Time Condition doesn’t support the at option. It uses after and/or before.

Documentation for Time Condition

Minimally, change at to after.

2 Likes

Doh. Should have looked it up. That actually makes a lot of sense.

A double DUH for me, cos I actually did look it up, but missed it. Guess I need to put a time limit on how late I fiddle around with Home Assistant. :slight_smile: I made the changes and now everything is working as expected. Thanks to you both!

1 Like