Timing issue

The following seems to work until we hit Midnight, at which point the light turns on.

The logic intended: Turn on the light when I get home, but only if it’s between sunset and 10PM. All other times, do nothing.

When midnight hits, the condition “before 10PM” becomes true and the sunset condition is already true.

condition:
    condition: and
    conditions:
      - condition: sun
        after: sunset
        before_offset: "-1:00:00"
      - condition: time
        before: '22:00:00'
      - condition: state
        entity_id: device_tracker.melanies_iphone_red
        state: 'home'
  action:
    - service: switch.turn_on
      entity_id: switch.entertainment_center

So, I can’t figure out how to get the action to fire between midnight and sunrise.

Would I create an AND condition to first handle 12:01AM through Sunrise, and then another AND condition for Sunset - 10PM separated by an OR condition?

“If it’s before sunrise and the phone is home, do this, OR if it’s after sunset and prior to 10PM, do that.”

I’d add another condition for either after: '12:00:00' or after: sunrise

After 12:00:00 would be noon wouldn’t it? Are we going for “after midnight?”

So if I do sun: after sunset and sun: after sunrise, then I’m eliminating everything between sunrise and sunset, correct?

Either should work, that’s the point.

Using after: 12:00:00 means it’ll only be valid between after midday and before 22:00, with the further condition of needing to be after an hour before sunset.

Using after: sunrise should cover sunrise to midnight, with after: sunset ensuring it can’t fire before then.