DIY Windows Shades Automation in Home Assistant – part 1

Hey, what’s up! It’s Václav here This video is about how I modified these shades, so I can control them automatically from the Home Assistant This is a second video in a row, if you missed the first one, you can watch it in here In there I was doing a walk through this house, and I was showing all kinds of things I do. How I automate them The multimedia, lights, heating and the window shades as well About the shades When we got them, they were not smart at all They had those two buttons, and using those buttons I could control the movement of the blades If I wanted to change the tilt, I would have to shortly push the button “UP” I would have to keep pushing it until I get the right position And if I wanted to raise them up, I would have to hold the button I would have to keep it down for about a minute or so keep it down and I’m waiting And I’d be waiting for about a minute Because if I let it go, the shades will stop And if I wanted to send them back down, I would have to push the other button And again, keep it down…and keep it pressed…and they will first tilt and then will go down And I have to keep holding it for about a minute And it’s quite inconvenient actually There you go So, what I did is I have Automated those buttons I have connected them to Home Assistant through Arduino and through that I can independently control the position of the shades – send them up, send them down, or to any position I like And I can also control the tilt I can open it Or I can close it Or I can set them to any position I want So for example 50 degrees right now And I obviously don’t do it from the phone like I’m doing right now. I do that automatically So I have automation, where in the summer, when it’s sunny outside Every 15 minutes, I make an adjustment of the tilt angle And I tilt them based on the angle of the Sun So I have calculated what is the right tilt for those blades so they would create shade inside They won’t let the Sun rays in But I would let enough light in so it’s not dark inside I do this during the morning, when there is a Sun on this side of the house And in the afternoon, I tilt them up So it’s nice and light in here And in the evening, I close them down to create privacy This is what I do when it’s sunny When it’s cloudy, I just keep them tilted up, so there is light inside – so I don’t have to turn lights on And in the winter, I control them not only based on the weather and the Sun elevation, but I also based on the temperature inside So when it’s cold inside and nice and sunny outside, I do not only tilt them up, but I open them up, to let the Sun in So I will save on the energy bill I will talk about this automation – how I did that I will show it to you and share it with you, in the next video So if you want to make sure you don’t miss that, hit the Subscribe down there! But in this video, I will explain to you how I actually modified those shades so I can control them and connect them through the Home Assistant Before I do that, these are not the only shades I have I have another kind Let’s come and look at them These are those regular covers that most of the houses here have Some of them they have manual control by ropes, I have them in electric But again those stupid buttons that I have to keep pressed and wait, until the cover comes up Because if I let it go they will just stop So I have to keep them pushed It’s a bit shorter than the other ones, it takes about 30-40 seconds, but still You know in the morning and in the rush So I automated them as well By Sun but also, because it’s in bedroom,

