What are the entity IDs (should start binary_sensor. and light.) for the door sensor, motion sensor and light? I think you want two triggers: no motion for 20s and door closed for 40s, with matching conditions so that the action only runs when the second criterion becomes true — but I don’t trust device conditions.
Making up your entity IDs:
trigger:
- platform: state
entity_id: binary_sensor.your_door
to: 'off'
for: '00:00:40'
- platform: state
entity_id: binary_sensor.your_motion
to: 'off'
for: '00:00:20'
condition:
- condition: state
entity_id: binary_sensor.your_door
state: 'off'
for: '00:00:40'
- condition: state
entity_id: binary_sensor.your_motion_sensor
state: 'off'
for: '00:00:20'
action:
- service: light.turn_off
target:
entity_id: light.your_light
Yes, i did exactly the same. I put my sensor ids to the code and still not good. It works, but it turns off the lamp immediately, its like it skips the conditions. The trigger works, the action work, but the conditions is not checked before the action.
I experimented with a delay. I made a simple automation that if the door is closed, after that there is a 10 sec delay and than it turns off the lamp, which works. But why the above mentioned code is not working?
There should be something obvious which im not seeing
The trigger should fire 40s after the door closes and 20s after motion stops. If the trigger works, then the lamp doesn’t go off “immediately” when the door is shut. It goes off immediately after the trigger fires, but that’s a time after the last physical change as defined.
If it does turn off immediately after the door shuts, please look at the logbook to check you don’t have another automation doing this; and if not, please post the full automation trace for the latest run where it “turned off immediately”; as well as the code for your automation even if you think it’s the same as above.
But in your code the triggers and the conditions are the same, if i omit the conditions i will achieve the same result, wont i? So its like HA wont check the conditions.