Debounce a Binary-Sensor in HA?

I have a problem. I have a binary sensor connected to a burner of the heater. As soon as the burner starts, I get a clean 1 sent. But when the burner turns off, numerous 1’s and 0’s are sent within 2 seconds. Only after that comes the clean 0.

So it is a bounce problem.

Is there a way to debounce the sensor in Homeassistant?

I would create a template binary sensor then use an automation to change the new sensors state based on the heater sensors state.

In the automation I would would have it delay state change until state held >2seconds or whatever is needed. This also allows you to make it ON/OFF

If your concern is just automating when the burner is in or off, you could have the automation have that state for x seconds before firing too.

Could be an use case for the statistics sensor …

Which integration are you using for your binary sensor?

Some of them have options for debouncing.

I found a solution :slight_smile:

- platform: template
  sensors:
    brenner_heizung_status:
      value_template: "{{ is_state('sensor.brenner', '1') }}"
      delay_off:
        seconds: 2
      friendly_name: "Brenner Heizung"
1 Like

If you had answered my question I could have told you that a week ago.

I could be doing something wrong, but VS Code is throwing an error for delay_off when making a template. (Home Assistant V2023.2.3, code-server: v4.9.1). I copy/pasted the code by Tomac84 into my configuration.yaml, checked the documentation on templates here: Template - Home Assistant, used their examples, and still get an error.

I wanted to post an alternative solution incase anyone else is running into this same issue.

### Michael Iphone Ping Debounce ###
- platform: template
  sensors:
    v_precence_michael:
      friendly_name: "V Presence Michael"
      value_template: >-
        {% if is_state('device_tracker.v_michael_phone_ping', 'home') %}
          home
        {% elif as_timestamp(now()) - as_timestamp(states.device_tracker.v_michael_phone_ping.last_changed) > 1020 %}
          away
        {% else %}
          home
        {% endif %}

If anyone has advice on how I am using delay_off incorrectly or if it is depreciated, it would be helpful.

1 Like