My home automation journey, or how I connect to 6 clouds to turn off a camera
By: Bogdan Ripa
Tags: Smartthings, Internet of Things, Smart Home, Uipath

My home automation journey, or how I connect to 6 clouds to turn off a camera Bogdan Ripa Feb 7, 2019·11 min read

My home automation journey started a couple years ago when I decided to redo the electrical installation at home. And since I was doing that anyway, I decided to “go smart” :)

Phase #1 — Bticino lights

I started doing some research and collected the requirements (mine and my wife’s of course):

I wanted the lights and window blinds to be controllable from my phone I wanted to make sure that whatever I build will be reliable. Meaning that even if the wifi is down and the smart hub is offline, I can still turn the lights on and off. I wanted physical buttons, not a “touch” interface My wife wanted the light switches to look good.

So my choices were really limited, but I managed to find the Bticino product line. They have light switches, shutters and a hub to control them.

The switches will communicate to the hub via a custom radio protocol, and the hub is connected to the internet.

Switches are wired so if the network goes down I would be fine.

So far, things looked good. I had smart lights at home.

Phase #2 — SmartThings

During my initial research, I also discovered the SmartThings platform from Samsung. It’s a really nice one, letting you connect hundreds of smart devices together and then implement your automations. It also has a great extensibility layer that I thought about using to connect the Bticino sub-system.

So I bought a kit (from Amazon.com), with some movement sensors, water leaking sensors, a siren, door/windows sensors (that detect when a door opens or closes), a keypad and a couple smart fire detectors. SmartThings has this concept of “arming” your house — like a home security system. And of course it comes with its own hub that knows multiple radio protocols for communicating with the devices I listed above.

So I installed everything and now I had movement sensors, door sensors and so on. The house would “arm” as everyone leaves and would dis-arm as someone arrives, and I would receive notifications if something goes wrong (like an intrusion detection or a fire alarm).

Phase 3 — cameras for outside

Next, I wanted some security cameras because — why not :)

So I got a few Amazon Blink cameras for the outside areas. All connected to the internet with their own hub.

But of course, they were not compatible with SmartThings out of the box…

So my first challenge was to bridge them.

To do this, I managed to create some “fake” devices on the SmartThings platform that would emulate the cameras. SmartThings has integration with IFTTT and so does Amazon Blink. So via IFTTT, the cameras now “arm” when everyone leaves and “dis-arm” when someone arrives. Hurray!!!

Phase 4 — bridging SmartThings with Bticino

But something was wrong. I had 2 apps on my phone — one for the lights and one for the sensors. And they were not talking to each other….

As it turns out, the Bticino radio protocol is a version of Zigbee that they modified to add some extra security… So of course, it was not compatible with SmartThings.

What to do? Build a bridge between the two hubs, of course.

SmartThings has its own extensibility layer, so that part was easy.

But Bticino does not have an Extensibility layer. So I turned to the next step: If the Bticino app can communicate with the Bticino hub via wifi/TCP, so should I.

I started by decompiling their Android app and poking around. But that app has a really bad design and was obviously obfuscated, so that leaded nowhere…

I tried playing the “man in the middle” game to try to intercept the communication by having an HTTP proxy on my computer, but there was almost nothing I could see passing through… So that must mean that the communication is low-level, maybe TCP.

After a number of long nights, I realised that on Android you can install a VPN profile that can read in the whole communication. So I used one of those network sniffing apps that does just that and managed to finally see how my phone was communicating, via TCP, with the Bticino hub and their cloud. What a relief!

Next I had to understand the protocol by playing with the lights and looking at the commands. It is not binary, but ascii.

So something like:

#0*1234#1

Would mean to turn off the light who’s ID is 1234

I’ve noticed there is also a discovery mode, where you get callbacks when something happens — that I managed to use to discover all the id’s in my local radio network, and get their states as it changes (like when I manually torn on a light).

So I took all that and created a node.js app on a Raspberry Pi that would expose all my lights via a standard REST protocol that I could call via SmartThings.

On the SmartThings side, I had to create what’s called a device handler and a smart app. The app would list all the discovered lights and ‘install’ them giving them human- friendly names.

The device handler would be used to instantiate every light. It has callbacks like ‘turn on’, or ‘set level to 20%’ and a UI listed in the SmartThings app on my phone.

So — long story short, I managed to connect the two. So now, when everyone leaves the house all lights turn off automatically, and when I open the front door, the front door light turns on (but only between sunset and sunrise).

Yay!!!

Phase 5 — voice control

We’ve all seen the movies where the house is voice-activated, so I obviously wanted that too. I knew I would not actually use that on a daily basis as it is just weird to do so (unless you’re disabled), but I wanted to do it as it’s a great demo to give my friends as they come over.

I had Amazon’s Alexa at home and — it turns out that SmartThings and Alexa are good friends. So it litrrally took a minute or so to connect the two and now, when I say “Alexa, turn on the dining lights”, it actually works! And remember the user-friendly names I gave my lights? They are automatically used via this integration so there was nothing else I needed to do.

Phase 6 — window blinds

Bticino also sells smart shutters, and I got some electrical window blinds, so I connected the two together as well.

Similarly to the way I linked the lights to SmartThings, I now linked the shutters. I created a new SmartThings app that discovers them via the Raspberry PI bridge and a device handler to control them.

