Sensor door and light-automation

Hi
I try to create automation but something wrong
when I open door, close door, and open again - the light its turn off even in 30 secondes
I try after 10 minutes the light its turn off

what wrong?

- id: '1576345901538'
  alias: 'Bedroom Door sensor '
  description: ''
  trigger:
  - entity_id: binary_sensor.door_window_sensor_158d0004184b4e
    from: 'off'
    platform: state
    to: 'on'
  condition: []
  action:
  - alias: ''
    data:
      entity_id: light.80874008b4e62d56a7e1
    service: light.turn_on
  - delay: 00:10:00
  - data:
      entity_id: light.80874008b4e62d56a7e1
    service: light.turn_off

First of all, could you explain what exactly you want to achieve?
I presume it is to have the light on for 10 minutes after the door was open, but who knows…

Speaking about the solution, I’d recommend to use timer instead of delay as to start with.
Create a timer and start it every time your door is open. You’ll need a second automation that triggers when your timer finishes and it should actually turn off your light.
Let me know if you need further help with it.

yes this what I want to achieve

if I create a timer, every open door the timer will work? It was a problem. maybe I open this door 3-4-5 times and the timer will start each time

Have you read the documentation on timer, the very first paragraph?
You need to define one timer in your configuration and on opening the door call timer.start service for the particular timer (so you always have one timer).
The result is your timer will finish 10 minutes after the last time your door was opened (and the light will be turned off as a result).

how i create timer ?

It it clearly documented as pointed out by @AhmadK

How does it fit into the automation code?

i create the timer

Respectfully keep reading through the documentation. It is all explained there with examples. But to give you an additional reference I did this;

confi.yaml

timer:
  carer:
    duration: '00:25:00'

automatons.yaml

- id: '1541766423795'
  alias: Carers lights
  initial_state: 'on'
  trigger:
  - platform: state
    entity_id: binary_sensor.front_door
    to: 'on'
  condition:
    condition: state
    entity_id: sun.sun
    state: below_horizon
  action:
  - service: light.turn_on
    entity_id:
    - light.hall_light
  - service: timer.start
    entity_id: timer.carer
- id: '1551277334505'
  alias: carerfinished
  trigger:
  - platform: event
    event_type: timer.finished
    event_data: 
      entity_id: timer.carer
  action:    
  - service: light.turn_off
    entity_id:
    - light.hall_light
    - light.bedroom_light
  hide_entity: false

Basically this is my translation from the documentation and it works fine for me. In my case. It is well documented but does require you to learn and understand how to configure it. That will stand you in good stead for all future automatons/configurations.

3 Likes

Thank you. It’s works (:grinning: