Setting up a garage door opener with Shelly and ESPEasy

Setting up a garage door opener

I recently installed an automatic door opener in my garage and of course I wanted to hook it up to my OpenHAB system. This is what I did:

The garage opener I bought is called Boxer 3000 and it seems similar to almost all other openers on the market. It has a (actually 2) remote controls with one button that controls the opening. One press starts or stops the opening and it runs until it’s fully opened or closed. This model also had an external wire that connected to an open switch, so pressing the switch has the same behavior as the remote control.

I already had installed wifi in the garage (a must, isn’t it :slight_smile:) and I then decided to have a WLAN based control for the opener. In the house it’s mostly a mix between Z-wave and Zigbee, but the range to the garage (and also price it turned out) made WLAN the best alternative.

I then got a Shelly 1 and replaced the firmware with ESPEasy, as I was already running that in some other devices in the house. The Shelly has a feature where there are some extra GPIO pins available that I planned to use.

One of the issues with the opener is that you don’t have any knowledge of the state of the door (opened or closed). To fix this I got a small reed switch and mounted it on the door so that the switch would trigger when the door was closed. This was then connected to one of the GPIO pins on the Shelly.

ESPEasy then uses MQTT to communicate with OpenHAB, one topic for reading the sensor (reed switch) and one topic do control the relay (which then controls the door opener).

Overview

Garage

ESPEasy config

I used the image ESP_Easy_mega_20200426_hard_Shelly_1_2M256.bin as firmware. I had initially planned to add some extra sensors for temperature and humidity (always good to keep track of that in the garage), but unfortunately almost no sensors was included in the image. This might be fixed in later release (or you could build your own).

One other thing that was a bit tricky was the state of the GPIO pins at boot. The Shelly has three pins available (GPIO0, GPIO1 and GPIO3), but only GPIO3 could be kept low at boot – if the others two were low, it would not boot correctly. As the sensor switch could be either high or low at boot depending on if the door would be open or not – this meant that only GPIO3 was available if I wanted to have a system that would safely handle a reset / power loss.

The ESPEasy configuration was as follows:

  • One device, named status, is enabled in ESPEasy, a Switch Input. Use GPIO-3 and internal PullUp. Enable Send to Controller.
  • You need to set up the MQTT connection as well of course.
  • The relay is at GPIO4, but that is called directly from MQTT

I also change some things in the ESPEasy setup (under advanced settings):

  • Disabled the serial port
  • Enabled the rules engine

I added a rule to send the status of the door everytime the Shelly is reset or if the MQTT server is down:

on MQTT#Connected do
  publish shelly_1/status/State,[status#State]
endon

The manual override needed some rules as well; the button input is received on GPIO 5. In the ESPEasy GUI, I added a device named button (normal switch).

on button#state=1 do
  gpio,4,1
endon

on button#state=0 do
  gpio,4,0
endon

OpenHAB config

This was the easy part. I saw some more advanced examples in the forum, but this was enough for my needs.

Thing

Bridge mqtt:broker:mybroker "MQTT bridge" @ "Home" [ host="1.2.3.4", port=1883 ]
{
  Thing topic garage "Garage Door" @ "Home" {
  Channels:
    Type contact : status "Garage Door" [ stateTopic="shelly_1/status/State" ]
    Type switch : control "Garage Door" [ commandTopic="shelly_1/gpio/4", on="1", off="0" ]
  }
}

Items

Contact GarageDoorStatus "Garage Door" <garagedoor> (gGarage)
  { channel="mqtt:topic:mybroker:garage:status" }

Switch GarageDoorButton "Garage Door" <garagedoor> (gGarage)
  { channel="mqtt:topic:mybroker:garage:control", expire="2s,command=OFF" }

// Command should be "Idle", "Open" or "Close"
String GarageDoorCommand "Garage Door"

Rules

I added a String item for the actual command to open or close the door. I can then use this from other rules with GarageDoorCommand.sendCommand("Open") to open the door. For example, when I turn on my Home Alarm system, the garage door is automatically closed.

rule "Init"
when
  System started
then
  GarageDoorCommand.postUpdate("Idle")
end

rule "Open garage"
when
  Item GarageDoorCommand changed from "Idle" to "Open"
then
  if (GarageDoorStatus.state == CLOSED) {
    GarageDoorButton.sendCommand(ON)
  }
  GarageDoorCommand.postUpdate("Idle")
end

rule "Close garage"
when
  Item GarageDoorCommand changed from "Idle" to "Close"
then
  if (GarageDoorStatus.state == OPEN) {
    GarageDoorButton.sendCommand(ON)
  }
  GarageDoorCommand.postUpdate("Idle")
end
3 Likes

This topic was automatically closed 41 days after the last reply. New replies are no longer allowed.