I am having problems with making an automation for my doorbell switch.
If I presse the button the light goes on and must be switched off after xx seconds.
First of all, not formatting your code correctly for a forum post. See here:
It’s really important: there could be lots of errors hiding in there that the formatting doesn’t show, and it’s much easier for us to read and diagnose when properly presented.
The problem seems to be in how you think the if: statement works. It does not wait there until it’s true: it evaluates once (as false, because the light has only just turned on) then continues. Have a look at the various ways to wait:
I’d strongly recommend using entities and state triggers rather than device IDs. Is light.plafondlamp_gang_licht the same as 5ffdf9350cf7ccab9faeff85d7332f1f?
At a guess, though it’s hard to be sure as that code isn’t formatted, your problem is that you check to see if the light has been on for 30 seconds when the doorbell is pressed. If at that point it has been on for 30 seconds the light will be turned off.
If you just want it turned off 30 seconds after it was turned on by the doorbell then you’d want to have an input boolean that was turned on when you turned on the light. Then when the light (or boolean) has been on for 30 seconds turn off the light. Another automation can turn off the boolean whenever the light is turned off (see here).