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

59,713

526

73

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

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

My Openhab items, rules and sitemap are on my Github (Edit april 2020: + 10% and - 10% setpoint is added to Sitemap in Openhab).

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"

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

Be the First to Share

    Recommendations

    • The 1000th Contest

      The 1000th Contest
    • Battery Powered Contest

      Battery Powered Contest
    • Hand Tools Only Challenge

      Hand Tools Only Challenge

    73 Discussions

    0
    stiff6291
    stiff6291

    3 months 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 3 months ago

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

    0
    Squ1sher
    Squ1sher

    4 months 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 4 months 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 4 months 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 4 months 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

    4 months 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 4 months 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 7 months 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 7 months 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 4 months 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???

    0
    Wim3d
    Wim3d

    Reply 4 months ago

    Which ESP module do you use? With an ESP-01 you need the GPIO1 and GPIO3 pins to control the stepper motor (see my answer above), then you can not use the serial monitor. Which pins do you use to control the stepper motor?
    "wdt reset" means that the program got stuck and the watch dog resets the module. See this video for an explanation about the watch dog timer: https://www.youtube.com/watch?v=D_7ciW_TCac

    0
    qaasimravat81
    qaasimravat81

    Reply 4 months ago

    ESP8266 V3. I used GPIO 1 and 3 first but i switched it to get serial monitor feedback and i got that as feedback.
    What i dont understand is why the without MQTT works perfect but the code with MQTT dont. I tested my MQTT server with a relay and the same ESP module and it worked fine but the motor is breaking me.
    Thanks for all the help so far.

    0
    qaasimravat81
    qaasimravat81

    Reply 7 months ago

    Thanks for the wuick reply.
    Okay i understand with regards to the serial monitor. The wifi setup is right because i logged into the router to see if it connected and it did but i counld not get the web page right. But ill keep trying and let ypu know if i came right

    0
    Wim3d
    Wim3d

    Reply 7 months ago

    Okay, I guess you got the IP address from your router. Is your MQTT server setup right? My code keeps trying to connect to the MQTT server. If this connection is not succesful (see line 95), the webpage will not be accessible, since the httpServer.handleClient(); command in line 92 is not executed when there is no MQTT connection. If you have no MQTT server, comment out the MQTT parts of the code.

    0
    qaasimravat81
    qaasimravat81

    Reply 7 months ago

    Im using openhab aswell. When i use MQTT.fx to test the MQTT server it shows that its up and running but for some reason i can't get this thing to work properly but ill keep you updated on if im getting anywhere or if i'll need more help thanks for the quick replys.

    0
    Wim3d
    Wim3d

    Reply 7 months ago

    The MQTT connection and control of the blinds via MQTT and the webpage should work separately from Openhab. Do you see the debug messages of the device, for example the connection message from line 175 of the code?

    0
    qaasimravat81
    qaasimravat81

    Reply 7 months ago

    Im a little confused now. Im using openhab as my mqtt server. Or do i have to use a different mqtt server?? Im lost now :(

    0
    qaasimravat81
    qaasimravat81

    Reply 7 months ago

    Hi.
    I think I found the problem. I downloaded the MQTT.fx app on my pc and tried to connect to the server but got the error "session present: false". I don't know what it means but im looking online to see if i can get the problem solved. If you have any advise please do let me know. Thanks for all the help so far.