Blinds Control With ESP8266, Google Home and Openhab Integration and Webcontrol

70,483

566

82

Introduction: Blinds Control With ESP8266, Google Home and Openhab Integration and Webcontrol

About: I like to combine electronics like Arduino's, ESP8266 etc with 3D designing and 3D printing.

In this Instructable I show you how I added automation to my blinds. I wanted to be able to add and remove the automation it, so all installation is clip on.

The main parts are:

  • Stepper motor
  • Stepper driver controlled bij ESP-01
  • Gear and mounting bracket

I controll the blinds via Google Home, my Openhab server and a website.

You can still manually control the blinds, because when the blinds are not opening or closing automatically, the stepper motor is disabled.

Supplies

I bought most components form Aliexpress

ESP8266: ESP-01

Stepper motor

A4988 stepper driver

Chain for controlling blinds

Buck converter

Power supply

I designed and printed the gear and mounting bracket myself

Step 1: Stepper Motor, Gears and Handles

I removed the gear from the curtain roller to re-engineer the gear in Fusion360. I experimented with different gears. Smaller gears gave a larger torque, but less grip on the ball-chain. A gear with 12 teeth worked best for me and I designed a mounting bracket to fit the stepper motor and the gear with the ball-chain.

I designed the handles to clip on the standard Luxaflex handles.

The STL files of all 3D parts are published on my Thingiverse page.

Step 2: Stepper Driver Hardware

The hardware consists of:

  • Step down (buck) converter (12V to 3.3V) to power the ESP-01 and the A4988 stepper driver
  • ESP-01 which connects to the WiFi network and controls the stepper driver (enable/disable, motor direction and steps)
  • Stepper driver A4988
  • Stepper motor (17HS4401)
  • Some electronic components

I soldered the female connectors to a perf board and connected the components mentioned above.

Step 3: Software

The code is published on my Github.

Edit april 2020: a version with no MQTT and only webcontrol is added.

Edit april 2020: + 10% and - 10% is added to webinterface.

The program with MQTT control:

  • Connects to the WiFi network and MQTT server
  • Checks whether to state of the blinds is equal to the setting, if not it changes the state to match the setting. Then enable the stepper motor, execute the right number of steps. Disable the stepper motor.
  • A setting can be received via MQTT or via the Webserver.
  • The webserver may enter the HTTPUpdateServer mode to OTA update the firmware.

Disabling the stepper motor by setting the 'EN' pin of the A4988 driver is important to:

  • Reduce the amount of current used by the device if the setting remains the same (vast majority of the time)
  • Enable manual control of the blinds.

The HTTPUpdateServer is enabled at IP address/update. Before entering the update mode via the webserver, it changes the state to the CENTER state, since the program starts up in the CENTER state.

This is how I derived the number of steps:

The total length of cord between closed and opened is approximately 40 cm.
One revolution of the gear is approx. 7.5 cm.The total length of the cord is 40 / 7.5 = approx. 5.3 revolutions.
I don't want to stretch the cord and the device starts from the middle position, so I round it to 5 revolutions (2.5 in one and 2.5 in the other direction).
One revolution of the stepper motor is 200 steps, but I have set my stepper motor driver to quarter steps, so one revolution is 800 quarter steps. 5 revolutions is 4000 quarter steps (MAX_STEPS).
The close setting (CLOSE_STEPS) is 90% closed = 3600 steps; the open setting (OPEN_STEPS) is 10% = 400 steps.
The middle position (CENTER_STEPS) is 50% is 2000 steps and is the initial number of steps when the device starts.

Step 4: Assembly

My controller is shoven to the windowsill via the mounting bracket of the stepper motor

I designed a back end for the stepper motor containing the stepper driver and ESP-01.

Step 5: Home Automation

Original: I have a Raspberry Pi Zero running Raspbian Stretch lite, NodeRed and Openhab 2.4.0

Edit march 2021: I have a Raspberry Pi 3B running Raspbian Buster lite, NodeRed and Openhab 3.0.0

