Delay on text

Hello all!

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:

    - platform: homeassistant
      id: openclose
      entity_id: binary_sensor.openclose_3
      internal: true

  sda: D1
  scl: D2
  scan: False
  - platform: lcd_pcf8574
    dimensions: 16x2
    address: 0x3F
    lambda: |-
      if (id(openclose).state) {
      } else {

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. :slight_smile:

1 Like

Or only decrement it if it is positive, or decrement it to a minimum of zero.

I’m not that familliar with those things :sweat_smile: but i’ll start reading into those things. Thanks!