Request for help with monitoring the state of a gate (open / closed)

Hi all,

Need some help / suggestions - I’m helping a friend in setting up HA and one of the things we want to accomplish is to monitor the state of his gate. This is based on a HySecurity Swingsmart DC20 (link) which has a relay that opens / closes whenever the gate is in that state.

This is the relay:

It’s wired back with the black/red cables to his garage where it was connected to an exotic box that, via a PSTN line connected to it as well, would call out if the gate remains open for a preset period.

I’ve set up an ESP32 with COM to GND and NO to GPIO13 but I get rapid changes between ‘open’ and ‘closed’ lasting between 15 and 220ms, like this:

gate_history

This is the code I use:

binary_sensor:
  - platform: gpio
    pin: 13
    name: magnet
    device_class: door

I have a similar thing set up in my own garage with a simple magnet from Amazon (this one) and it does the trick…

I must be doing something wrong or overlooking something but I have no idea what…

Any ideas / help would be truly appreciated.
Bernard

Is that relay switching AC? They are hefty looking cables. If so, maybe you are picking up noise.

It’s not switching anything at all so noise is my current thinking as well - I’ll have to see when I go back next weekend.

I’d say that pull-up or pull-down resistor from gpio is missing, that way gpio is floating, resulting in rapid changes. You can enable it in esphome’s yaml, usually it’s enough, but if noise is too big you’ll need external one.

Exactly what you said, @Protoncek - I had put a resister on but looks like my soldering was shoddy and it didn’t do its job…

1 Like