Time Before and After condition, I´m going crazy

Is pretty simple. I want to activate a Scene when the motion sensor goes on between certain time, and another Scene if it goes on between other time. Also turn off the lights when the motion sensor goes off.

But I´m pretty sure I´m using time condition before and after in a wrong matter because the just don work when they should.

Here is the code:

alias: Motion Detector luz Closet
description: ''
trigger:
  - platform: state
    entity_id: binary_sensor.sonoff_a44000d616
    to: 'on'
    id: 'on'
  - platform: state
    entity_id: binary_sensor.sonoff_a44000d616
    to: 'off'
    id: 'off'
condition: []
action:
  - choose:
      - conditions:
          - condition: time
            after: '08:15:00'
            before: '23:00:00'
          - condition: trigger
            id: 'on'
        sequence:
          - service: scene.turn_on
            target:
              entity_id: scene.luces_closet
            metadata: {}
      - conditions:
          - condition: time
            after: '23:00:01'
            before: '08:14:59'
          - condition: trigger
            id: 'on'
        sequence:
          - service: scene.turn_on
            target:
              entity_id: scene.luces_closet_sueve
            metadata: {}
      - conditions:
          - condition: trigger
            id: 'off'
        sequence:
          - service: light.turn_off
            data: {}
            target:
              entity_id:
                - light.sonoff_10012bd2e7
                - light.sonoff_10012c04bd
    default:
      - service: light.turn_off
        data: {}
        target:
          entity_id:
            - light.sonoff_10012bd2e7
            - light.sonoff_10012c04bd
mode: single

Thanks a million guys!!
:crazy_face:

What does the automation traces show? If you don’t see the traces, put an id in your automation:

alias: Motion Detector luz Closet
description: ''
id: dfe41220-e30a-48f5-a53a-dcd820a96c87
trigger:

id can be anything: I use a UUID4 from here: https://www.uuidgenerator.net/

Should then be visible in the logbook:

I still struggle to get my head around this too, but I’m pretty sure the second condition is the problem. It can’t be both after 11pm and before 8:15am because the times are considered on the same day.

Someone else may chip in with the best answer, but I think you may want an ‘OR’ in your second condition so you can make it after 11pm OR before 8:15am (two separate conditions in the or statement rather than having them both in one).

The trace just send me to the Default.

Yes it can. Time ranges can span midnight.

I did delete the metadata: { } an it works!

do you care to explain why?

It made me wonder because I only know the service in connection with "data: ". "metadata: " did not work, but later it did - strange.

Great - I’ll need to revisit this!