I’m trying to get a text on a display if my doorbell is rung or not. I’m using a door sensor (the Aqara door/window sensor) to check if the coil is activated in the chime. So far i have this in my code:
Now i get the text on my display, but it’s only displayed on it while the sensor is active, but i want the text to be displayed for a few seconds so i can read it properly. Does anyone know how to put like a delay in a if/else lambda? I’ve tried lots of stuff but can’t figure it out.
I would use a global variable of type integer. When the sensor triggers, use on_press or one of the other automation triggers to set that global to the number of seconds you want to text to display. Then use a time component that fires every second (which I believe is the default). Every time time triggers, subtract 1 from the global variable. The timing on that won’t be precisely 1 second, but it will be close enough for this sort of thing.
Display the text only if the global variable is >0.
(I’ve only explained this briefly because I don’t know if you are already familiar with the things I mentioned. All the items are straightforward ESPhome mechanisms.)
Of course, if your doorbell doesn’t ring for a couple of decades, that global integer will wrap around, but I imagine that’s OK.