Set binary sensor after X minutes

Hi guys,

I’ve got a self-made Home Assistant Health Check tool. This tool consist of several checks. Some of them will fire an alarm in my house (e.g. power circuit broken, PV broken, etc), or a warning blinks (batteries are dying, etc).

I have also a check if our robot vacuum battery is gett’n low, or if there is any other error. However, this fires an alarm immidiately. But sometimes my robot vacuum has a connection hickup and will thus fire the alarm.

What i want:
a yaml sensor which only change it’s value when e.g. the value template has a specific output for X minutes.

my code for this:

sensors:
    tippi_wan_needs_attention:
      friendly_name: "Tippi Wan vereist aandacht"
      value_template: >-
        {{
            state_attr('vacuum.tippi_wan', 'battery_level')|int < 50 or
            states('vacuum.tippi_wan') == 'error'
        }}

is this even possible? Or do i really need an automation for this?

You can switch to the contemporary template sensor format to take advantage of trigger-based sensors which should allow you to rate limit based on a state attribute:

template:
  - trigger:
      - platform: state
        entity_id: vacuum.tippi_wan
        attribute: battery_level
        for: "00:05:00"
    binary_sensor:
      - name: "Tippi Wan vereist aandacht"
        state: >
        {{ state_attr('vacuum.tippi_wan', 'battery_level') | int < 50 or states('vacuum.tippi_wan') == 'error' }}

FYI:

  1. You do not need to convert all your old template sensors to the new format.
  2. trigger-based sensors will be unknown between restart and the next trigger if you do not add a homeassistant trigger
  3. It is always a good idea to add an availability to template sensors.

Wow, that’s quite powerful! Didn’t knew that exists. Working for almost 1,5 year with HA now, and still learning :wink: thanks for your effort!

They are still relatively new (added in 2021.04) so there aren’t many tutorials or videos out there that highlight how and when to use them.