Tuesday, June 26, 2018

[v2.0] Ok Google, Open my curtains!

This post is a follow-up to my previous post http://vignesh.foamsnet.com/2018/06/ok-google-open-my-curtains.html.

Note: I've created a github repository which contains the code and some more details. I intend to keep that up to date with newer ideas, etc. https://github.com/vickyg3/curtain-automation

When i posted the previous set-up on reddit, one of them suggested a better way to do this that will overcome the cons of the previous method (noise and lack of manual control).

In a nutshell, these are the replacements i made:
  • Use a stepper motor instead of a servo.
  • Use a timing belt pulley and timing belts instead of a pulley and rope.

Here are the updated list of parts (with links to the cheapest ones i could find online to keep the cost minimum - although i didn't necessarily buy it from these links):

* Mounting bracket for the pulley on the non-motor end - I used a servo mounting bracket with a long screw. I am sure there are better alternatives for this one - $12.99
* Super glue - $4
* Vibration dampener for stepper motor (optional but highly recommended to keep the noise down) - $2.98
* 12V DC adapter - $8.99

Total Cost - $67.69 (some of it can probably be gotten for a cheaper price on ebay/gearbest/aliexpress).

Step 1 - Screw in the mounting bracket

This is quite straightforward. I drilled in a couple of drywall anchors and screwed in the mounting bracket to the wall.

Step 2 - Install the motor and the vibration dampener

Place the vibration dampener on the motor. Make sure that the non-threaded holes on the dampener are touching the motor and use two M3 screws to attach the motor and the dampener. Attach the pulley wheel to the motor's shaft using the screws on the side of the pulley.

Now the motor can be mounted on to the mounting bracket using 2 M3 screws which connect to the dampener's threaded holes.
Motor attached to the mounting bracket (shown without the vibration dampener).

Step 3 - Install the pulley mounting bracket on the other end

I drilled a drywall anchor on the other end and screwed the pulley mounting bracket in. I then used a long screw with a couple of plastic fillers to hold the other pulley roughly in the center.

Step 4 - Loop the timing belt around the pulleys

I had bought an open ended timing belt. I looped it around either pulleys and tightened them as much as i could by hand and cut off the rest of the belt leaving about an inch of overlap. I then used super glue on the extra inch of belt to stick to them together with as much tension as possible. You could also use a clamp like this with a screw to close the loop on the belt.

At this point, you should be able to move the belt manually by hand by pulling it gently in either direction. If so, there is enough tension on the belt to move the curtains.

Step 5 - Attach the curtains to the timing belt

Just as before, i placed the curtains in the completely closed state and attached each curtain to either side of the timing belt using a safety pin.

Here's a sketch from before about how the pulleys and the curtains move:

Step 6 - Program the microcontroller

I used the same NodeMCU ESP8266 controller as before. Here's the gist that contains the Arduino sketch: https://gist.github.com/vickyg3/623ca535b565ed43c8b617a6f7c7c06f (it is a crude version and has a lot of room for improvement, but i left it for another day).

Step 7 - Microcontroller and Motor Driver setup

Here's the wiring:
* DIR+ to D2
* PUL+ to D5
* ENA+ to D8
* DIR-, PUL- and ENA- to GND (can either be bundled together or connected separately to individual GND pins on the NodeMCU)
* A+, A-, B+ and B- need to be connected to the motor (refer to the motor's spec for the wiring colors for your motor).
* The switches on the driver need to be set to ON, ON, OFF, ON, ON, OFF (S3 and S6 should be off).

Connect the DC power supply to the driver. I cut the ends of an old DC adapter and identified the positive and negative wires using a multimeter.

I then glued the driver and the NodeMCU board to the wall behind the curtain using small command strips. Any double sided tape should work as they aren't that heavy.

Step 8 - Home Assistant Configuration

That is pretty much it. For more details on how you can control it from Google Home/Alexa, please see my previous post.

The noise level of the old servo based system was around 60 decibels (as measured by an app on my phone). The new system with vibration dampeners works at 30-35 decibels and is barely audible. Most of the noise is from the curtains actually moving on the rod.

Here's how it works (The video is noisy because the roomba was running when i recorded the clip):

Here's a video without much of external noise:

Saturday, June 16, 2018

Ok Google, Open my curtains!

Finally I've found a worthy enough reason to write a blog post.

I've been wanting to make the curtains in my home "smart" for a while now. I have what is called "grommet curtains"  and there are apparently no off the shelf solutions to automate this. There is this kickstarter project called Slide which retrofits to any curtain type, but that is still in its early stages and a bit pricey (~$150).

I ran into a tutorial which spoke about automating grommet curtains. But they used a 3d-printer to print custom designed components which wasn't an option for me (I don't have a 3d printer and i don't have any knowledge of how to design components for a 3d printer).

I borrowed the basic idea from that video. Two pulleys at either end with a rope running around them. One of the pulleys is attached to a servo which is controlled by a microcontroller. Here's an awful sketch of the idea:

Here are some of the challenges faced/things i did:
  • There is no cheap off the shelf servo that has a pulley attached to it. So i had to tweak around to figure out a way to mount a pulley to the servo.
  • The load on the servo to pull the rope along with the curtains is pretty high. So the servo has to be mounted securely to the wall. I first tried a heavy duty double sided tape, but that wasn't enough to withstand the tension of the rope. I then tried out various things and found a mount that could be screwed into the wall.
  • The wall mount for the servo held it too close to the wall and there was no room for the pulley (whose diameter is larger than the breadth of the servo) to fit in and rotate smoothly. So i used a couple of washers behind each mounting screw to give enough room for the pulley.
  • To tie the other pulley (which has no motor), i simply used a rope to tie the pulley on to the curtain rod's mounting bracket.
  • The servo had to have metal gears in order to have enough torque to pull the curtains. But such servos need a minimum of 4.8 volts of power. I found a NodeMCU board which had a 5V pin to supply enough power to the servo.

Here are the list of parts with links to where i bought them:

* NodeMCU (ESP8266) microcontroller (model with 5V pin) - Amazon - $5.98
* Jumper wire (to connect to the 5V pin) - Amazon - $5.24
* MG995 Servo (360 degree, metal gear, digital model) - Amazon - $10.99
* Servo wall mount - Amazon - $12.99
* Washers - I just used a couple of old washers lying around. Equivalent link: Home Depot - $2
* Pulley (for attaching with servo) - Servocity - $3.49
* Pulley (for the other end) - Home Depot -  $2.47
* Rope - Home Depot - $3.98
* Safety pins - Amazon - $3.15

Total Cost - $50.33 (some of it can probably be gotten for a cheaper price on ebay/gearbest/aliexpress).

Ok, with all that out of the way, let me explain how exactly i built and programmed this.

Step 1 - Attach pulley to the servo

Attaching the winch pulley to the servo is quite straight-forward. I screwed in the 4 pieces of the pulley with 2 bolts (on diagonally opposite ends) and small hex nuts. I then attached one of the servo horns to the other two holes of the pulley with two small screws (that came with the servo).

Now, the servo horn can merely be screwed into the servo until it's fairly tight.

Step 2 - Install the mounting bracket

After marking two spots with the mounting bracket's holes, i drilled in two drywall anchors on those spots. Then use two screws to screw the mounting bracket into the wall placing two washers in between the mounting bracket and the wall. This makes sure there is enough room to mount the servo along with the pulley.
This is the bracket i used to mount the servo to the wall
Step 3 - Attach servo to the mounting bracket

This is very straight-forward. The only catch is i used two nuts instead of 4 to attach the servo on to the mounting bracket.
Servo mount with washer behind. Pulley attached to the servo.
Step 4 - Mount the pulley on the other end

I used a small rope to tie the pulley on to the curtain rod's mounting bracket on the other end. A nut and bolt can also be used but since the rope worked for me i didn't look further.

Step 5 - Tie the rope on to the pulleys

Loop the rope around the pulley without the servo once. In the servo end, loop the rope around the pulley at least twice and then tie a really stiff knot. Make sure that the rope is really tight. Cut off any extra rope since it could cause friction when the rope is moving.
Rope tied to the pulleys and attached to the curtains.
Step 6 - Attach the curtains to the rope

I used a couple of safety pins to attach the curtains to the rope. I set the curtains in fully closed positions and then attached each half to one of the ropes. When the pulley spins, both the ropes will move in opposite directions thereby opening each curtain outward. The same process is reversed to close it.
Curtains attached to the rope with safety pins.
Step 7 - Program the microcontroller

This is my first foray into programming a microcontroller and surprisingly enough it was really simple. The NodeMCU ESP8266 board is a $5 wifi enabled board. Wifi means that you can send commands to it through simple HTTP requests.

Here's the arduino sketch i used to make a simple HTTP server that supports 3 commands: left, right and off (which spins the servo left, right and turns off respectively): https://gist.github.com/vickyg3/94b80435fa10a58691f563f643aaf807

Once this is flashed into the board, controlling the servo is simply a matter of "curl http://<ip>/left".

Step 8 - Mount the microcontroller

I mounted the microcontroller near the servo (using a small double side tape on the wifi chip) and just attached the servo wires to the appropriate pins (i used a jumper wire to connect the power wire to the 5 volt pin). I then ran a long micro-usb cable that i had lying around to power the microcontroller.

Step 9 - Home Assistant configuration

I added this to home assistant as a command line cover that used curl. Here's a sample configuration:

Where curtains.sh contains the following:

I determined the time to sleep between rotating the pulley and turning it off by trial and error. It usually took more time to close than to open because the set up struggled a bit to pull the curtains in that direction. It now shows up in home assistant, like so:

That's it. You can now include this in your automations, etc. I have set up automations like close the curtains after sunset, when we are away and so on.

If you have your home assistant tied to google assistant, you can control the curtain by saying "Ok Google, Turn the <curtain name> on/off". If you want custom commands, you can also try ifttt with google assistant to have commands like "Ok Google, open my curtains!".

Here's the Eureka moment

Some cons of this system:
  • The servo is a bit noisy. This is probably ok given that curtain control is not too frequent. It is probably bearable for 10 seconds or so once in a while.
  • Hooking up the curtains this way makes it impossible to control the curtains manually (since the curtains are tied to the rope). I've worked around this by sticking a button next to the curtain by the wall for those scenarios where we don't want to use voice control. Pressing the button will open/close the curtain.
    Button to control the curtains in lieu of voice/phone control.

Comments and suggestions about improving this in any way are welcome!

Sunday, October 25, 2015

Stand-up Paddleboarding!

Off late, we have developed a curious obsession. It's made our weekends much more awesome and active (physically).

Most people here either hike or bike on weekends to keep themselves physically active. I hated hiking mostly because it was sweaty and i just was not physically cut for it. I have tried it a bunch of times in the past and failed to develop any liking towards it whatsoever.

Stand-up Paddleboarding (SUP)!

Gayathri is a huge fan of water related activities. We started out with basic kayak'ing in a near by lake. As we did that, i found that to be super fun. It was literally like sitting on water. We could go at our own pace and it was awesome. As we did that, we started awe'ing at people who did stuff which seemed even more fun - like Stand-up paddleboarding, Wind surfing and Kite boarding.

We decided to give Stand-up Paddleboarding a shot (SUP) as that was the activity that seemed the most fun with the least learning curve. And boy, it was really one of the best decisions we have ever made in life. It was like kayaking, but way better. You were further closer to water, you could stand, sit, kneel, lie down (and even do some yoga while you are at it). You were figuratively walking on water with something easily maneuverable. It was amazing.

Who needs life jackets in the middle of a ~30ft lagoon ...

We are still looking forward to paddleboarding in the pacific ocean (so far did only in lakes and lagoons where the water is fairly still). We are also looking forward to learning the more harder water activites like Wind Surfing and Kite Boarding.

You can literally sleep on water ...

Until then, I highly recommend trying out SUP. Just go to a near by lake this weekend and rent one. I promise you, it will be totally worth it.


Sunday, February 1, 2015

The Arsenal Obsession #COYG

Despite being raised in India, there has pretty much been only one sport which always appealed to me. It's football (ugh, soccer). And ever since I was a kid (before moving to the states), I have been a fan of one team and one team only. Whenever i describe myself (even on online forums like Twitter Bio, etc.), I always take pride in being an Arsenal fan.

So much so that it's part of our living room!

Life on the Pacific Coast

I moved to the states about two and half years ago and the Arsenal fan in me had a very interesting situation ahead. European football games typically happen on weekend and kick-off is usually somewhere between Noon and 5PM local time. For Arsenal, local time happens to be London time, which is 8 hours ahead my local time, thereby making the US west coast to be the worst possible region to live in for a European football fan. For a game starting at noon in London, i have to be up by 4AM. That's right, 4AM!

Because of this, my typical weekend looks like this:

Say the game is on Sunday at 1PM London Time.
  • I'm usually out on Saturday nights pretty late (either a movie or something else).
  • Back home around midnight.
  • Spend some time playing games or watching something on TV.
  • It's around 2PM or so at this point and dilemma ensues. Do i stay awake for 3 more hours and watch the game, or should i get some sleep (and risk missing the game by oversleeping)?
  • More than often, i end up staying awake the whole night.
  • Watch the game.
  • Sudden existential crisis for the rest of Sunday. What now?

Twitter Effect

When i was in school, we watched games as a group. Always as a group. When i moved to the states, I have been meaning to go to a sports bar and enjoy the game with a supporters group. But i have not managed to do so even once (usually because of the ungodly hours).

Twitter came to the rescue. I usually tweet a lot during the game (and annoy the crap out of my non-football friends) and i have made a lot of new friends (living on various parts of the world) because of that. I now really feel that watching the game with Twitter feed open is as good as watching it with friends. And there's always casualties (TV Remote being the worst victim).


I'm slowly getting towards a point where i might be able to afford to fly to London once or twice during a season. I am really looking forward to making it a habit of attending one or two games every season in person.

And by the way, for the uninitiated, #COYG = Come On You Gunners.

Happy February Everyone!


Thursday, January 1, 2015

Tis The Season - 2014!


This is me with another attempt in vain to remind myself that i should write more.

2014 has been wonderful. Lot of memorable moments. First full year as a married person. A wife who loves you more than the world. A job that, well, i really have no words to describe it, it's that good. I could not have imagined a better life.

The year started just like any other. The first big moment was in March where we celebrated our first anniversary.

And then along came a pretty sweet moment at work. I got an opportunity to give a recorded-talk at Google I/O, Google's annual developer conference. It was a big deal as developers from all over Earth tune into it.

Then thanks to my girl we got to spend the summer in Seattle as she was taking up an internship there. It was three awesome months that encompassed a wide range of cool things like living across the street from Space Needle, flying on a sea plane, an awesome trip to the island capital of British Columbia. Not to mention, getting away from the heat of California's summer.

Along came October where there was a really fun filled party for her birthday.

Then came the holidays where we did crazy things like reaching 130ft beneath the Pacific Ocean on a submarine.

126ft beneath the Pacific Ocean!

I am writing this as we pack our stuff headed to celebrate the dawn of 2015 in random parts of the California West Coast.

Until then, Mahalo & Happy new year 2015!

To end this post, a random quote from Phoebe that always makes me laugh - "If you wanna receive email about my upcoming shows, please give me money so that i can buy a computer".


P.S.: I cheated in this post by including more pictures than words. Although, i really hope that i will write more in 2015!

Tuesday, July 15, 2014

The story behind Seattle's floating homes!

In Seattle, there are a lot of people who live on the waterfront (in Lake Union). There are two types of floating life shelters: Floating Homes and Houseboats.

Houseboats are one of the most ingenious ways i’ve ever seen of gaming the system. It’s a pretty long but very interesting story. Read on.

Back in the early 1900s, people who could not afford a house on land in Seattle started building simple house-like structures using some logs and put them on Lake Union and started living there. Since the lake was open to the public, anybody was allowed to build such a "floating home" free of cost and live there.

People who lived on such floating homes did not pay any property taxes. On realizing that, a lot of people who lived on land started moving to the lake and naturally it started getting crowded. Since these floating homes did not have proper sewage system, people started to dump all their waste on the lake and hence it started to become a mess.

The City of Seattle then decided enough is enough, and drew up some regulations on how many floating homes will be allowed on the lake and designated certain spots in the lake to be for the exclusive use of floating homes. Since the number of homes were limited and they were always docked, they also decided to hard wire them into the city’s sewer and electricity systems. Thereby, floating homes were started to be considered as regular homes and people needed to pay property taxes on them.

The floating home used in the movie Sleepless in Seattle

When something becomes “limited edition”, obviously the prices go up. So all of a sudden, what was once the home of people who could not afford a house became a limited edition floating home that started to go for millions of dollars. Also, sewage and electricity were no more an issue.

Now, there were this new class of people who couldn’t afford a home on the land, and obviously not the waterfront as well. So they just started to put a roof on their boats, and started living there. Since they were just regular boats, there was no restriction on how many such boats could be in the lake as long they are registered vessels. It gradually evolved and today’s “boats” look like this:


628x471 (1).jpg

You see what they did there? It’s a lake and obviously the city cannot put a limit on the number of boats allowed on the lake. These “boats” are registered as vehicles to the DMV and are authorized to be in the lake wherever and whenever they want. The only restriction being, “they should be able to move on their own”. So all they need is to have a motor underneath that will help them achieve that criteria.

628x471 (2).jpg

If you look closely at the above photo, you can see a Honda motor attached to it on the bottom left. It’s very impractical for the city to enforce that rule on a day-to-day basis. So most of these boats, even though they self-propel at the time they are registered to the DMV, they hardly remain so throughout the year.

So today, you can find a lot of such "Houseboats" on the waterfront of Lake Union in Seattle.

P.S.: This was a story that was told to me when i took the Rode The Duck in Seattle. It’s really an awesome tour and i highly recommend taking it if you are visiting Seattle.

P.P.S.: I originally wrote this for this Quora question: "What are the best examples of people gaming the system?"


Friday, June 27, 2014

Use your Chromecast/Roku on a Hotel WiFi

Chromecast and Roku are really wonderful devices which allow you to take all your media with you where ever you go. Especially, if you travel a lot, it's definitely way better to watch something on your Netflix subscription rather than paying exorbitant rates on the hotel's pay-per-view.

But there's a problem. Hotel WiFi's usually use web based authentication (i.e.) their wireless network is usually open and anyone can connect to it. Only when you try and open a webpage, they send you to an authentication page that asks for a username/password (which the hotel will provide you) and/or asks you to accept the terms and conditions.

The problem is that Chromecast and Roku do not have native support for such authentication. But fear not, in this post, i am going to write about a few ways in which you can work around this limitation to enjoy Roku/Chromecast on the hotel's WiFi network.

Find out your device's MAC Address

2 of the 3 workarounds that i mention requires you to know the MAC Address of your Chromecast/Roku device. Here's how you figure it out:

  • Switch it on
  • Navigate to Settings->Network->Wireless
  • On the bottom right, you can see the MAC Address of the Roku
  • Switch it on
  • Connect your phone to the hotel WiFi and authenticate it
  • Open the Chromecast Setup app on your android phone
  • Tap on devices and wait for it to scan
  • Tap on your Chromecast device in the list
  • Tap "Set Up"
  • Tap "I see the code"
  • Tap "Set Name"
  • The MAC Address of your chromecast will be displayed on the screen now. 
Workaround 1 - Call the Tech Support

Most hotels give you a small sheet of paper with your WiFi username and password. That sheet usually also has a "tech support" phone number. Here is what you can do: Call the tech support number and tell them exactly this: "I would like to use the roku media player device over the hotel WiFi. I wanted to check if you could whitelist the MAC Address of my device to by-pass the authentication page".

Depending on the mood and knowledge of the tech support person, he/she might say okay. But nevertheless, it's gonna take some time before the whitelist happens. And once the whitelist happens, you can enjoy Chromecast/Roku over the hotel WiFi.

Workaround 2 - Spoof your MAC and authenticate from your laptop

The whole web authentication system works around MAC addresses. Once you enter your username and password, your MAC and IP addresses are going to be whitelisted for a certain amount of time (about 24 hours) and your device will be allowed to access the internet in that time period.

One key weakness about this authentication mechanism is that MAC address is easily spoof'able. So we are going to to assign your Roku/Chromecast's MAC address to your laptop and perform the authentication like usual and then make use of that whitelist to access the internet from your Roku/Chromecast. Here are the steps (follow them precisely to the word):
  • Find the MAC address of your Roku/Chromecast using the steps above. Note it down.
  • Open the terminal (assumes linux).
  • Run "ifconfig" and note down the MAC Address of the laptop. [1]
  • Run this command: "sudo ifconfig wlan0 down".
  • Disconnect from the WiFi network on the laptop.
  • Run this command: "sudo ifconfig wlan0 hw ether <mac address of roku>".
  • IMPORTANT: Turn off the Roku/Chromecast by unplugging it.
  • Run this command: "sudo ifconfig wlan0 up".
  • Connect to the Hotel's WiFi network on the laptop.
  • Open the browser and navigate to google.com (or any other website).
  • It will ask for authentication, provide username/password that the hotel gave you.
  • Type google.com again and verify that you can access Google.
  • Run this command: "sudo ifconfig wlan0 down".
  • Disconnect from the WiFi network on the laptop.
  • Run this command: "sudo ifconfig wlan0 hw ether <mac address of your laptop from step [1] above>".
  • Run this command: "sudo ifconfig wlan0 up".
  • Now you can plug your Chromecast/Roku back in and connect to the Hotel's WiFi network on that. It should now be connected to the internet!
You will have to repeat these steps after the whitelist expires (usually about once a day).

Note: The above two work arounds will connect your Chromecast/Roku directly to the hotel's WiFi 

Workaround 3 - Set up your own WiFi network

Buy a portable WiFi adapter and use that to share your Hotel's WiFi through your own access point.

Hope this helps!