Automation conditions over 2 days (overnight)

Hi. I’m adjusting my bathroom nightlight automation. Current config:

trigger:
  - type: motion
    platform: device
    device_id: a5999fbb3c5eebb1f67dacf2b2a83a97
    entity_id: binary_sensor.hue_bathroom_sensor_motion
    domain: binary_sensor
condition:
  - type: is_illuminance
    condition: device
    device_id: a5999fbb3c5eebb1f67dacf2b2a83a97
    entity_id: sensor.hue_motion_bathroom_light_level
    domain: sensor
    below: 30
  - condition: time
    after: '22:30:00'
    weekday:
      - mon
      - tue
      - wed
      - thu
      - sun
      - sat
      - fri
  - condition: sun
    before: sunrise

This isn’t working. Looking at the traces, at 0330 it fails as the time is not ‘after 2230’ as per the config. Which makes sense, but of course I mean ‘after 2230 that night’.

This worked before when the conditions were just time or just sun. Now I am using both sun and time as conditions it is failing.

Is this possible the way I want, does anyone know?

Thanks,
Matt

My understanding is
After 22:30h means between 2230h - Midnight
and
Before sunrise means between Midnight - Sunrise

Therefore as conditions are automatically ‘and’ then any trigger after midnight will not pass both the above conditions.

I would try putting the 2 conditions as an ‘or’ statement like this:

- condition: or
  conditions:
    - condition: time
      after: "22:30:00"
      weekday:
        - mon
        - tue
        - wed
        - thu
        - fri
        - sat
    - condition: sun
      before: sunrise
1 Like

Thanks. This makes sense and looks good. Found this page in the docs (should have looked first…): Conditions - Home Assistant and I’m using mixed AND and OR. Will test tonight.

Also - the docs explain that, for the time condition, if both before and after are specified then can span across the midnight threshold. Smart.

Matt

Worked nicely. Thanks.