Introduction: MQTT Home Automated Blinds

About: DIY and IOT enthusiast

The MQTT Home Automated Blinds is exactly what it sounds like, a MQTT controlled window blinds system using a Nema 17 stepper motor controlled by a Easydriver stepper board for motion.

All the makeable parts have been printed using the Anet A8 (Prusa i3 clone) 3D printer, and models modelled in Autodesk inventor. I`ve not included this particular process, but all the .stl files are attached.

This instructable is divided into the four following steps:

    1. Hardware
    2. Software
    3. Assembly
    4. Code
    5. Setting Up Home Assistant Configuration.yaml
    6. Photos

    A lot of the information i`ve used is gathered through watching tutorials and I will do my best to paste links to the once used so the right people is credited for their work.

    Step 1: Hardware

    Why invent the wheel allover again? so instead of explaining how all these parts work I`ve put links to sites that does, and doing so much better than what I`ve could have done.

    On the hardware side we need the following parts:

    There is a vast range of prices and stores that sell these items, I mostly used ebay for purchasing the parts, but whatever suits your preferences work, just keep in mind that cheap knockoffs may have different functionality and dependencies and could potentially turn the project more troublesome than it have to be.


    Remove the hard plastic lined in the bottom of the blinds, failing to do so will make the blinds close when the stepper motor gets de-energized. Alternativley you could remove the relay module, leaving the stepper motor energized all the time, but this is NOT recommended!!!

    RC gears

    I used the 18T and 19T gears, which is what i design the roller for, but I guess they all work with a little sanding of the 3D-printed gear teeth, if you do have access to a 3D printer, you can just design one yourself or scale mine.

    3D printed parts

    Below you can find the .stl files for the 3D-printed parts, No support and 10% infill should cut it. After a while the blinds can start to squeak, in that case just drop some oil in the fittings (Plain cooking oil would do). The parts are a little overkill when it comes to dimensions, but hey, It’s better to be safe than sorry.

    Don`t pay attention to the poor quality of the box, its due to poor calibration (laziness), when starting the print.

    My future plan is to implement some bearings between the mount and the rollers, but for now these will do. (These will replace all the IKEA stock parts)

    Step 2: Software

    On the software side:

    No new wheels invented in this section either, lets head over to my "assistant" YouTube and watch some tutorials, just click the links and the "YouTube" will teach you how to.

    The Arduino IDE

    Start by download and installing the latest version of the Arduino IDE.

    To be able to program the Wemos D1 mini using the Arduino IDE, you need to configure it (the board is not included in the default installation) by adding the board as an additional board. YouTube I belive this is your queue: Setting up the Wemos D1 in Arduino IDE

    Now download and install the CH340G USB to UART driver and voilà, you are now able to program the Wemos D1 using the Arduno IDE.

    Home Assistant

    This is where you break out your favourite little linux computer named after a tasty fruit and a mathematical constant (or Python?): The raspberry Pi

    To install Home Assistant I used the all in one installer, which includes both Mosquito and Samba, which we are using later. Ben from BRUH Automation explains how to in this tutorial. *In this video Ben is using WinSCP to access the configuration.yaml file, where I`m using samba. Choose which ever you feel the most comfortable, it doesn't matter.

    The Moqsuitto MQTT broker

    The Mosquitto MQTT broker is what controls the communication between the Wemos D1 and your Raspberry Pi and Home Assistant.

    Essentially what we do is creating topics where were we can publish and subscribe to messages being sent over the WiFi. (btw, you do need a WiFi router).

    In my case I use the topic: “blindsbr/move” to publish the messages (also called “Payloads”) : “UP” and “DOWN” from the Rasperry Pi and the Home Assistant GUI. The Wemos D1 will conversely subscribe to the same topic and perform the action related to the message and subsequently publish a "I did it message" to the topic: "blind/state" with the payload: "OPEN" or "CLOSED". Again Ben from BRUH Automation can again help us setting this up (Mosquitto MQTT broker).

    Step 3: Assembly

    I`ts time to bring out your soldering iron and get that solder melting or just use dupont jumper wires, either way works.

    Note! Indexing of pins in the Arduino IDE is different from the indexing on the Wemos, use the picture above to map your pins. The green numbers are the corresponding pins in the Arduino IDE.

    Example: #define stepPin 16 equals D0 on the Wemos board, but that belongs to the next step: Code.

    Step 4: Code

    Now you should have the Arduino IDE up and running with a functional board driver and the Wemos board loaded in the board manager.

    I guess three is the magic number cause again, no wheels invented, maybe some training wheels, but that`s it.

    When googling around looking for a way to code MQTT into the Wemos I came across this blog called Automated Home Party where he did just that. In that case for controlling a fireplace and a garage door. But hey, Garage doors and blinds, basically the same thing isn’t it?, give or take a couple of kilos. And the best part, OTA Updates!

    OK, head over to Automated Home Party and pick up at step 2 of his tutorial using the code I`ve attached here rewritten by you with your changes to the custom part:

    //Define parameters for the http firmware update

    • const char* host = "WemosESP"; (Here, choose a name for your device)
    • const char* update_path = "/WebFirmwareUpgrade";
    • const char* update_username = "username"; (Type in a username)
    • const char* update_password = "password"; (Type in a password

    Remember to keep the: " " in front and after your input. (interpreted as a string)

    //Define MQTT Parameters

    • #define mqtt_server "Internal Ip address of your MQTT server" (ifconfig in your RasPi terminal)
    • #define blind_state_topic "blindbr/state" (Topic for publishing state payloads)
    • #define blind_topic "blindbr/move" (Topic for subscribing to movement payloads)
    • const char* mqtt_user = "user"; (Username set in pwfile setting up mosquitto)
    • const char* mqtt_pass = "password"; (Password set in pwfile setting up mosquitto)

    The main change I made to the code was adding the stepper motor function, this lets you move the stepper motor in one or the other direction depending on the payload for the subscribed topic.

    I recommend you to go through both my code and the one from Home Automation Party and try to understand what each function does, it will make it much easier to customize it for your own needs.



    int steps = 3000 ; // Number of steps in each for loop

    if you increase this number you will get a WDT error and the Wemos will reset before completing all the loops, hence bilnds will not move either. If you do need to include more steps just copy paste the below code into the end of the function as many times needed.

    The delay(0) in between the for loops is to reseting the WDT so the looping can continue , this is the best workaround I could figure out, if you find a better one please let me know, it would be much appreciated.

    3000 additional steps:

    for(int x = 0; x < steps; x++) {







    Also remember to load and install all the libraries in the top part of the code using the manage library function on the sketch drop down (they should turn orange when all is OK)

    Step 5: Setting Up Home Assistant Configuration.yaml

    If you followed the previous tutorials for installing Home Assistant you should now have a working MQTT broker and know how to locate and open your configuration.yaml file.

    Paste the below into configuration file and a cover will pop up in you Home Asisstant GUI (Ip address of your raspberry Pi and port 8123 example: the next time you reset it.

    If you made your own changes to the code during the previous step, implement the same changes here.

    - platform: mqtt

    name: Bedroom Blinds

    state_topic: "blindbr/state"

    command_topic: "blindbr/move"

    payload_open: "UP"

    payload_close: "DOWN"

    state_open: "OPEN"

    state_closed: "CLOSED"

    optimistic: false

    BadabomBadabim, you should now have your own MQTT controlled blinds.


    Step 6: Photos

    Step 7: Ongoing Projects

    This is not a step, but rather some information on other projects related to this using the MQTT protocol and the Wemos D1 mini, if interested, leave a comment and my files are yours.

    MQTT controlled irrigation system

    In my quest for finding excuses to use the Wemos board, MQTT and Home Assistant, I planted some chillies and avocados to build a MQTT controlled automated irrigation system.

    It works the following way:

    As you can see from the pictures the plants are standing in my living room window. So each morning when the sun rises Home Assistant publishes three MQTT payloads, one opening the blinds, and the other two starting a pump and opens two solenoid valve resulting in watering of both the avocados and chillies.

    After this , the Wemos then publishes a payload back to Home Assistant which then sends a pushbullet to my phone, letting me know that my plants just got watered and are currently bathing in sunlight.