I controll them by the alarm clock or Google Calendar based on the time So I open them in the morning and I close them in the evening It’s quite neat But I also wanted to maintain the function of the buttons So if I wanted to close them, I wouldn’t have to search for my phone So the buttons actually works similarly as before with one exception I wanted to improve that. So if I wanted to fully close them, I don’t have to keep it down I just shortly push it And the relay will close. It will keep it closed until the cover comes down And then it will open it. In fact, I recognise two positions One closed, with those vents open Which you can use in the summer to let some air in And if I push it again, they will fully close, to keep it dark inside Before did that, I wanted to ask the manufacturer for a quote So I went to the producer and I asked, what can I do to control them through MQTT or something? So they gave me proposal first for the upgrade of the electrical motor Because it had to be different one with more wires, with end stops and so on And the quote was around $1,500 for one of the motors. And I have two in each bedroom So that is 6 plus the the ones in the corridor, so it’s 8! Times 1,500. And this will be just the motors, then I would have to do something about the controls And then probably buy some API and and do the interconnection So do you think I went to my wife with this proposal? No, I didn’t! So I was thinking maybe using Arduino, I can do the automation myself! So let’s come and see how I did that! So there are two windows This is how it looks from the side Each window has a cover in front And at the top, its rolled like that In the middle there is electrical motor And when the motor rotatesN left and right, the cover is coming up and down. Each of the motors has three wires comming to it One is coming from the phase (L) It’s coming all the way down to the wall switch, and the switch has two buttons – one for coming up one for going down There’s those three wires through the wall And there is a control box in here and then there is the neutral (N) And the buttons are on springs, and they’re blocking each other. So I can’t push both at the same time When I push the left one the electric motor is going to rotate counter-clockwise to the left and the shutter is going to go up. And if I push the right one the shutter is going to go down. And the second one is exactly the same So there are two buttons, also connected to the phase And they go up to the wall box So if I wanted to automate that, what I need to do is, I need to replace those physical buttons by relays I will disconnect this cable here And add two relays in here One coming up here second coming there they will be connected To the phase Now those two buttons they will be disconnected from the mains and they will be connected to Arduino So that we connect it to pins this one will probably something like GND And each of them is gonna go to one pin and so I will be able to detect when I press the button I’ll be able to open or close each relay If I did just that, it will allow me to control the buttons from the Home Assistant So I could have buttons on the Home Assistant screen and I can push one It’ll come up, and if I push the other, it’ll come down That’s a good start, but it’s not exactly what I wanted to do What I want to do is I would like to be able to control the shutter, so it will open and close from 0 to 100%

Or anything in between I’ll be able to say: “I like the cover to go to 50%” and it will go and it’ll stop exactly here from wherever it is and I’d like to also be able to control the tilt of those blades up and down From the completely horizontal position (open) the completely vertical position that is closed Now the way how I can do that is, if I know the current position And if I know the time for the shutter to come down Or the time to come up indeed if (it’s not the same) and if I also know the time that it takes to tilt the blade from one position to the other then what I can do is I can program the Arduino so when I send it the target position and tilt, it will close the relays for the exactly time needed for the shutter to arrive to the desired position, and then it will open the relay again Now for the tilt I know that when the shutters are coming down. There are always in closed position, And when it’s coming up, first thing it’s gonna do is, it’s going to open the shutter, it is going to tilt it up and then it’s going to move up So I know that when I’m going down, they’ll be closed when I’m coming up and then I stop they’ll be open So based on that I can also control the tilt if I know the time it it takes to tilt up and down So if I’m coming up, I know the blades are open and if I wanted to set them to 45 degrees I will then shortly close the relay for going down for half the time it takes to close the blades And it will set them to 45 degrees Now that we know how to do it we can start building it I could get some Wemos mini But the easiest and cheapest way to do that. In fact is to get a Sonoff 4 ch That is exactly what we need We have 4 relays and then we have those 4 buttons And those buttons what they do is they connect GPIO0, GPIO9, GPIO10 and GPIO14 with the GND To close the relay. It’s pretty easy to connect the wires for the shutters to those contacts here And the L and the N, but there are no connectors for the buttons, unfortunately but we can easily change that so what I’m going do is I’m going to rotate it. There is 1-2-3-4 buttons in here. So I’m gonna get a piece of wire, I’m gonna get four of those so one and four Then I’m going to strip them So I need to do is I just need to solder piece of wire in here And then what I’m gonna do is I’m going to get a another one for the GND So now we have those 4 buttons and the GND in here To make it easier I can take this connector in here and connect them in here. So I’ll take a screwdriver and just connect each wire to one of those So I have them connected like this I can take piece of double-sided tape and just glue it in here and then I have everything ready. So all we need to do now is to program this board with a logic that we have designed on the tablet As for the firmware I was looking at a couple of options for fw that were already are ready to be made and some of them looked very promising At the time I was doing it about a year and a half ago Tasmota would be a fw of my choice for the sonoff anyhow

