Trying to setup a light turn on if contact sensor opens between 10pm and 5am. Can't get it to work!


alias: "Porch Lights On "
description: ""
trigger:
  - type: opened
    platform: device
    device_id: 572302359fd0bc80e248d6f31e0bdbea
    entity_id: binary_sensor.front_door_sensor
    domain: binary_sensor
    for:
      hours: 0
      minutes: 0
      seconds: 0
condition:
  - condition: time
    after: "22:00:00"
    before: "00:00:00"
    weekday:
      - mon
      - tue
      - wed
      - thu
      - fri
      - sat
      - sun
  - condition: time
    after: "00:01:00"
    before: "05:00:00"
    weekday:
      - mon
      - tue
      - wed
      - thu
      - fri
      - sat
action:
  - type: turn_on
    device_id: fce1179ec9feb7de71b556f9f068d5a0
    entity_id: light.porch_lights
    domain: light
mode: single

alias: "Porch Light Off "
description: ""
trigger:
  - type: not_opened
    platform: device
    device_id: 572302359fd0bc80e248d6f31e0bdbea
    entity_id: binary_sensor.front_door_sensor
    domain: binary_sensor
    for:
      hours: 0
      minutes: 0
      seconds: 10
condition:
  - condition: time
    after: "22:00:00"
    before: "00:00:00"
    weekday:
      - mon
      - tue
      - wed
      - thu
      - fri
      - sat
      - sun
  - condition: time
    after: "00:01:00"
    before: "05:00:00"
    weekday:
      - mon
      - tue
      - wed
      - thu
      - fri
      - sat
      - sun
action:
  - type: turn_off
    device_id: fce1179ec9feb7de71b556f9f068d5a0
    entity_id: light.porch_lights
    domain: light
mode: single


Conditions are AND logic by default. It cant be in both those specified time ranges at once. You need OR logic:

condition:
  - condition: or
    conditions:
      - condition: time
        after: "22:00:00"
        before: "00:00:00"
        weekday:
          - mon
          - tue
          - wed
          - thu
          - fri
          - sat
          - sun
      - condition: time
        after: "00:01:00"
        before: "05:00:00"
        weekday:
          - mon
          - tue
          - wed
          - thu
          - fri
          - sat

Iā€™m getting this error!

Compare your indention of the conditions to mine.

Got it to work! Top man! Appreciate it man.

1 Like