Duration 30:50
16+
Play
Video

RailsConf 2019 - Automate your Home with Ruby by Karl Entwistle

Karl Entwistle
Senior Ruby Web Developer at Cookpad Ltd
  • Video
  • Table of contents
  • Video
RailsConf 2019
May 1, 2019, Minneapolis, USA
RailsConf 2019
Request Q&A
Video
RailsConf 2019 - Automate your Home with Ruby by Karl Entwistle
Available
In cart
Free
Free
Free
Free
Free
Free
Add to favorites
1.3 K
I like 0
I dislike 0
Available
In cart
Free
Free
Free
Free
Free
Free
  • Description
  • Transcript
  • Discussion

About speaker

Karl Entwistle
Senior Ruby Web Developer at Cookpad Ltd

I am a software engineer. I like: reading science fiction novels, watching documentaries about space, time and the universe and cooking.

View the profile

About the talk

RailsConf 2019 - Automate your Home with Ruby by Karl Entwistle


With the increasing number of home automation devices, our homes are getting smarter and smarter. How can Ruby help?

Instead of installing separate apps to control my many devices, I wanted to use HomeKit via Siri and the pre-installed Home app on any iOS device, for one unified experience.

This is a talk about how I created the first ever Ruby library for the HomeKit accessory protocol to bridge the gap between different platforms and just some of the exciting possibilities this could unleash.

Share

I have run for this talk is entitled ultimate your hands everybody. My name is Colin and you can meet me at call. Am I so fat? And they just wanted me to come through rounds come and get this talk. You can probably tell from my accent. I'm not from America. I'm not sure you from the UK. And this is my first time in America Adam to my thoughts, trials, and my brain's been a bit of a weird thing and the things that associate nice with America is the video game Grand

Theft Auto. Sorry, sorry. What while I'm walking around in like the downtown area, I feel I feel a bit like I'm in Grand Theft Auto and everyone else is like a an NPC will can cost. So yes, it's a bit confusing and I'm from Bristol in the in the UK and Bristol is a city and county in the southwest of England. I used to live in London, but my wife and I wanted to buy a house, so we need to Bristow and property prices a month Tomorrow full double in bridge building in London sweep or mother spies

high as you can. Scratch my house once much bigger. So I'm off to mix into a house. I decided that I wanted to be a small home a smart home from the future with some light bulbs Starbucks in Philips hue light bulbs in a cut them in all the rooms in the house and the Philips hue light bulbs need an application to control them. So my wife and I downloaded and installed the application on 12 finds soft lighting situation under control. I decided the next thing that

would be good for us to control would be the temperature with a smart thermostat in England's kind of cold. So it's quite nice to be able to set the heat to come on or off before I leave the office. So it's the same situation. We have to download and install accept application. I'm on spy for things we can control that. This is actually in high school and Hope she got the idea by now or if there's two different devices that I needed to buy vitamin needs why I wanted to buy they'll require their

applications. We ended up with nine different applications on a phone to control the various Scotch. It's the pool and there's no consistency between them and interoperability between them the gadgets from like different manufacturers and it's kind of a closed ecosystem. So what I really wanted was one unified app one applications control of my devices and it turns out there is such an application and if you have an iPhone is pre-installed and it school time. Anthem

hinges is a framework for Titan cat. So what is Titan cat? Well on a framework for making smart home devices work seamlessly with iOS devices. And this means you can control your smart home devices using any of the devices in Apple's ecosystem. I don't care since the latest update to the elf rating system, which I think is pronounced Mac OS mode mode off cities are the types of devices behind his official officially support as lights power points Windows fans to name but a few You can see

the rest on the flight. Something I really liked about him chat is that you can control it with Siri. So you can say come ons like turn on the living room lights turn off the lights set the dinner scene or my personal favor at what temperature is the shed. Route route normally not science in an Irish accent that the temperature is like 15 degrees or something that's in celsius to fahrenheit. In addition to Siri. Does the visual components to the bathroom? So I'm controlling the Philips Hue Lights like the

brightness. I know so recently installed some underfloor heating. I'm a bit of a DIY and fees you so I can retire control of the underfloor heating. I know you like Phillips on the floor heating sites to separate benzos within the one application. Okay, so that's the end of this whole quiet you just buy things that's full of there is a bit of a problem and not problem is that you can use devices with homekit if they have any support and you know that fish least important because they have no sticker on the box or the website that

says that it was about the Philips hue light bulbs for the nest thermostat on the Soundbar that I had to know so I could have theoretically uni devices, but I don't really want to cuz that would have been pretty expensive and likewise. So I had a bit of an idea what if I'm cat communicate? Bennett be able to bridge the gap between Huntington and any unsupported devices so I can control my soundbar behind cat and it'd be able to say something like hey Siri switch on my soundbar. So this point I did

