Shelly 1 as a garage door opener, reed switch woes

Hello everyone,

I have a Shelly 1 serving as a garage door opener in Home Assistant. I have configured it via MQTT and everything is working fine, except for a small glitch related to the reed switch.

The problem is that everytime the reed switch changes state (garage door opens or closes), the Shelly is sending two event to MQTT.

Here’s a screenshot I took while following the state topic on MQTT.
The garage door was closed (value 1), then I opened it and value goes to 0 but then quickly goes to 1 and back to 0 again. And you can see a similar thing happening when I close the garage a few seconds later.

The problem is that for example, I always get two notifications in HomeKit when opening/closing the garage (open saying the garage opened, and the other ir closed). It also means some automations run when they shouldn’t.

Anyone have any idea what could be causing this? Is my reed switch crap?

No, it’s perfectly normal for switch contacts to bounce.

How are you getting the binary sensor into home assistant?

There are a few ways to correct switch contact bounce.

I’m using this config:

cover:
  - platform: mqtt
    name: "Garage Door"
    position_topic: "shellies/GarageMotor/input/0"
    command_topic: "shellies/GarageMotor/relay/0/command"
    availability_topic: "shellies/GarageMotor/online"
    retain: false
    payload_open: "on"
    payload_close: "on"
    payload_stop: "on"
    position_open: 0
    position_closed: 1
    payload_available: "true"
    payload_not_available: "false"
    device_class: "garage"
    unique_id: "garage_door"

So it’s simply using MQTT topics. Is there a way to compensate for the bounce using MQTT?

What I did is flash the shelly with ESPHome and set up a delayed_off filter there.

binary_sensor:
  - platform: gpio
    pin:
      number: D5
      mode: INPUT_PULLUP
    id: garage_open
    internal: true
    filters:
      - delayed_off: 50ms

Thanks but hopefully there’s an easier solution via software. Flashing another firmware seems a bit overkill, but if nothing else works I might just try that.

I’m very new to HA so I’m not sure what are my options here but at the very least I should be able to code something that listens to that topic (shellies/GarageMotor/input/0), debounces it, and pushes to another topic (shellies/GarageMotor/input_db/0). Then I’d configure the cover in HA with the latter topic.

Hoping there’s something in HA I can use to get around this.

Create a binary template sensor from your mqtt sensor and use the delay on/off options to debounce it:

That looks promising! To use this, I’d need to:

  1. Create a binary_sensor from the MQTT topic using this
  2. Similarly create a switch for the MQTT topic
  3. Create the binary_sensor template wrapping the entity create in step 1 with the necessary on/off delays
  4. Create a cover template reading the state from the entity created in step 3 and operating the switch in step 2

Is that it?

I am using a shelly via mqtt with reed switch, I dont have that issue. If you manually trigger the read switch, do you still get the double signals?

Is it just a matter of getting the 2 pieces of the reed switch closer together?