I also found out that switching off lights with one automation that waits for sensor state to be off for xx minutes does not work well: it seems multiple off timers start, each time the motion sensor state changes to off, and the lights start to turn off randomly until all timers have ended. I didn’t notice it at first because the delay time was only 30 seconds, but it gets annoying with a 30 minute delay time.
So, back to using a timer script with the automation to trigger it…
hello, I’m new to Home Assistant. I have made an esp8266 MQTT motion sensor. when motion is detected it will be sending MQTT message “Motion Detected” to HA… what I want to do he when HA received Motion detected message I want the light to turn on and keep it on for 3 mins then turn it back off. I have made an automation to turn on the light when motion is detected. someone, please help me can I make it to auto turn off after 3 mins?
You basically just need to scroll up in this thread, and you will find plenty of examples where lights are turned on triggered by motion detected or sun setting, and then turned off after a set amount of time.
Hello @Ashfaaa
This is the way I’m doing it, thanks to @Pilot, which I’m happy with…
- alias: Light off after 90 sec when motion off
trigger:
- platform: state
entity_id: binary_sensor.motion_sensor
to: 'off'
for:
minutes: 1
seconds: 30
action:
- service_template: light.turn_off
entity_id: group.kitchen
Not sure if it helps, but my lights only become motion activated at 9pm. I just wrote an automation to turn my motion automations on at 9 and off at 7am when they become normal lights. Iv hardcoded these times but you could use a input_number to set the time they cone off/on.
automation motion on at 10:
alias: Motion - on at 10pm
initial_state: True
hide_entity: False
trigger:
platform: time
at: '22:00:00'
action:
service: automation.turn_on
entity_id: automation.motion_1_on__lights_on,automation.motion_1_off__lights_off
automation motion off at 11:
alias: Motion - off at 7am
initial_state: True
hide_entity: False
trigger:
platform: time
at: '07:00:00'
action:
service: automation.turn_off
entity_id: automation.motion_1_on__lights_on,automation.motion_1_off__lights_off
I followed someone else’s idea to try and the motion sensor tries to keep turning off unless there is motion, I also have built in time as I want the lights to be dimmer at certain periods. Here’s my automation around it:
- alias: Motion Home Hallway
trigger:
- platform: state
entity_id: binary_sensor.neo_coolcam_battery_powered_pir_sensor_hallway
from: 'off'
to: 'on'
condition:
- condition: state
entity_id: light.hallway
state: 'off'
- condition: or
conditions:
- condition: state
entity_id: input_select.chris_status_dropdown
state: 'Home'
- condition: state
entity_id: input_select.val_status_dropdown
state: 'Home'
- condition: or
conditions:
- condition: sun
after: sunset
after_offset: "-1:00:00"
- condition: sun
before: sunrise
before_offset: "1:00:00"
action:
- service: scene.turn_on
data_template:
entity_id: >
{% if now().hour >= 20 or now().hour <= 7 %}
scene.hallway_nightlight
{% else %}
scene.hallway_bright
{% endif %}
- alias: Lights Hallway Off
trigger:
- platform: state
entity_id: binary_sensor.neo_coolcam_battery_powered_pir_sensor_hallway
to: 'off'
for:
minutes: 1
action:
- service: homeassistant.turn_off
entity_id: light.hallway
This should be sooooo simple, yet Homeassistant makes it so difficult, writing code and code and everyone tells you something different… specially when there are a lot of different plataforms out there that do the same thing in 3 simple steps…