the obvious thing. I said Google and get hub for hunting chat Ruby library, and I'm sending you surprised that one didn't exist. I wondered why that's what how hot can it be to get life refer eBay. I am so remember to quite from a very influential man. And I Gandhi once said you must be the change you wish to see in the world. So I decided I was going to create the faster U library fighting cat. And I did pray and it's cool dream behind me and you can install it with them in so we behind and it's just won't get hot under the collar Musso 4/3 behind.

Search for I speak a little bit about how I create at the gym and then I'll show you how you can use it to estimate your home's. So the first thing I did was one on a Fool's develop website and downloaded the non-commercial version of the hanky accessory protocol specification. I know I was just I was really happy to find out the specification and I was really excited to find out that it was a very technical 256 page document that directly reference 12 are C's go on to the specification on a stool tables hexadecimal

code of a Spate HTTP protocol and something about the Cha-Cha 20 poly 135 Wichita and out was a form of encryption and stop seeing all dawns. Probably the most logical thing to do at this point was to use the accident JavaScript library, which already existed instead. However, I really did want cheese where you be and I'm also pretty quickly enough maybe over a weekend but actually ended up taking about six six months of light hacking away on it in the evening so I could have sat down and read the whole document. However, it's quite a long

read and it's quite Technical and also its prey abstracts. Like if you trying to read and understand and isolation, so instead of doing that I decided to walk through the process so if interested play as if I just bought an officially supported accessory, so let me explain what I mean by that soothe irritated for the whitefly pairing a new accessory. I press the plus icon. click add accessory and I said I didn't have a Kyoto couldn't scan and let it put me to the screen and I knew from past experience that the accessory should be displayed

to so at this point. I just got through the specification to try and figure out how to make the accessory appear here. I ended up translation. It says accessory service must support multicast DNS. How do you spell names? Okay. So everyone with Michael iPhone will already be familiar with multi cost you an ass or a hole that bonjour anytime you want the shed devices sidebar populated by computers appetizing that services using Poncho multicast DNS iOS when you're using a drop its results to populated with most costly and I

So I found this great the software by a company couto days off coupons your browser and it displays of the monkey Christiana services on your life will not work. They're going back to the problem as a Saturday outing to Philips Hue Bridge, which officially Sports haven't yet. Sorry using bonjour browser. I could see the key value pass that it was broadcasting this point. I need just need to review library to broadcast. They stimulate Ki bani past. I found a really good motocross tienes library for rebate and it put the nssd milia face

Paxton or Tender Love. So I think they would do I want it and it has a really simple syntax so you can see here that I've required the nfsd and then I was signed an instance of an instance of a TCP server running on post 88 to the variable TCP server, and then I've used DNS Estes libraries announce function, which makes the sorry it takes the TCP server Synology men and a string. Which I just sent my TCP Saba. So if I run that Kayden I'll be and take a look at it

in banjul browser. Then I could see the service was being at the party. So I'm not so you cannot defy Services as well. If you ever need to do most cost DNS at this point. I just mimic to keep have I least it was coming from the Philips Hue bridge and then back on my phone. I could see Reba hiring appearing is not classical. So now how to appearing as a service I could click on the icon. And it cost me for Sal code. So I just put in 1 2 3 4 5 6 7 8. Because I was just like

running for it. So then at the spots the following HTTP post request my TC piece of everything of his prey Norman at first glance and then use the content type. So the content type is application for parent plus t l V8 a stranger for a few hours before I was expecting maybe come out. I wonder if the body of the request. Best yeah, pretty much how I felt the long and pretty complicated hiring process. I don't want to go into too much detail about the firing process cuz we would be here for quite a long

time. But the key thing that I needed at this stage was to be able to understand what the body of the request men so I could proceed for the pairing process start again. How did I do this while I just saw it to the documentation for the one piece of information I had which was that application Parent Plus tlv Farthest point in the documentation. It told me that parent response is it delivered is tlv data in the body of the HTTP response with that next new piece of information, which is POV and

intersection in the documentation. So in order to read the hexadecimal beta is there was being sent to the sub. I found another reading ice Jim Corbin die side and Pain Center provides a decorative way to read my structured binary data. And this means you can specify what the full name of the binary days to is and sorry if the binary tree's open Dice WhatsApp has read my data in this format. I know so if anyone choose Riebes Paco unpack methods they can get quiet to like

complicated and difficult to manage. Sorry. We've been later has a lot easier to read and write the structure data so you can see that it's actually to tlv is an HOV contains an 8-bit pipe followed by an 8-bit lamp. I'm not lamp tonight's how much is the value should read special places. We know that the value is 211 that long so we can read that file you get in free to pairing process each of the devices like my iPhone on my iPad. The iPad was very behind cuz he has its own unique Titan. I don't sorry behind holds a

