Wifi-enabling a gate the complete way
Tags: hass, homeautomation, iot, smarthome
Published: 2020-07-20 19:35:22

I'm not sure if there are any Redditors out there on Dev, but if any of those that are are kind enough to click in, FTP, LTL :P

# The why

There are products on the market to automate gates. I especially like [Remootio](https://www.remootio.com/).
I have however been yearning for some DIY electronics action so I took it upon myself to DIY something similar that could not only open and close my sliding gate, but what would tell me if the gate is open or closed.

# The how

I have a Centurion gate motor; they are a popular gate motor supplier in South Africa and they also have their own lineup of home automation products.

# The content :)

## Initial concept

I've had a simple eWeLink relay in the gate box for a while now, which can help me open and close it remotely. This is very useful when a courier decides to stop by as soon as I go out to the shops. The problem with this is that I have no way of verifying that the gate is actually closed after they leave, other than asking them. Two weeks ago, I noticed that my gate control board has a status LED output, which mirrors the Status LED on the control board itself. Upon some nerdy doc reading, I discovered that this light (and thus output), except for the obvious rudimentary error checking, also indicates the gate status as follows:

 * Open: Solid on
 * Opening: flashing
 * Closing: flashing
 * Closed: off

I immediately started looking for solutions as to how to use this somehow.

## And action

I recently flashed my first Sonoff board with ESPHome and I fell in love instantly. First off, it integrates into Home Assistant (I have it running in a cloud instance) with a single click and the YAML OTA is extremely convenient for updating the configuration.

When dealing with the status light, one of my primary concerns was regarding how to check if the light is just flashing or whether its staying on or off. It's not ideal to watch a gate icon flash between open and closed for 30 seconds, wondering whether the gate is actually closing or not. I trawled ESPHome's documentation and eventually saw a line that made my heart skip a beat.

> For example, you can measure if a status LED of a pool controller is permanently active (indicating that the pump is on) or blinking.

It raised a couple of questions for me though, mostly regarding the time frame of the state checks. I decided to power through anyway and headed out to buy a NodeMCU dev board.

The proof of concept worked flawlessly. I built a simple voltage divider with some resistors I had lying around and it actually worked. The final voltage was actually around 1V (3.3V logic) but it still seems to trigger it just fine.

## The installation

I headed out to my gate, armed with a NodeMCU hanging onto a breadboard for dear life, and started connecting it up. The dreaded moment of truth finally arrived, but instead of confirming my genius by spluttering to life, nothing happened. After a lot of troubleshooting, I finally figured out that my gate controller outputs about 16V on the 12V port! Not ideal for the cheap YwRobot board I had repurposed to deliver safe 3.3V to my NodeMCU.

## Back to the drawing board

Not to be outdone by a simple voltage spike, I headed back to the interwebs in search of a better solution and there it was! A Sonoff SV.

![Sonoff SV](https://dev-to-uploads.s3.amazonaws.com/i/38882cuh8r4frjezmrpy.jpg)

The Sonoff SV is a simple board which is designed to handle 5-24V; perfect for my rebellious gate controller. As an added bonus, it exposes 3 GPIO pins right on the board!

## The installation v2

It turns out that the Sonoff SV is intended to be used to power DC devices, but luckily, this specific board is extremely hacker-friendly.

Pop out two relays and pretend to remove the jumper that wasn't included with my specific board and you now have a relay that is unpowered, perfect for triggering something. Of course there is a but though; there is always a but. The relay is unpowered but one of the two sides needs to be connected in order to complete the gate trigger circuit.

Also, because I like doing things the right way, I busted out my soldering iron. Now, even calling my soldering skills decent is a pretty long shot, but I managed to bridge the gap and while I was at it I soldered a jumper wire onto the board (the relay inputs do not have headers.

## The aftermath

![HASS view of my gate device ](https://dev-to-uploads.s3.amazonaws.com/i/hfm7l3hbjs98vts6ek4o.png)

At the time of writing this, ESPHome does not have the "gate" device class as per Home Assistant's documentation, but I have just submitted a PR to fix it :) https://github.com/esphome/esphome/pull/1175 (also my first contribution to ESPHome).

Depending on how well this post does, I will show off my horrible soldering skills and I'll add some more information regarding how I installed it in the motor enclosure.

Thanks for reading :)