So now I was able to control the blinds to open at sunrise and close at sunset. You do that via the SmartThings app.

The shutter had 3 commands, and no way to read the current state: up, down, stop.

But I wanted to be able to set them at 50% or any other level….

To do this, I ended up caching the “assumed” state in my node.js app, and used some timers to approximate what 50% means. So for example, if it takes 18 seconds to fully open the blinds and I wanted to get to 25% from 50%, I would command it to open, and then send a stop command after 4.5 seconds.

That worked just fine.

Then my wife came to me and she said she wanted the blinds to close when it’s raining or snowing. Challenge accepted!

To do this, I connected my node.js app to the Open Weather APIs and, every 5 minutes, I would check the weather and command the blinds to close if it was raining. All good!

Then one day I was traveling and my wife called saying that we have a problem. What is it, I asked? Well — it is slightly raining and the blinds closed. But I want them open, and after a few minutes they close again. Of course — I said. Every 5 minutes it checks, sees that it is raining, and decides to close them. But no, that was not good enough, so I reprogrammed the whole thing so that when manually opening, they stay opened.

Then a new request came in (also from her😂). If it’s raining but not a lot, they should stay open. BUT if it’s not raining too hard but the wind is blowing, I need them closed. Now — I am a product manager and I understand these type of requests. They make sense but come on…

Luckily, the Open Weather APIs were giving me this information so I managed to put that in as well.

Her next request? If it’s raining and the wind is blowing from the north, don’t close the shades on the south side. This is where I said “no” :)

Phase 7 — Amazon CloudCam

Amazon has these other cameras — called CloudCam. I like them and are great for the inside. They stream data to their cloud and they work quite fine.

BUT — they have no APIs of course. So you can control them from your phone, or from a browser, but that’s about it.

They have this “privacy” mode where you can set them up to turn off when you’re at home via geo-fencing, but that only works for one phone at a time. And guess what — usually in a home there are multiple people living there…

So came in my wife’s new request. “I want the cameras to be off when we are at home”. Sure — I said. Challenge accepted, again!

But how would you do that? I know that at home / not at home can trigger IFTTT since I have done that for the Blink cameras, but the CloudCam has no IFTTT integration….

I decided not to look in the phone/browser communication protocol as this is Amazon and authentication alone would have killed me…

So I turned to a different solution — RPA, or Robot Process Automation. UiPath is developing RPA solutions that lets you remotely control web browsers or any desktop apps. I got the UiPath Studio Community Edition and built a software robot that was able to open Chrome, log-in to https://cloudcam.amazon.com using my credentials, and click the on/off camera button for each camera.

Next — I needed to connect them.

From IFTTT I can call an API, but starting a new job on the UiPath platform is more than just calling an API. You have to authenticate first…

So I ended up deploying another node.js app on Google’s AppEngine that would proxy IFTTT with the UiPath platform to start a job.

The actual robot executes on an Azure Windows VM that I borrowed from a friend that had the UiPath robot installed. A windows VM is required to run UiPath’s automation.

So now, as me and my wife leave home, our phone (using geo-location) will ping the SmartThings cloud letting it know that we left, that will ping IFTTT, that will ping Google’s cloud (AppEngine), that will ping UiPath’s community cloud (https://platform.uipath.com) that will command a robot sitting on a windows VM in Azure to open a browser window, open a website that sits on Amazon’s cloud (https://cloudcam.amazon.com) and click a button to turn the camera on.

Phase 8 — The floor heating system

When we built the house we made sure to have floor heating — and we went for an electrical option as we have gas-based heating as well. It was installed nicely and the thermostats were mounted on the walls. I did not want any sophisticated thermostats as I knew I was going to replace them with smart ones that I’d connect to SmartThings.

So I went off and found these nice looking ones from HeatIt:

But wait… Since I bought them from Europe, they would not connect to my SmartThings hub (yes, these hubs use different frequencies in Eu vs. the US), so I had to buy a 2nd Smartthings hub, that works on European frequencies.

All good so far, but now… the 2 hubs won’t talk to each other… Even though both are from Samsung, both are Smartthings hubs, it turns out that Samsung does not support 2 hubs in the same location…

So what do you do in this situation? Build a bridge, of course, via IFTTT. I ended up creating virtual switches in my US hub that, when turned on or off, would turn on or off corresponding virtual switches in the Eu hub that, when turning on or off, would turn the thermostats on or off.

And lastly — I automated those switches to turn off when everyone leaves the house and turn on when someone is at home on their respective floor.

Pase 9 — auto lock / unlock the doors

To automate the house doors, I choose the DanaLock v3 Smart Locks that turned out nicely. Easy to install if you also buy a compatible adjustable cylinder.

The smart lock communicates over Bluetooth with your phone directly, but also integrates nicely into the smartthings app / ecosystem via Zigbee and Z-Wave so you can build in more automations — like “lock the door if everyone leaves the house”.

The bluetooth connection is nice as well as it help auto-unlocking the door as you approach (bluetooth range, so a few meters).

Pase 10 — making everything more reliable

As you can imagine — being so complex, all of the above can and will fail. The #1 failing component in my experience so far is the Bticino router that decides to stop working every now and then. To fix this, I added a Fibaro wall plug in the mix that can be controlled via the Smartthings APIs. So from my raspberry pi — whenever I see a connection error, I am automatically resetting the router.

And guess what? All of the above is actually working!