Motion triggered lights only after a defined time and before sunrise

So,

I have setup where outdoor lights turn on at sunset and stay on unconditionally to 11pm. After 11pm, but before sunrise I want them to turn on only, if motion sensors report occupancy. Unfortunally, the following automation does not work, probably due to a collision in the condition statement.

alias: motion lights after permanent lights
trigger:
  - platform: state
    entity_id: binary_sensor.motion_sensor
    from: 'off'
    to: 'on'
condition:
  - condition: sun
    before: sunrise
  - condition: time
    after: '23:00:00'
action:
  - service: light.turn_on
    data: {}
    entity_id: light.grp_outdoor_lights
mode: single

I guess - for HA - the time of triggering cannot be between 11pm and before sunrise, what could I do instead?

Cheers

m0wheld

Correct, as explained in the docs but you can make the conditions or instead of and as described here.

Isn’t it great we have docs explaining all of this :wink:

Try this

condition:
  - condition: or
    conditions:
      - condition: time
        after: '23:00:00'
      - condition: sun
        before: sunrise

That would also activate motion-triggered lights before 11pm (after sunset, where they should stay on permantly).

Guess I need to go that extra mile for the time from 11pm to midnight.

condition:
  - condition: or
    conditions:
      - condition: time
        after: '23:00:00'
# https://www.home-assistant.io/docs/scripts/conditions/#time-condition
# "If only after key is used, the condition will be true from the specified time until midnight."
      - condition: and
        conditions:
          - condition: time
            after: '00:00:00'
          - condition: sun
            before: sunrise

No it doesn’t, read the docs I linked.

You are correct and so is @sheminasalam.

For the record:

Note that if only before key is used, the condition will be true from midnight until sunrise/sunset. If only after key is used, the condition will be true from sunset/sunrise until midnight . Therefore, to cover time between sunset and sunrise one need to use after: sunset and before: sunrise as 2 separate conditions and combine them using or .