Light motion at night automation help

I’m stumped as to why the following automation is not getting trigger.

- id: turn_on_family_room_lamps_with_motion_at_night
  alias: Turn On Family Room Lamps If There Is Motion At Night
  trigger:
    platform: state
    entity_id: sensor.foyer_motion
    to: 'active'
  condition: 
    condition: and
    conditions:
    - condition: state
      entity_id: sun.sun
      state: 'below_horizon'
    - condition: time
      after: '22:30'
    - condition: sun
      before: sunrise    
  action:
    service: homeassistant.turn_on
    entity_id: switch.family_room_lamps

Any help would be appreciated.

Thanks!

Midnight!

After 22:30 means between 22:30 and midnight.

Before sunrise means between midnight and sunrise.

Combine the two conditions and there is never a time that satisfies both of them.

I just realized that looking it over again. Dope!

I would love to have one automation which would cover everything after 22:30 until sunrise the next day.

Is it necessary to check if the sun is below the horizon AND the time is later than 22:30? Unless you live near the Arctic, it can be assumed the sun is below the horizon by 22:30.

If we use that assumption then we can simplify the filtering to:
(Time > 22:30) OR (Before sunrise)

Then I think it looks like this in YAML (I have not tested it):

  condition:
    condition: or
    conditions:
      - condition: time
        after: '22:30'
      - condition: sun
        before: sunrise
1 Like

Thanks! I will give it a try tonight.

Did you ever solved this ?