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
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.
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).