Add a second hall sensor to Sonoff SV Garage Door Opener

Over a year ago I was in the process of automating things around the house, having recently discovered Raspberry Pi-driven home automation and the associated potential for “fiddling with things”. During this phase, I came across the excellent John’s Tech Blog writeup on how to automate garage door openers using Sonoff SV boards.

This setup uses one reed switch (open/close switch) to sense the garage door state. One sensor is not a lot for a garage door - you can know with certainty whether it’s closed (or opened, wherever you installed your sensor), but other than that the door might be in any position and the home automation wouldn’t have a chance to know. So I wanted to complement this straight away with a second sensor, for sensing both ‘open’ and ‘closed’ positions. Being lazy, I simply added a ZigBee open/close sensor. Which required a ZigBee repeater in the garage. And worked mostly, but wasn’t the most reliable setup imaginable.

More is better

Some months later, looking at the Sonoff SV GPIOs and the associated Tasmota firmware config options, I thought that I should be able to add a second hardwired reed switch to my setup, allowing me to get rid of the ZigBee sensor. At this point, a quick shoutout for the Sonoff SV, as well as the Tasmota firmware project for ESP8266 devices! These little boards are marvelous playthings, not expensive, and provide electronics noobs like myself with an accessible sense of achievement.

Second sensor setup

The main part of the install involved preparing and running cables, getting worked up over cheap connectors, and some of the peculiarities or our garage door installation. The actual sensor setup is pretty straightforward, mirroring the first as described by John (see above):

  • I used IO4, which is located right next to the IO14 pins of the first sensor
  • In the Tasmota config UI, set the GPIO4 to “Switch” “3”
  • (this mirrors the first switch, which is using GPIO14 “Switch” “2”)
  • To make the reed switch work properly, run the console command SwitchMode3 2

That’s it! The sensor status should now show up in the corresponding MQTT channel, in my case that is cmnd/<boardId>/POWER3. And no, I have no clue why a GPIO input status is mapped onto a ‘cmnd’ topic…

Home assistant wrapup

The rest is even simpler - a straight copy of the first sensor configuration in the home assistant setup, in my case the sensors for one Sonoff SV board look like this:

- platform: mqtt
  name: "Tasmota1_Status"
  unique_id: "sensor.tasmota1.status"
  expire_after: 604800
  qos: 1
  state_topic: "tele/<boardId>/LWT"
- platform: mqtt
  name: "Tasmota1_Open"
  unique_id: "sensor.tasmota1.open"
  expire_after: 604800
  qos: 1
  state_topic: "cmnd/<boardId>/POWER2"
- platform: mqtt
  name: "Tasmota1_Close"
  unique_id: "sensor.tasmota1.close"
  expire_after: 604800
  qos: 1
  state_topic: "cmnd/<boardId>/POWER3"

Voila! In my case, one of the things I’m doing with this is setting the value of a home assistant Dropdown Helper to “closed”, “opening”, “open”, “closing” - depending on the statue changes of the two sensors. And I can actually trust this info now!


Waymarks

  • always verify sensor installation location by observing full movement range of garage doors :-D
  • I should have done this earlier