My Openhab items, rules and sitemap are on my Github.
Edit april 2020: + 10% and - 10% setpoint is added to Sitemap in Openhab).
Edit march 2021: I added the Openhab 3 description in the files.

See this Instructable how I set up MQTT on Openhab 3

In this case Node Red is only used for debugging purposes.

Google Assistant

The Google Home Openhab integration is described here.

If my TV is turned on via Openhab, blinds close according to the rule.

"Hey Google, set window blinds to 50"

Be the First to Share

    Recommendations

    • Plastic Challenge

      Plastic Challenge
    • Made with Math Contest

      Made with Math Contest
    • Tinkercad Student Design Contest

      Tinkercad Student Design Contest

    82 Comments

    0
    zet6
    zet6

    Question 7 months ago

    Hey, great project! Hardware side was easy but software is a major pain though. I do have everything running smoothly with web interface. But for the love of god I can't figure out how to set OpenHAB up! I got the ESP to register with mqtt (raspi4), I got an mqtt bridge thing online in OpenHAB. How do I make them talk to each other? I tried simply copying your .item file into corresponding dir - didn't work. Tried setting up the item thru OpenHAB interface - it's a maze ! Do you think you can help ?

    0
    Wim3d
    Wim3d

    Answer 7 months ago

    Dear zet6, I edited some parts to suit a Openhab 3 installation and made a separate Instructable in which I explained how I set up MQTT on Openhab 3. https://www.instructables.com/MQTT-on-Openhab-3-Tu...
    I hope this is clear for you, otherwise do not hesitate to ask.

    0
    zet6
    zet6

    Reply 7 months ago

    Hi Wim, thank you so much. I repeated all the steps in your tutorial but unfortunately it doesn't seem to work. I now have 2 "things" in OHAB, broker and generic. I have configured "blinds/side/percentage" in the Generic thing. Then I have tried both textual and UI ways of adding an "Item". I end up with an item that has a percentage slider - but that does nothing. I can't see any activity in mosquitto while adjusting slider or when operating blinds through web interface. I must admit - this is one of the most unintuitive pieces of software I ever touched.

    0
    Wim3d
    Wim3d

    Reply 7 months ago

    That's a pity.
    Do you see that the item is linked to the channel of the thing (see step 6 of my tutorial)?
    The error can be in both the Openhab setup or the blinds controller (be sure they are connected to the same MQTT broker).
    I suggest you try to control the blinds control via MQTT from another MQTT client. I use Node Red for that purpose (I find Node Red very intuitive), since you can easily send values and also monitor the messages which are send by the controller on the debug topic and also the messages which are send or should be send from Openhab. But of course there are other MQTT clients, like MQTT dash for your phone.
    If you change the blinds via the webinterface, you can monitor the messages on the debug topic. In a new version of the code I will see that it publishes the settings from the webinterface to the MQTT percentage topic.

    0
    zet6
    zet6

    Reply 7 months ago

    So I tried HomeAssistant instead and after some trial/error was able to control the blinds through mqtt-number integration. I would love to use openhab as it allows free Google assistant integration though.

    0
    redvader
    redvader

    Question 7 months ago on Step 2

    Would you be willing to sell the gearing required?

    0
    jensvermincksel
    jensvermincksel

    8 months ago

    Very nice project! I made it as well, had great help from Wim!
    I made sure the program/communications with MQTT worked first, I used NodeRed with Google Assistant and Mosquitto MQTT. Now I still need to do the mechanical part which I will be doing directly to the shaft of my blinds (I have roller blinds).

    0
    ansarakmal12
    ansarakmal12

    8 months ago

    how to control curtain with no mqtt code

    0
    stiff6291
    stiff6291

    1 year ago

    Just what IM looking for.
    The only problem is how do you set it up without mqtt. is there any way you can do a tutorial for the not so smart people like me

    thank you

    0
    Wim3d
    Wim3d

    Reply 1 year ago

    In this April I added a version without MQTT, only with webinterface. How do you want to control it?

    0
    Squ1sher
    Squ1sher

    1 year ago

    Thx for the nice project. I'm trying to modify the code a bit for my needs. Can you point me to all that reference documentation that you used (ESP8266Wifi, PubSubClient) ?

    0
    Wim3d
    Wim3d

    Reply 1 year ago

    I am willing to help, what kind of modification are you looking for? Reference material of the libraries can be found at the Github page of the library. I had some inspiration from Youtube (Andreas Spiess, MK Smarthouse, Kevin Darrah).

    0
    Squ1sher
    Squ1sher

    Reply 1 year ago

    Thx for anster. I'll have a look.
    I want to open/close my window instead of blinds using a stepper motor and a threaded rod. Controlled via openhab+mqtt also. First i want to disable the esp access point for security reasons. I just found that method: WiFi.mode(WIFI_STA)
    . The next thing is to have accel/deaccel (because the window is heavy) and translate the motor steps into window angle which is not linear all the way. Concrete questions: is the delay(10) in setup_wifi necessary ? How does the wifi module get its loop() called, because i suspect it also needs regualar cpu time for packet handling.
    Its because i must have full attention for my loop/progress function without having too much pauses in it between cause i can't miss out motor steps when driving the heavy window with its momentum.
    Thx!, Squ1sh

    0
    Wim3d
    Wim3d

    Reply 1 year ago

    OK. You need WiFi.mode(WIFI_STA) only once, but it is no problem to execute it every time, what I do. I don't thick delay(10) is necessary. I think I have added it when I encountered some problems. I copied the setup_wifi program from another program I made.
    In my program I check whether the WiFi is still connected. If nothing happens, the WiFi connection remains intact.
    client.loop(); is necessary for the MQTT connection to stay active,
    httpServer.handleClient(); is needed to handle the HTTP requests and the OTA update.

    0
    bonelifer
    bonelifer

    1 year ago

    Being new to home automation and just in the planning phase, I do have a newb question. I assume I can use this with a HASSIO(home assistant) MQTT based setup, intead of openhab.

    0
    Wim3d
    Wim3d

    Reply 1 year ago

    Sure, but I do not have HASSIO, so I cannot help you with the setup and the yaml files. Have a look at Youtube at the channel of 'Thehookup'.

    0
    qaasimravat81
    qaasimravat81

    Question 1 year ago

    Hi. I've been trying this project out for a while now but i cant seem to get the code running properly. When i uplode the code all i get in the serial monitor is a whole bunch of symbols this web pade dont load. Any help?

    0
    Wim3d
    Wim3d

    Answer 1 year ago

    Hi. In this project I use an ESP-01 and use the pins which normally are used for the serial connection (RX (GPIO3) and TX (GPIO1) to control the stepper motor, see line 49 and 50 of the file in my Github. Since I use these 'serial pins' for other means, there is no regular serial communication possible for debugging. The symbols you see are from the bootup of the ESP, have a look at these symbol at a baudrate of 38400.
    Maybe there is no good WiFi or MQTT connection. Did you fill in the right WiFi and MQTT credentials (see lines 14, 15 and 34 of the github file)?
    Otherwise you can try the code on another ESP device, change the stepper direction-pin and step-pin to other ESP pins and initiate Serial communication at startup and generate debug infomation via Serial.
    Please let me know your progression.

    0
    qaasimravat81
    qaasimravat81

    Reply 1 year ago

    Hi. So i finally got the chance to get back to this project. But this time i changed the pins to get serial monitor feedback and i have been getting this error...

    ets Jan 8 2013,rst cause:4, boot mode:(3,1)
    wdt reset
    load 0x4010f000, len 3456, room 16
    tail 0
    chksum 0x84
    csum 0x84
    va5432625
    ~ld


    I have no idea what any of that mean. Do you maybe have a solution???