Automation condition based on time and sun state

I’m running 2023.6.1 and one of my long time automations is now failing on the condition step.
I have a motion trigger to turn on a night light with a condition if Time is after 11pm and Sun is Before Sunrise. This automation used to work perfectly, but now its failing. I tried reordering the conditions to have sunrise check first then time or vice versa. Trace shows it failing if I trigger it at 3am. Its passes the before sunrise, but fails on the after 11pm. If time is first condition, at 3am it fails the after 11pm check.
Any ideas how to get this condition working again?

can you post what you have?

Here’s the yaml. I have flip flopped the two conditions and tried each way, both unsuccessfully.
Thanks

alias: Midnight Snack Motion ON
description: “”
trigger:

  • platform: state
    entity_id:
    • binary_sensor.main_floor_motion
      from: “off”
      to: “on”
      condition:
  • condition: sun
    before: sunrise
  • condition: time
    after: “23:00:00”
    action:
  • type: turn_on
    device_id: 78bc9ac97df84be20cab50ebd8a7a80c
    entity_id: switch.counter_lights_plug_switch
    domain: switch
    mode: single

From the documentation:

Reference: Time Condition

Change it to this:

  - condition: sun
    before: sunrise
  - condition: time
    after: '23:00:00'
    before: '08:00:00'
1 Like

Thank you. Ill try it out. Its definitely a new update that I didnt realize I needed to implement since this automation has been working for over a year in the past.
Thanks for catching this.
Jeff

1 Like