ESP8266 Smart Shutter Controller

Introduction

The windows of our new house have classic white roller shutters that have to be closed by hand, using a roll next to the window. Since we are renovating it, I decided I wanted to have something automatic and flexible.

My requirements for the controller:

  • Remote control using handheld 433Mhz or 868Mhz remote.
  • Automatic opening and closing based on simple and advanced timers. For example, I want the shutters to close randomly within 30 minutes after sunset. The controller should handle this autonomously and not depend on some external trigger or online service.
  • Integration into home automation systems, such as HomeAssistant or OpenHAB. This means network connectivity and an open interface.
  • Components should be standard or easy to source, to avoid problems in 10-15 years...

After a long online search for an off-the-shelf solution, I found some products. The more intelligent ones are based on gateway boxes that communicate to a manufacturer's 'cloud service'. This allows the use of a smartphone app as remote control and the configuration of timers. But besides the proprietary aspect, assembling a set with motors/gateway/remote gets expensive quickly, so I was not very enthusiastic about these.

I started to look to at building my own controller. Online I sourced suitable motors to be mounted inside the existing roller axle and eventually sourced some from here. Basic motors are easy to find and powered via 3 wires. Switching the direction is achieved by changing over 1 wire. There is no feedback on the position of the shutters however, but there are adjustable limit switches inside the motor to set-and-forget the allowed travel.

So eventually the plan started to take shape:

  • Cheap 433Mhz remote and receiver.
  • SPDT relays to switch the live wire to the shutter motors.
  • ESP8266 WiFi microcontroller with battery-backed RTC, programmed from the Arduino IDE to save development time.
  • The RTC can be synced from an internet time-server.
  • Configuration of the autonomous timers via an onboard webpage.
  • MQTT support for home automation.
  • DIN-rail mounted to integrate it inside an electrical cabinet.

Remote and receiver

The most suitable remotes I could find are based on the PT2264 encoder chip. Many remotes can be found on the usual websites and eventually I settled for a 15-channel remote pictured below on the left. Unfortunately, the buttons are not marked, but each row of 3 keys can represent one shutter motor, left=up, middle=stop and right=down. Additionally, these remotes use a 12V cell for power.

There also exist wall-mounted 433Mhz switches that I could add, or more classy flat remotes such as those on the right.

To make the ESP8266 receive the button presses, I sourced a simple super heterodyne receiver PCB, shown below on the right. Adding a piece of wire (17cm) as antenna made it useable from distances >20 meters.

For the receiver, I discovered the RC-Switch library for Arduino, and this combination of remote and receiver worked immediately with the supplied example. On to the next part!

Relays and drivers

Initially I wanted to use solid state relays, but eventually I settled for 'normal' relays. Each channel needs 2 switches to be able to switch the direction or remove mains power from the motors altogether.A benefit of using SPDT relays is that I can physically avoid the shortcircuiting of the mains (e.g. enabling both relays because of a software fault), since the first relay can disable the second when it is active.

So I settled on Omron G5LE-1-VD 5V relays. There are a lot of counterfeit Omron products though, so I found it safer to order these critical components through Conrad and RS.

To provide enough current to drive the relays, an ULN2803 Darlington array preceded by an 74HC240 inverting buffer was chosen. However, the ESP8266 does not have a lot of GPIOs, which I easily solved with a PCF8574A I2C I/O expander. This has the benefit that the relay outputs are disabled at power-ip, and the ESP first has to enable them. This sidesteps possible undesirable glitches during startup or reset.

In any case, the relays will be driving strongly inductive loads, so it makes sense to add a snubber circuit to their output.

Microcontroller and firmware

For the brain of the controller, I chose the Wemos D1 Pro for its possibility of an optional external WiFi antenna (useful when the controller will be mounted inside an electrical cabinet) and larger flash memory to serve webpages. The onboard webpages show and control the actual state of the channels, and allow the controller to be configured. Below are some screenshots of the onboard webpages.

The 433 Mhz remote can be paired to "actions" on each channel using a "learning mode". Furthermore, timers can be set up using classical time-based parameters, or using events such as sunrise or sunset. A random delay can be added to the triggers. This should hopefully give an "occupied" impression of a home during longer periods of absence.

Initially, when the controller is not linked to a WiFi network or used standalone, a push on a microswitch makes the ESP8266 set up a WiFi access point. Connecting to this AP immediately forwards to the configuration pages.

PCB Design

Since my goal was always to be able to integrate the controller inside the electrical installation of my home, I wanted it to be mounted on a standard DIN-rail. Because of the space taken up by all the relays, I went with a 12 slot DIN-rail enclosure, the largest I could find. Powering the controller and receiver is a Hi-Link 5 Watt 5V AC/DC converter. I also added a small fuse in an easily accessible spot. The MAX DS3231 RTC is backed with a coin-cell so that time is kept when an NTP server is not (immediately) available.

The wiring to the motors connects via large 5.04mm pitch screw terminal blocks.

Originally I also planned to have a 433Mhz antenna, but the small piece of wire proved to be sufficient as well. In fact, it picks up the remote's signal from 30m away, way outside the house...

Installation

TBW