Automation not working motion sensor based on time

I have an automation that I want to trigger when it see’s motion between 11pm and 6am and stays on for 5 minutes then resets and waits for the next motion. here is the code from my automation.yaml file. This is not working and I can not understand why.

- id: '904'
  alias: Hallway Sensor Night
  trigger:
  - entity_id: binary_sensor.hallway_motion_sensor
    for: 00:05:00
    from: 'off'
    platform: state
    to: 'on'
  condition:
  - after: '23:00'
    before: 06:00
    condition: time
  action:
  - data:
      entity_id: light.hallway
    service: light.turn_on

Thanks

Hi this is my configuration for the front door after sunset to sunrise. So if front door or motion is detected it will turn ON lights for 3mins. Also the state of the light has to be OFF. so if you turn it ON it will stay ON. Automation will only work under certain conditions. i have another automation to turn off lights at 10pm incase was turned on manually and then the 3min automation will start.

- id: fronthallway_lightson_for_3min
  alias: FrontHallWay Lights ON For 3min
  initial_state: true
  hide_entity: false
  trigger:
    platform: state
    entity_id: binary_sensor.front_hallway_motion, binary_sensor.front_door
    to: 'on'
  condition:
    condition: and
    conditions:
      - condition: state
        entity_id: switch.front_hallway_lights
        state: 'off'
      - condition: or
        conditions:
          - condition: sun
            after: sunset
          - condition: sun
            before: sunrise
  action:
    - service: switch.turn_on
      entity_id: switch.front_hallway_lights
    - delay: '00:03:00'
    - service: switch.turn_off
      entity_id: switch.front_hallway_lights

The automation’s trigger requires the motion sensor to be on for at least 5 minutes before the balance of the automation is evaluated. Is it possible that your motion sensor fails to remain in the on state for an uninterrupted 5 minutes?

I don’t know what kind of motion sensor you have but some have short timeouts. In other words, unless they see constant motion, they will quickly return to the off state.


EDIT
Ignore my question. Your automation is waiting for the 5 minutes of continuous motion before triggering. However I don’t believe this type of trigger is what you actually want to to do. You want the light to turn on for 5 minutes (when motion is detected) then automatically turn off.

I believe the times need to be in double quotes… (or single not really sure docs show double)


for: "00:05:00"

Or

for:
  minutes: 5

Your before time also is not in double-quotes

The time can be specified with or without quotes (single or double).

I ran this simple automation:

- alias: 'test unquoted for'
  trigger: 
    platform: state
    entity_id: input_boolean.toggler
    to: 'on'
    for: 00:00:15
  action:
  - service: persistent_notification.create
    data_template:
      message: 'Duration: {{ trigger.for.seconds }}'
      title: 'Test complete'

and after 15 seconds it generated this message:

Screenshot%20from%202019-09-04%2021-28-50

His automation telling to trigger the lights after 5mins of motion detected…
try this

- alias: Turn on light there is movement
  trigger:
    platform: state
    entity_id: binary_sensor.hallway_motion_sensor
    to: 'on'
  condition:
    condition: time
    after: '23:00:00'
    before: '06:00:00'
  action:
    service: homeassistant.turn_on
    entity_id: light.hallway

- alias: Turn off light 5 minutes after last movement
  trigger:
    platform: state
    entity_id: binary_sensor.hallway_motion_sensor
    to: 'off'
    for:
      minutes: 5
  condition:
    condition: time
    after: '23:00:00'
    before: '06:00:00'
  action:
    service: homeassistant.turn_off
    entity_id: light.hallway

I think you’ve correctly interpreted what @damato300x7 is attempting to achieve (turn the light off after 5 minutes) as opposed to what the automation presented is actually doing (waiting for 5 minutes of continuous motion).

Yes you are correct. I want them to turn off after 5 minutes. I have changed it. We will see if it works tonight.

Let’s say there’s motion detected and the light is turned on. Do you want the light to turn off:

  1. Five minutes after being triggered.
    The light turns off 5 minutes later regardless of the motion sensor’s state.
  2. After five minutes of inactivity.
    The light turns off only after the motion sensor has reported no activity for 5 minutes.

It worked as intended with Bsodi example.

Thanks