HomeBridge – MQTT Blinds

After several questions about automating blinds, I found the solution. In this blog I show you how to automate your blinds.

Homebridge

You need to setup your Apple Homebridge based on MQTT first to connect this setup with Apple HomeKit / Siri. For whom did not read my previous blog about setting up your Apple Homebridge based on MQTT you can find it here.

The hardware

When I have collected al the necessary parts, you can setup the test environment like show in the image below.

As you can see I used a NodeMcu v3 Lua ESP-12E WIFI Development Board in this setup to simplify the setup. Connect the ULN2003 Stepper Motor Driver board to to your NodeMcu v3 Lua ESP-12E WIFI Development Board as following:

D1=IN1,D3=IN2,D2=IN3,D4=IN4

Connect 5V directly to Vin on NodeMCU board and to the ULN2003 board. 5V may simply be not enough to be able to control the blinds, even with the higher gear ratio, The ULN2003 can go up to 12V if nessecarry. I’m using the 5V version of the stepper motor and it has worked well for me so far – there’s an 12V version though that should be able to give a higher torque than the 5V. My test roller blind is just 100cm wide and if you have a really wide roller blind I would probably go for the 12V version of the stepper motor.

Software

The Software is a WebSocket based version, So there is no need of an MQTT server but MQTT is supported as well – you can control it with WebSockets andwith MQTT messages. How does it work you ask, well a tiny webserver is setup on the esp8266 that will serve one page to the client. Upon powering on the first time WIFI credentials, a hostname and – optional – MQTT server details is to be configured. But more about this later.

After you uploaded the code to your NodeMcu v3 Lua ESP-12E WIFI Development Board, go to your WIFI settings on your computer. Connect your computer to a new WIFI hotspot named:

AutoConnectAP

and use the Password:

StudioPieters

You will be redirected to this screen and now you can select Configure WiFi.

WOW, How does it works!

When your ESP starts up, it sets it up in Station mode and tries to connect to a previously saved Access Point if this is unsuccessful (or no previous network saved) it moves the ESP into Access Point mode and spins up a DNS and WebServer (default ip 192.168.4.1) using any wifi enabled device with a browser (computer, phone, tablet) connect to the newly created Access Point. Because of the Captive Portal and the DNS server you will either get a ‘Join to network’ type of popup or get any domain you try to access redirected to the configuration portal choose one of the access points scanned, enter password, click Save. The ESP will try to connect. If successful, it relinquishes control back to your app. If not, reconnect to AP and reconfigure.

After you configured your NodeMcu v3 Lua ESP-12E WIFI Development Board, you can connect to your normal WIFI with your computer, phone or tablet and go to the IP address of the device – or if you have an mDNS supported device (e.g. iOS, OSX or have Bonjour installed) you can go to http://{hostname}.local. If you don’t know the IP-address of the device check your router for the leases or more simple check the serial console in the Arduino IDE.

Using MQTT

When it connects to WIFI and MQTT it will send a “register” message to topic /raw/esp8266/register with a payload containing chip-id and IP-address. A message to /raw/esp8266/[chip-id]/in will steer the blind according to the “payload actions” below. Updates from the device will be sent to topic /raw/esp8266/[chip-id]/out

If you don’t want to use MQTT. Simply do not enter any string in the MQTT server form field upon WIFI configuration of the device.

Configuring your blinds settings

Now that everything is installed it’s time to calibrate you Blinds. Open the webpage typing the IP address in your web browser, that is assigned to your NodeMcu v3 Lua ESP-12E WIFI Development Board. As the webpage is loaded it will connect through a websocket directly to the device to progress updates and to control the device. If any other client connects the updates will be in sync. Go to the Settings page to calibrate the motor with the start and end positions of the roller blind. Follow the instructions on the page.

After the calibration of your blinds, you can If you don’t Use MQTT, Use Web interface to open and close the blinds or use the slider to set it on a manual position.

If you want to use MQTT or in this case Homebridge to control your blinds you need to configure your homebridge to connect to your MQTT Blinds.

Homekit2mqtt webserver

To add the new accessories, homekit2mqtt has a build-in web-server. This allows you that easily add new MQTT accessories for Homekit. So to connect to your homekit2mqtt web-server, open your web browser and type:

Raspberry_ip_adress:51888

Now you can login with the username:

homekit

and password:

031-45-154

For this setup I added a accessories to the Apple Homebridge based on MQTT by removing all standard MQTT clients by selecting them and press DEL in the lower left corner.

Then you press + Add, to add my new build roller blind control. In the service field you can select your type of service, in this case want want to add a window covering.

In the Template field you can select a predefined template , in this case we choose None.

In the configuration screen you can fill in the following fields:

ID

Check the serial console in the Arduino for the esp8266 ID

Name

The name you want to give it homekit, eg. Rollerblind

SetTargetPosition

/raw/esp8266/ID/in

StatusTargetPosition

/raw/esp8266/ID/out

StatusCurrentPosition

/raw/esp8266/ID/in

StatusPositionState

/raw/esp8266/ID/in

Identify

At The MQTT Payloads and fill in the following fields:

targetPositionFactor

Number

1

currentPositionFactor

Number

1

positionStatusDecreasing

Number

1

positionStatusIncreasing

Number

1

At the accessoryInformation You can add the Manufacturer model and serial number, but it’s not necessary. Then select Save and close the web browser.

So your InTopic is in this case /raw/esp8266/CHIP-ID/.

3D model

Now that we have the hardware working we need a enclosure for the motor. You can download all files at the end of this article.

TESTING FASE

After installing my blind with the standard 5V 28BYJ-48 Stepper Motor. It work kindoff… because my blind are 2 meter wide and needs to go down proximally 2,5 meters the motor isn’t strong enough. So I’ve ordered a new 12V 28BYJ-48 Stepper Motor, and replaced the 5V one. This also required another 12 V power supply. Unfornually this motor also has not enough torque to open the blinds once they were open.

So back to the drawing board and figure a way out to get this thing working with bigger blinds. Want to see how to fix this problem, come back soon, for part two!

Donate

Since October 2015, StudioPieters® has been writing this blog. Help accelerate its development with a small contribution! StudioPieters® is open source, and 100% free . Please consider donating to StudioPieters® before starting the fun of building and learning. StudioPieters® is a non-profit organisation devoted to making creative use of electronics accessible to everyone.