I’ve tried your blueprint, and it looks like exactly what I need, and makes it a lot easier to create a door automation than doing it manually, which is great, thanks!
I’m a bit new to Home Assistant though, so forgive me if what I’m about to write is dumb.
I tried using the timeout, and found out that the following scenario does not work as expected:
Use a short delay to experiment (say 3 seconds)
open the door (light turns on as expected)
close the door (light has not turned off yet, waiting for the delay to expire)
start counting seconds
before the delay expires, open the door again (at this point, light is still on)
when the delay expires, even though the door is open, lights turn off.
I would expect the lights to stay on, until I close the door again and the wait time expires.
I believe setting the automation to mode: restart would fix it: if the trigger happens while the automation is running, then restart it (ie. turn the light on again then wait for the closed trigger again).
Update: it also looks like you can use the “wait for trigger” action’s for parameter to set up the wait time, so you don’t have to add another action - delay: !input door_closed_wait.
Here’s how I modified your blueprint to fit my needs:
blueprint:
name: Door Sensor Light
description: Turn a light when a door is opened
domain: automation
input:
doorsensor_entity:
name: Door Sensor
selector:
entity:
domain: binary_sensor
light_target:
name: Light
selector:
target:
entity:
domain: light
door_closed_wait:
name: Wait time
description: Time to leave the light on after door is closed
default: 120
selector:
number:
min: 0
max: 3600
unit_of_measurement: seconds
mode: restart
trigger:
platform: state
entity_id: !input doorsensor_entity
from: "off"
to: "on"
condition: []
action:
- service: light.turn_on
target: !input light_target
- wait_for_trigger:
platform: state
entity_id: !input doorsensor_entity
from: "on"
to: "off"
for: !input door_closed_wait
- service: light.turn_off
target: !input light_target
Hello, I am sorry for the late Reply. I am a bit on and off on the Community.
Great work modifying the blueprint to fit your needs! We are all new at some point. This is actually My first or second blueprint, learning from existing ones
I created my own automation that will turn on the lights when the front door opens after sunset. I also added a rule so that it doesn’t do it for 30 seconds after the lights are turned off (ie. when turning off the lights before leaving the house)
trigger:
- platform: state
entity_id: binary_sensor.z_wave_door_sensor
from: 'off'
to: 'on'
condition:
- condition: sun
after: sunset
- condition: state
entity_id: light.living_room_lights
state: 'off'
for:
hours: 0
minutes: 0
seconds: 30
milliseconds: 0
action:
- service: light.turn_on
target:
entity_id: light.living_room_lights
data:
brightness_pct: 100
mode: single
I want to switch on the light on the balkony and leave it on for 5-6 Mins by opening a door.
All that works great unless i put in that special condition.
My goal is that the light just gets switched on between sunset and 5 o’clock in the morning.
Switching the light on on condition sun - below horizon works too.
Its just something about that “between sunset and 5 o’clock” i guess.
Here’s the entire code.
blueprint:
name: Door Sensor-activated Light
description: Turn on a light when door is opened.
domain: automation
input:
doorsensor_entity:
name: Door Sensor
selector:
entity:
domain: binary_sensor
switch_target:
name: Schalter
selector:
target:
entity:
domain: switch
door_closed_wait:
name: Wait time
description: Time to leave the light on after door is closed
default: 360
selector:
number:
min: 0.0
max: 1000.0
unit_of_measurement: seconds
step: 10.0
mode: slider
source_url: https://community.home-assistant.io/t/door-sensor-turn-on-off-light/255657
mode: single
max_exceeded: silent
trigger:
platform: state
entity_id: !input 'doorsensor_entity'
from: 'off'
to: 'on'
condition:
condition: and
conditions:
- condition: sun
after: sunset
- condition: sun
before: sunrise
before_offset: "-02:00:00"
action:
- service: switch.turn_on
target: !input 'switch_target'
- wait_for_trigger:
platform: state
entity_id: !input 'doorsensor_entity'
from: 'on'
to: 'off'
- delay: !input 'door_closed_wait'
- service: switch.turn_off
target: !input 'switch_target'
Ahh okay I see what you’re trying to do now. I’m not good enough with the coding to do that. But right now, your code is not telling it to turn off the light. The condition is just saying turn the light on if it’s between these times only.
My solution would be to create a second automation to turn the lights off. So a new trigger for when it’s 5AM or 2 hours before sunrise with the action being to turn the lights off.
I’m currently working on an extend to this blueprint (I will probably do some more changes, but feel free to try) that will enable open and closed actions. With those actions you can customize what the door sensor will do not only for turning a light on, with it you can also like turn a power plug or something like that. Or use conditions as actions for timed events.