car spawning you need to make him fit each of the devices and eat time. You'll find comes on to the network. Like if you arrive home then it will pay for the pairing process and actually holds the connection first price in a long time. I don't know how the two actually life doesn't just go down pretty quickly. But somehow it holds the TCP connection are you can leave your house. Obviously the connection is closed and Teen Titans got generated next time the device comes back on the network.

I also mention that the Hat specification requires a custom HTTP server. I'm not sure at the time when the two when they discovered the fire and hope that you know how you can let it switches to this customized HTTP and the documentation says each HP messages splitting frames know lots of the 1024 bytes. I need frame has the following format. It was such as one session security has been established if your accessory encounters a decryption failure, then it must immediately closed the connection used for the secession. Sounds pretty complicated.

Like what does that mean? What does that diagram mean that she turned out to be pretty simple. So just explain it briefly. She now. This is a standard HTTP 1.1 response and you can see the price code is HP 1.1. And the states code is 200. Okay, that's from Heather's light content type content and I'm sorry, but they don't show up. Just putting some lorem ipsum for a nice long body for demonstration purposes. Do we take that entire response and we are breaking Austin's free frames. And as you can see the first one is 1024 bytes.

The second one is 1024 bytes. And the last one is the remainder which just happens to be 792 by its sorry off to be taken each of these frames. We encrypt each one of them individually I do. So at this point, it doesn't obey of additional metadata decided which is who turn on swish dance photography ones. And this is a number of pets during the shoes. He wants and it's is so used to calculate the contents the encrypted message so she did Value for the nonce you got out one series of theta energy change the new got

an entirely different month. Do I mean Christy to the frames individually, we identify the nouns and it starts as they are and then one and then to and from that you got the encrypted message for each of the frames. So you can concentrate sceva the three encrypted frames and then you got your customized top Force Ones, which is just like a gulf of hexadecimal date. So I know the reason I mentioned the nuns is cuz it's pretty cool because it prevents response re playing so if someone is on your

network and is somehow packet sniffing requests and responses that being said for the country play the request and this is because the firing Andrew behind by snarky what the numbers count should be for each request. So if someone's on your network and that I like pockets and change request without the speech of it be able to just replay the request to Reba hunting and if you have like a small home door lock or something. If you could just replay the request then they could potentially just reflag access to your house for your door.

If you're still with me, you might be wondering if I did this encryption pot with a middle. If we briefly revisit, right or if you're already familiar with it. You know that he's right you provide an app an object the response to the Cool Math fit taking the environment hashes promise that I'm returning an array with free element, which is the Hasty Response Code. I have had as a nurse one spot so that slide on screen now is the rock DSL for sending this HTTP response and I've labeled the Response Code the headers and the body Sexy remember I need to encrypt the whole thing icon just

in the body contest in crib the head is I need the whole response be encrypted just before it's being sent to the device. So as far as I can tell I couldn't make this as a rock middle at I think it's a little bit of limitation with the rock middle ydsl. I don't think my problem using Rock hijacking but ended up causing more problems than it solved. I'm so at this point. I have a stiff drink and a bit of a thing and I was just like to browse through the web resource guide. This is the wrong method and what breaks HTTP server class is probably a bit hard for

you to read. So I'm going to remove the exception handling timeout logic and connection close me or Jack and this is what we laugh with. The First Crusade like cool out is the pause section midsection uses an instance of the HTTP request object to read the contents of the socket has been paused in the Second Crusade. I'd like to point out is the senators from section. I miss texting uses an instance of the HTTP response subject to write the contents of the HTTP response to the fuck are so stupid controversial and don't show up. But why did at this point with substitute the

HTTP request an HTTP response floss is with my own Clause's the entire life from the original like this So now when we get to the pause section inside of my custom cloth, I can override the pausing logic and if the request is supposed to be unencrypted a Jacuzzi for with the socket and if it's supposed to be encrypted. Badnam, I can just increased the data and then send it over to the socket and it's a similar story for the the response. Safest place to be an encrypted. I just received. However, if it's supposed to be encrypted then I do the operation and then send out Eva ended

up with an architecture for the gem that looked a bit like that. I'm not paying that you will run home and I ride went back on your life production apps but it works for behind make it by a please to speak to me off to this Hawk. The last thing I wanted to explore with you from the Hat specification is unsolicited HTTP, the documentation says. Accessories deliver notifications by sending an event message and this is an unsolicited HTTP response to this means the HTTP server

support responses at any time because the iOS device inside. I have kept to suck it connection iPhone. So I thought diagram here and it shows you two devices that going for the pairing process. And if one of the devices like the iPhone in this diagram request for adults, and then re behind will broadcast an event to the iPhone and the iPad that didn't originally make the request so that they fights knives at the door is now - and another example of this is with the pharmacy could someone can obviously physically I'm done a lot for dogs on the temperature on that. You can solve in stop

