Blinds Control With ESP8266, Google Home and Openhab Integration and Webcontrol
Intro: Blinds Control With ESP8266, Google Home and Openhab Integration and Webcontrol
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.
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"
82 Comments
zet6 3 years ago
Wim3d 3 years ago
I hope this is clear for you, otherwise do not hesitate to ask.
zet6 3 years ago
Wim3d 3 years ago
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.
zet6 3 years ago
redvader 3 years ago
jensvermincksel 3 years ago
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).
ansarakmal12 3 years ago
Wim3d 3 years ago
stiff6291 3 years ago
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
Wim3d 3 years ago
Squ1sher 3 years ago
Wim3d 3 years ago
Squ1sher 3 years ago
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
Wim3d 3 years ago
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.
bonelifer 3 years ago
Wim3d 3 years ago
qaasimravat81 4 years ago
Wim3d 4 years ago
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.
qaasimravat81 3 years ago
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???