They support MQTT, I was using them for all the lights switches and if you look closely they also do have some support for blinds and shutters Even though you have to recompile it, but it was a big deal. I like to do that anyhow But if you look closer, they only support Opening the covers closing them and setting them to a specific position But they have no support for tilting This is disappointing Then I looked at the ESP home, which is actually my current firmware of a choice I use that for all the light switches and I like its flexibility and they do have support for covers as well And they have “control cover” action, which does support tilting as well. So this is great But if you look at the specific Time-Based cover again, they only support opening and closing There’s nothing about tilting And I wanted to have a bit more flexibility with the firmware anyhow For the button actions, you know – short press and long press and so on So at the end I have decided to write own firmware I brought it in the Arduino and I made available for you on the GitHub so if we go to Bruxy70, which is my GitHub page, there is a repository for Venetian Blinds Control, and there you can find the firmware that I use both full covers as for the shades. They are highly configurable So if you download those files to your computer and you open them from the Arduino ide then there is the config.h file, that you can open and do basic configuration – your MQTT parameters timing and so on But you don’t have to do it. Because I added a WEB interface to it, so you can change all of your configuration So the minimum that you need to configure in here is the Wi-Fi SSID and password. So that you can connect to it when it boots So you can configure it here, do the programming (which I’m gonna show you in a minute) and then you can go to this Web page I’m gonna show you mine Let’s choose the gallery and Then you could see it has a web page where you have those 4 buttons that you control it from here some basic statistics You can Upgrade the firmware from here You can also calibrate it so it’ll send it up and down and reset the 0 and 100 position. You can restart it but you can also configure it And here you can change whether it has it has vents, whether it had tilts – it will change the configuration options. You can set it for 1 or 2 shutters. And you can configure the Wi-Fi in here MQTT server username and password, the MQTT topics As well as the timing. And this is very important! This is one thing that you would have to definitely do for your shutter to work You will have to measure the time it takes your shutter to go down and you enter it in here in milliseconds, and then duration up and then in this case (because I have tilting) you would have to configure the duration to tilt. If I had vents, then there will be the duration to vent. Which is not configured in here because this one is not it’s tilting And if you have two shutters, like in this case, you could have each shutter configured differently, right? Sometimes you have one longer, and one shorter, and you can also change the GPIO in here. And you can Save it and Restart, and it will reboot And it will be reconfigured. So you can do it in here, or you can do the configuration in here in the Arduino config file. I’m not gonna go through it, because it’s essentially the same as you saw in the webpage And it’s pretty self-explanatory, and it’s commented So what you do is, you do your configuration here, and then you need to upload it to our board For that you need to connect the board So you need to go to Tools, you need to make sure that the board is set to ESP8285 generic You can check all of those other parameters In the Port, I don’t have it connected yet so I don’t see the port. But as you can see I can also upload from this IDE over the air,

So this is also available, if I want to update it But what I’m gonna do is I’m going to connect it through the USB and send the firmware over the USB cable So here I have the board that we have soldered previously. I’ve already connected the USB pins to it So those 4 wires I’m not gonna go into full detail explaining how you upload firmware to the Arduino board But essentially I’m connecting 3Vto 3V, then RX to TX and TX to RX, And then I have the GND, which I’m connecting to GND Now, I have this little wire connected to ground in here which goes there. So I’m connected to this connector because there was no hole anymore. So I have everything connected Now what I need to do is I need to take this USB cable. I need to switch into programming mode so I will switch the GPIO0 to GND, on this board is very easy because the first button is GPIO0. And I will plug in the USB And then I will release it And if I go to Tools and port it’s already connected to COM3 So all I need to do is push this “Upload” button. It will compile it and after compilation It will program the board. So I’m gonna speed it up in here so they don’t have to wait Now the firmware has been uploaded to this board so I can disconnect it, and it’s ready So I can now take it and connect it to the wall box So Ihave those 4 buttons in here 1 2 3 4 that should connect to this common ground then I have the neutral the phase and then those 4 wires that go to the shutters So it’s pretty simple, I am not gonna show you that – everyone can probably do that And the board is ready So now you know what you can do with my firmware But if your needs are simpler, but perhaps more general you can always use Tasmota or ESP Home I showed you where to find it and the principle is the same So that’s it for this video. I catch you guys later on the next one, where I’m gonna be showing you how to do automations using these boxes to automate the shades and covers in the windows Bye!