Switch chatter

I have a simple integration in HA to check and control my garage door; 1 relay output to open/close, and 1 switch input to check if the door is open or closed.
I added an automation in HA to send a notification every time the door is opened (so I can check on my smartphone when the door opens). The thing is I always get 2 notifications when the door opens. I am wondering if it could be related to switch chatter, and if so, if there is a way to solve it. Any suggestions?

You should use a binary sensor to know the status of the gate.
You can use pullup or pulldown to avoid debouncing on the gpio. And add delayed_on_off, for example if the gate swings and makes the sensor change state several times.

One switch input? What is it exactly, is it a physical sensor? A reed switch or what? What other sensors are on the door?

Where is your esphome config? Where is your automation config?

How do you expect anyone to help you if you don’t provide any actual details? With the tiny information you’ve provided, you’re just going to get a bunch of people making guesses and then you wasting your time trying them all.

Always provider as much detail as possible! You’re question as is would be similar to calling an auto mechanic and saying, “my car is making a noise, what’s wrong with it?” You think he is going to be able to pin down the exact problem with that information and tell you why your car is making a noise? Of course not, no one could and we can’t do it either…

What is firing off the notification? I’d start there. You probably have a duplicate causing the notification to go off.

I’ve checked what’s firing off the notification, can’t find any duplicates.
The sensor is a simple reed switch, no other sensors.
Very basic code for the sensor, automation is set up via HA.
I’ll check the delayed-on-off option walberjunior suggested.

Look at the sensor history in the home assistant at any time you opened the gate. If the state is OFF ON OFF ON it is debouncing.
It would be good if you posted the esp and automation yaml

hmm, good tip checking sensor history logs. Says “was opened”-“was closed” with long intervals, so no debouncing issues.

here’s the code:

  • ESP:
  name: esphome-web-58adf3
  friendly_name: ESPHome Web 58adf3

  board: esp01_1m

# Enable logging

# Enable Home Assistant API
    key: "*******************************************************"

- platform: esphome

  ssid: !secret wifi_ssid
  password: !secret wifi_password

  # Enable fallback hotspot (captive portal) in case wifi connection fails
    ssid: "Esphome-Web-58Adf3"
    password: "*****************"

  - platform: gpio
    name: Garage Door
    pin: 5
    id: garage_button
    icon: "mdi:garage"
  - platform: gpio
    name: "GaragepoortOpenDicht"
      number: 4
      inverted: false
        input: true

  - platform: template
    name: Garage
      - switch.turn_off: garage_button
      - switch.turn_on: garage_button
      - delay: 0.3s
      - switch.turn_off: garage_button
  • Automation:
platform: state
  - binary_sensor.esphome_web_58adf3_garagepoortopendicht
from: "off"
to: "on"

service: notify.notify
  message: Garagepoort geopend

I don’t see anything wrong with the settings.
Did you “zoom in” on the history (put an interval of just 5 minutes, for example)?

I think you’ll have to look at the automation traces.

Since your switch doesn’t return any status I would change it to (it won’t solve the problem):

  - platform: gpio
    pin: 5
    id: garage_button

  - platform: template
    name: Garage
    icon: "mdi:garage"
      - output.turn_on: garage_button
      - delay: 0.3s
      - output.turn_off: garage_button

I don’t use ESPHome, strictly MQTT, but here’s what I don’t get. Why are you triggering the switch so many times. Its a relay. It only really needs to be triggered 1 time. If its ON it turns OFF and if its OFF it turns ON.

I’d start there.

Because he wants to simulate pressing a button.

But for some reason he put a turn off first to make sure the relay is off.

Ok. Sounds weird and complicated though.

Guess I need to read up on esphome.

In fact, this is how the gate button works.
He wants to control a gate. Normally the gates are controlled by a button, so each time he presses the button and releases it, a command is sent.
So he added a relay to play this role and simulate pressing the button:

  - platform: template
    name: Garage
      - switch.turn_off: garage_button # Kind of unnecessary, if the relay is already off, there is no need to turn it off again.
      - switch.turn_on: garage_button # Same as pressing the button
      - delay: 0.3s # Adds a delay to give the relay time to change state. Off to on in this case
      - switch.turn_off: garage_button # Same as releasing the button