that request cuz that's an API like the next API and then broadcast. To the devices that pad of Reba hiding flat do know that the temperature is changed. So everything keeps NSYNC Okay, so that was quite a lot of technical stuff. So now it's going to be a bit more lighthearted Richardson. This is where the character that takes Andre Heinz Kraft fine as you can see you require e behind. I know the devices I mentioned idea like lights power switch is Windows fans are all types of services. So I've used to be behind service Factory which I basically modeled off of

factory factory rotten. I'd like turn up my volume up on my iPhone. an effect on an accessory I said I don't have to call you dokkan scan. And now at this point I start running the program just to show you the most cost DNS. Search generator unique code. Which I now - on the phone. And then it's going to go free the pairing process. So now it's going to be the parent price estimate just confirming the different services. And you can see the van that so I can switch on or off. On a

cool thing and how you miss that all the different Services have different widgets like this that you can check on C C Moore. And control them. Okay, cool, so what if you got you want to know Andrew be home if someone is switch to find on or off well, like I said the financing service and service has many characteristics I'm one of the characteristics of a fine is the aptly-named on the characteristic Henry behind you can subscribe to changes on a characteristic using the off drop date function, which

will yield block with the updated value if the characteristic so in this example, I just said if you updated value is equal to true then we can puts into the terminal that the finest on otherwise we can put the fan is off. So let's run now. So I'm just shutting down the server and then starting against the change gas applied. I know the phone's going for the pairing process again, and I switched it on and it says in the town of the fine is on the switch 2 off. I've used the front switch it to do it again.

And like I said earlier you can control it with Siri as well. So I said Siri switched on own. I think I switched it back off again. Yes, I did. Okay, cool. guava services I'm sorry, so I'm just going to reduce the program back down to those free lunch. And also want to show you the other types of characteristics that van has and you can see behind yourself for sagging them name on rotation speed and direction and they keep having you so I've supplied hear it going to be the initial values that are applied

each time the side of a cat's worst off to it. So If I apply. Code and shut down the server again. when when it repass, I just had to order off so that it picks up the change. But now you can see that I've got the speed so I can control the speed as well. Honor Society rotation direction so the the widget guess more or less complicated depending on the different characteristics of the service supplies, So I'll just put it here in 2 in the fire. So you can see that the request Summers the requested a r e d coming for you to read behind and you could only see subscribed to the changes as well

like I did earlier. Okay, cool, so what if you want more services than just the fine well then we need a bridge so how do we create a bridge in all this crap. She just talked to include another service that school accessory information to the party but I'm Set up. So now the park. I'm happy accessory information service in the van. And then in addition to the fan I've added six all the services. I just picked in the air purifier and a quality sensor the garbage door

light bulb on an outlet sci-fi safe out and running again. I quite like the spot cuz when you restart the program they will just magically appear. I do. So like I said all the characteristics you can subscribe to that off drop date so you can do some quite cool things cuz you could use something like fire dates and the HTTP request. So I made a witches website with a hex code Color Picker so you can change the color on this website has kind of simulate a light bulb and now I can control the color of the website using a hunting cat on

the on my life. I live right behind. The last time I die I want to show you if you remember the Soundbar that I mentioned. I can switch it on off the unsolicited events. Cuz when the timer runs you'll see that I'm requesting it on the fine. And then the update is getting broadcast to the iPad and vice-versa so much fun. Now. connect controller using sound bars in remote control And then I'm just going to leave running that keeps checking the soundbar to say are you on or are you off and if the state changes that I broadcast said to have to

pass devices? Elliott has lots of different Services. You can use your free behind and the fullest of them is here. Now I could show you. Maisel. They about to go to stop somewhere and leave you something to imagine. So if I caught you excited, then you can oversee Usry behind white people side Lenape about how you can split a large problem into small and manageable chunks. And yeah everything you need to know about Reba hiring if you want to use it. Everything in my to look and thanks very much for listening.

Cackle comments for the website

Buy this talk

Access to the talk “RailsConf 2019 - Automate your Home with Ruby by Karl Entwistle”
Available
In cart
Free
Free
Free
Free
Free
Free

Access to all the recordings of the event

Get access to all videos “RailsConf 2019”
Available
In cart
Free
Free
Free
Free
Free
Free
Ticket

Interested in topic “IT & Technology”?

You might be interested in videos from this event

September 28, 2018
Moscow
16
166
app store, apps, development, google play, mobile, soft

Buy this video

Video

Access to the talk “RailsConf 2019 - Automate your Home with Ruby by Karl Entwistle”
Available
In cart
Free
Free
Free
Free
Free
Free

Conference Cast

With ConferenceCast.tv, you get access to our library of the world's best conference talks.

Conference Cast
577 conferences
23312 speakers
8705 hours of content