Introduction: MQTT Home Automated Blinds

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.

    IMPORTANT

    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.

    IMPORTANT

    //-------------------MOTOR---------------------------//

    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++) {

    digitalWrite(stepPin,LOW);

    delayMicroseconds(200);

    digitalWrite(stepPin,HIGH);

    delayMicroseconds(200);

    }

    delay(0);

    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: 192.168.0.122:8123) 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.

    Congratulations

    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.

    Comments

    author
    miguipda1 made it!(author)2017-06-15

    Hi,

    I just found this should target what I talked about considering the IKEA store use without modifying the store axe :

    http://www.somasmarthome.com

    It seems use a smaller motor than yours. Any idea about which motor is used in this soma smart home ?

    author
    miguipda1 made it!(author)2017-04-26

    Hi,

    great job ;-)

    Three questions :

    1) why did not you use the Home Assistant embedded MQTT in place of installing Mosquitto ?

    2) could you upgrade it by adding a light sensor to automatically set the blind down when the light are switched on in the room. Because if you switch the light on it means you do not want the poutside people could see what happened inside.

    3) could you also upgrade it by using a variable which is set ON or OFF following we are or are not at home. It means that some other events should modify this variable (presence detection, google calendar, ...) and then if we are not at home the blind should automatically be down. The idea is to simulate presence to avoid thief. By example when we are in holidays.

    Sincerely thanks.

    author
    einarms made it!(author)2017-04-27

    Question: Embedded MQTT broker

    I didn’t now Home Asisstant had an embedded broker, is this the one you`re referring to? https://home-assistant.io/docs/mqtt/broker/#embedded-broker ?, I`ll definitely check it out though.

    When debugging I found Mosquitto to be a good choice, at least for me, and
    if something is not working the way it should on the Home Assistant side (cause of my poor .yaml skills when writing in the configuration.yaml file), I can
    always SSH into my Pi and publish some messages. I Do think you can do this in Home Assistant also at least for publishing messages, don’t know about
    subscribing though.

    Question2: Light sensor

    Yes of course, I actually had a light sensors or a photoresistor pointing out the
    window. The idea was to open the blinds when the sun was rising, but as I`m currently living in area with a lot of car traffic the sensor keep reading the headlights of cars as a rising sun. As you say you would like the blinds to go down when the lights are switched on, you could use the same setup and just turn the sensor to point into the room instead.

    The sensor I used was analog, so just calibrate your analog readings for “lights on” and “lights off” and use that as your limits for staring the blinds motion function. But keep in mind that the Wemos only have one analog input as far as I know. If you need more you can just add an Arduino to your system for handling that.

    Question: Variable switch

    I don’t really understand your question here?
    The presence detention would fall in the same setup category as above?

    The simulation of presence is a possibility that am currently using for my wake up alarm, I have a function in Home Assistant where I can set the time I want to wake up, and a automation rule publishes a message to the Wemos controlling my blinds and the light in my bedroom and acts accordingly.

    Check this project out:

    https://community.home-assistant.io/t/creating-an-alarm-clock-updated/15195

    If you don’t need the Home Asisstant GUI for setting the time, I`ts quite easy
    writing a simple automation rule directly into the configuration.yaml file. Like so:

    https://home-assistant.io/docs/automation/trigger/

    Note: use the TIME TRIGGER combined with a MQTT action.

    Hope this answers your questions, thanks for feedback, always appreciated.

    Cheers

    author
    miguipda1 made it!(author)2017-04-27

    When you said :

    1) Yes I talked about this embedded-broker

    2) "you could use the same setup and just turn the sensor to point in the room instead" except the parameters will be inversed because the blinds will stay closed when the light is on (in your case the blinds are open when the light (sun) is on ;-).

    I approximately have the same problem that yours. I do not have car traffic lights but I just have a public light in front of my house. Then I can not check if outside it is the night. I just can check if inside the light is open.

    3) Variable switch : I was talking about a simple status variable that will change following some events (calendar (holidays, not at home, ...), ...). This status variable will then be send (MQTT) to the Automated Blind inform it if it will be open or close.

    Then when everyone of the family is outside (by example during holidays) the status variable has a value telling it that it will simulate presence at home (and then open and close the blinds randomly at sun rise and near the night). We may consider the status variable should be 0 to close, 1 to open or 3 to simulate (in this specific case the blinds must be randomly open (by using TIME TRIGGER) between 6 hour and 8 hour and close between 17 hour and 18 hour during winter but between 20 hour and 21 hour during summer).

    Then this status variable could also be used to know if it must randomly switch on/off lights (but this is another thing).

    I was talking about a reading a status variable because I think it will be the easiest way that your code can know what it must do (simply open or close the blinds). This status variable will be modified by other codes (resulting from events : calendar when in holidays, someone goes back at home by a sensor, ...).

    As you can see you code will not so much be modified by reading a status variable.

    Sincerely thanks for your answers.

    Cheers

    author
    tutdude98 made it!(author)2017-04-27

    This is nice, you could also add LED grow lights that would work when its cloudy

    author
    einarms made it!(author)2017-04-27

    Yeah, I`ll have to do some research on that. I plan on making a fully automated home greenhouse, so artificial sunlight would be a nice feature.

    author
    tutdude98 made it!(author)2017-04-27

    thats nice, i have arduino controlled irrigation system and its solar powered, i also plan on adding few leds and putting whole thing into something like grow box

    author
    Swansong made it!(author)2017-04-26

    That's a neat setup :)

    author
    einarms made it!(author)2017-04-26

    Thanks :)

    About This Instructable

    3,386views

    100favorites

    License:

    Bio: DIY and IOT enthusiast
    More by einarms:MQTT Home Automated Blinds
    Add instructable to: