The past few years have seen an explosion of IoT devices. Many of these are for the so-called
smart home. Their true potential lies in the ability to coordinate and automate them as a
group. How can your garage, Wi-Fi, Chromecast, and window shades work together automatically?
Chances are these are all from different manufacturers with different protocols and
apps. That's why you need something like Home Assistant. This Python-based app brings over
740 devices together and allows you to observe, control, and automate them as a whole. This week,
you'll meet Paulus Shouston, who created Home Assistant. This is Talk by Thinomy, episode 122,
recorded July 25th, 2017.
Welcome to Talk Python to Me, a weekly podcast on Python, the language, the libraries, the
ecosystem, and the personalities. This is your host, Michael Kennedy. Follow me on Twitter,
where I'm @mkennedy. Keep up with the show and listen to past episodes at talkpython.fm,
and follow the show on Twitter via at Talk Python. This episode is brought to you by Rollbar and us
at Talk Python Training. Be sure to check out what we're offering during our segments. It really helps
support the show. Hey, everyone. Before we get to the interview with Paulus, let me just share a quick
news item with you. So last week, I was interviewed on one of the other major Python podcasts, Podcast
Init, and the topic was the migration to MongoDB. So I met with Tobias Macy, and we had an hour-long
conversation about why and how and so on. I migrated all the podcasts and training sites and things like
that from SQLAlchemy and a relational database over to MongoDB. What went well, what didn't, lessons I
learned, things like that. If this is interesting to you, just check it out at podcastinit.com, or if you
subscribe to the podcast, you can find it there. Now, let's talk with Paulus about home automation.
Paulus, welcome to Talk Python.
Yeah, welcome. Hey.
Hey, great to meet you and talk with you. I'm really excited about this project that you've created.
One of the biggest, booming, growing, exciting areas is not really smartphones and devices anymore. It's
internet of things and smart homes and little things that used to just be dumb widgets that we can now
bring together. And really, what you built is not about the widgets, but about the bringing together,
right?
Yes. Yeah. The main goal of Home Assistant is to, you know, we have like, well, we call it the three
pillars. We have observe, control, and automate. And the observe part is first bringing together,
just knowing what's going on in the house. Control is being able to control the devices that are in
your house. And then automate is based on observations, issue control commands.
Yeah, that's awesome. And I'm so looking forward to chatting about it. But before we get into all
the details there, tell us about your story. How do you get into programming in Python?
During college, I studied, I initially studied computer science, but I actually dropped out.
I was more interested in data. And so I started doing a business intelligence major. And there,
I mean, you're always doing stuff with data. And I was always like using, like you're doing small
projects in college all the time. And that's where I kind of like Python started to like sneak in.
In the beginning, just based on what I know, how I used to learn programming, there's still a lot of PHP,
but I slowly switched over to Python. And actually, when I was doing my master thesis is where I
started doing a lot more Python. And that's also when home assistance started.
That's cool. What was your thesis on?
My thesis was on Medicaid fraud detection for the federal government here in the United States.
Wow, that's really cool. That's I think there's really an untapped area in all of this
medical information. It's pretty locked up, but it's starting to open up for machine learning and
things like that.
Yeah, I think there will be a huge potential just like even anonymized data can give us so much insight in
all these things that are going on.
Yeah, it's going to be cool as we get enough of this data out to actually do analysis.
Okay, fraud is also good. Make sure that people who paid for the care or are paying for the care get it.
That's great.
Just for having this obviously unrelated to the topic of the podcast, but the fraud was actually
not the people paying for the insurance. It were the doctors and the hospitals.
Wow, that's kind of creepy.
Medicaid is a free insurance. So those people actually didn't care how much got billed for
them a lot of times.
Right. They maybe didn't even know. Okay, I can see that. That's that's a little more disturbing. But yeah,
good that someone's on keeping them on us. That's cool. So what do you do day to day these days?
I'm a senior software engineer for Appfolio, which is a software as a service company. We provide a product
for property managers to run their business in the cloud and a product for lawyers to run practice
management in the cloud. And I work on the lawyer side of things. It's called my case.
Okay, that's really cool. I feel like there's an untapped market. Well, not entirely untapped because
you guys are doing it. But there's a big market for these super niche tool sets for just you pick
your vertical and there's there's probably a not great solution for most most people, right?
Yeah, definitely. And I think every so many verticals are still in like, you know,
doing things with pen and paper or Excel spreadsheets for everything and being as a software as a service
being able to build like an integrated solution that you know integrates everything from like,
intake of clients to like billing clients to keeping track of your work sharing things with
clients. There's a big opportunity.
Yeah, that sounds really cool. We could definitely talk more about that. But let's let's talk about home
automation. So you've been working on home assistant for about four years. And before we get into home
assistant, I'd kind of like to get your your vision of the perfect home automation because you've written
kind of a blog post manifesto type thing of like, here's where we should aim for this. What's your
vision?
Yeah, so my my vision for home automation is that a lot of people that kind of like, it's kind of like
the early adopter phase where we're in right now where all these devices are entering the houses and
people are realizing that with their smartphone, they can control their lights, they can control like
the thermostat. But they tend to forget that it's usually not faster to, you know, actually use your
smartphone like they tend to, you know, put in all these smart lights and all of a sudden your switches
don't work anymore because your smart lights always need energy to be communicating with the network and to be part of the end of things.
And so all of a sudden people like end up not having any light switches, which means that all of a sudden when they enter a room,
they have to get their phone out of their phone, make sure it's connected to the network.
And actually, they actually are instead of improving their life, they are decreasing their life experience kind of.
Yeah, I totally think you're right with that. I mean, these things need to be kind of seamless like they are but better.
They need to get better, not not just different, which makes it really it's a big, a big challenge, but a big opportunity.
You know, like a quick, quick story. I was out biking the other day and I got this smart bike lock, this super tough smart bike lock, Bluetooth, you can control it, do all sorts of stuff.
It works kind of okay. But you unlock it with your phone. And the phone wouldn't connect to it. And it was locked up. I'm like, what do I do? There's no key.
I might be just stuck here. Because that stupid Bluetooth won't pair. What am I going to do? And this is like, this is the problem, right? Like, it's fine until it doesn't work sometimes, right?
Yeah. And I think that's also another important part of like, you know, your Internet of Things devices is when you want to like, when your phone doesn't work, or you can't connect to it, you should still be able to like, be able to use your device.
So in case of your lock, that's a very bad, like, you know, experience where like, oh, the Bluetooth doesn't work. Well, you're screwed.
Yeah, yeah. There is a little panel, but it wasn't working as well. So like, it was, it was bad.
Yeah. For example, the Philips light bulbs, when you turn them off with the electricity, like just the electricity off, and then you turn them back on, they will reset and turn on and like a white light you would expect from a normal light bulb.
And so that's a nice experience. And even if you have a light switch, you can at least turn your light switch off and on to get the light to turn on.
Right. So the failure mode is kind of like the dumb home, or whatever, the dumb device, in a sense.
Yeah, exactly.
Yeah, and these are the lights that you can dim, you can like change the color.
And so they just go back to full power light, or something like this, huh?
Okay, that makes sense.
Yeah.
Other parts of the home automation part is that like, a lot of people will build automations that are optimized for their own life, like as a one person in the household, but most of the times you're not one person in the household.
So it's very annoying if an automation triggers, and it's not like somebody is like annoyed by it.
So for example, if you're, you know, if you have this automation to turn off the lights or dim the lights when you are going to watch a TV series, if somebody is like reading a book on the side, then their light is gone.
That's right.
And so it's very difficult.
You want to write automations that have like very, very high success rate.
And the problem to writing automations with a very high success rate is that you either need to have a very scheduled life, you know, you need to be constantly like every day has to be almost be the same.
And like have patterns for everything.
But I mean, for a lot of us, that's just not the case.
So we need to make like small automations that improve our life, but do not like work against you in the case of like you're going off the pattern.
Yeah, exactly.
Like, for example, you come home and normally you unlock the door with your phone, but your phone is dead.
Now what?
Yeah, exactly.
So one of the automations I have, which has been very stable, is that like when we open the door, my phone is connected to the Wi-Fi.
So home assistant knows I'm home and it will turn on the light, but only when the sun is down.
And so the worst case is that the light is not being turned on for me and I have to hit the switch.
Right.
So the failure case is like what you had before.
Yeah, exactly.
Okay.
Yeah, that's really cool.
So another thing that you said in your vision was the perfect app is no app.
What do you mean by that?
It's kind of what I was talking before about like how the switch is faster than like opening your phone.
And for most of these applications that you're having in your house, it is just as convenient or sometimes even more convenient to just go to the device and control it.
The only thing that actually is coming up now that's going to be faster and more convenient is the voice assistants.
So there's like the Google Home, the Amazon Ego, because those devices, even if your hands are dirty, for example, you're cooking or something, you can still control it.
And it's very convenient.
Yeah, I think this is that example really highlights some of the huge possibility and benefits, but also some of the challenges, maybe even apprehension for some people that we have this possibility of having this thing listening all the time.
You can just speak to it like like like on Star Trek, like computer, dim the lights, please.
It's amazing, right?
It's just so incredible.
But, you know, a lot of people are concerned about having a thing that is like constantly listening to them in their house all the time.
Right.
Yeah, no, that's definitely a valid concern.
So there's actually been a couple of startups that are focusing on local speech to text.
So they are doing local listening.
And one that's recently come up and we've integrated and they actually contributed an integration to Home Assistant to integrate a system that looks very promising.
It's called Snips, Snips.ai.
They are a French startup and they're going to be their system is fully they're working on making it fully open source and it's already free to use on a Raspberry Pi.
But the idea is that they pretty much build like an Amazon Ego with like the way you configure it with like these are the sentences that I want to support.
But then they will run it completely locally on your device.
So there's no cloud connection.
And it also means that it's way faster.
Yeah, that's one of the drawbacks of a lot of these cloud things.
I mean, it's ridiculous.
Like I can ask my phone like, hey, Siri, what time is it?
And it will wait like five or 10 seconds and go, it's 2.30.
Why did it take you 10 seconds to know that it's 2.30?
Like this is not a huge challenge, man.
Do you think that's a transient situation that we're in or do you think this is a permanent thing?
Like is that just because the cloud is where the power is and it's moving to the devices?
Or is that like places like Google would rather have the data to learn from and to massively scale on rather than make it work at home?
I think there's multiple things in place.
One is definitely Google and Apple, et cetera.
They want to have your voice because they can see if they're training data, right?
And so the more voices they have, the better they can learn from.
But I think the biggest difference is actually is the way how these voice assistants work.
So the Amazon Ego has a very basic approach as in if you want to write a skill, a voice part for Amazon Ego to know to support like add something to my shopping list.
You have to register with Amazon every single sentence that the user can ever say.
So you have to say, you know, you can have like slots that will like be filled in with the actual word.
So you can have add item to my shopping list.
But then you have to add another sentence, add item to my shopping list instead of the shopping list.
And so you end up with like thousands of variations of your sentences.
But the way Amazon Ego, this allows them that once the speech to text has been done, they can very quickly map it to a sentence that you can say because there's only like, you know, 10,000 possibilities of all the different skills that are active on your device.
Right.
It's not wide open machine learning.
What did that person mean?
Sentiment analysis type of thing.
Right.
And so that's where Google is the Google home.
At least the way I think it works.
They do more speech to text and then like get the intent of the text, which is a different approach, which is way more difficult to actually push into the devices.
They're going to try, obviously, like, I mean, not per se Google, but like Apple's talking about like adding an AI chip.
And, you know, getting all these things to run locally just because of, you know, privacy is important.
Yeah.
Like you said, don't discount latency.
That's super annoying that it takes that long to get simple responses.
Okay.
So, yeah, these, I think you're right.
This is a really great way to interact with.
If you can interact with your home, there's some challenges like discovery, like what can you say to your home?
It's sometimes hard to know, right?
Yeah.
No, that's, I mean, the problem with a voice assistant is that because we're still in the beginning phase where we actually don't really understand.
what you're saying.
We have just hard coded every sentence that we expect.
So, you know, a lot of people call it artificial intelligence, but it's not really artificial intelligence yet.
And I think the whole idea of having a normal conversation is not there yet.
Once we haven't, we can like, kind of like, you know, as if you're talking to a person like, hey, what can you do?
And like, you know, it's easier to interrupt them, et cetera.
Then we can probably discover commands easier.
Right now it's, you know, we'll, Google Home has like an Alexa, both of like newsletters.
They email you like, did you know you can ask this?
Kind of things.
That's how we have to learn.
Right, right.
It's just a home, a smart speaker lesson every week.
Interesting.
Okay.
So let's get specific about home assistance.
So there's a number of, what would you think of this, like as a hub for a smart home?
Or how would you describe it?
Yeah, I would say it's a hub because the way I see a hub is that a hub is a device or a piece of software that speaks multiple languages and combines all these devices together and provides the user an interface or ways to control them.
Yeah, well, you spoke about the challenge of having to open your phone and open an app to do a thing rather than just hit the switch.
Well, there's an app for your plug.
There's an app for your lights.
There's an app for your garage door.
Like if you have got to like go to the 10 different apps because you want to do a thing, like then it gets super crazy.
So a home assistant will like speak the language of all these devices and give you one place to go, right?
Yeah.
And besides giving the user one place to go, it also means that it is one place for automations to run.
Because if you have two different vendors, two different products of vendors that don't speak together, that don't work together, they have their own apps, their own clouds,
then you will not be able to automate them without having like an intermediary that knows about both of them.
Right, for sure.
And so the motion sensor in a nest cannot be used to trigger a light being turned on or something like this.
Well, a home assistant knows about your light, knows about the nest and can combine these things.
Okay.
So it basically, it can receive, it does a couple of things.
It observes and monitors the state of many things.
And it also receives events or at least state changes, right?
Yeah.
So the way it works is that we have a state machine.
So home assistant, the architecture is that the core of home assistant is a event bus in which events related to your house are being fired.
And these are, for example, a button is pressed or motion is detected.
However, actually motion detect is a bad example because we represent that as a binary sensor because we can say motion is being detected.
Yeah.
And so the difference about something that happens right now and something that is happening is we want to, we have to capture it differently.
We cannot just have an event.
And so on top of the event bus, we have like a state machine and the state machine captures representations of devices in your house or other things.
So for example, in the state machine, you have a light and the light is the main state is on or off for a light.
And they have attributes that describe the state.
So for example, for light, this could be the color, the brightness, maybe the color temperature.
But for a media player, the state is, for example, passed or playing.
And the attributes could be what type of media is the TV show?
Is it a music album?
If it's a music album, what's the artist?
What's the song title?
What's the track number?
Et cetera.
Yeah.
And then whenever we change the state in the state machine, we will fire an event saying, hey, a state changed.
And so it actually changed from this to this.
And this allows other automations, for example, that can listen to either events or to state changes through the state changed event to kind of respond to whenever device representation changes in home assistance.
And we can start like automating things.
Yeah.
That sounds really, really, really useful.
So you start out with observing them and then you layer on state tracking.
And then at the home assistant level, you fire the event that, hey, the state has changed.
Anybody care about this thing?
Maybe they do.
Maybe they don't.
Things like that.
This portion of Talk Python to Me has been brought to you by Rollbar.
One of the frustrating things about being a developer is dealing with errors.
Relying on users to report errors, digging through log files, trying to debug issues, or getting millions of alerts just flooding your inbox and ruining your day.
With Rollbar's full stack error monitoring, you get the context, insight, and control you need to find and fix bugs faster.
Adding Rollbar to your Python app is as easy as pip install Rollbar.
You can start tracking production errors and deployments in eight minutes or less.
Are you considering self-hosting tools for security or compliance reasons?
Then you should really check out Rollbar's compliant SaaS option.
Get advanced security features and meet compliance without the hassle of self-hosting, including HIPAA, ISO 27001, Privacy Shield, and more.
They'd love to give you a demo.
Give Rollbar a try today.
Go to talkpython.fm/Rollbar and check them out.
So let's talk a little bit about how you built it, what technology is behind it.
It's Python-based, right?
Yes.
So it's Python-based.
It's Python 3.
It actually started out with Python 2.
I was still learning Python back then, and I just kept reading up on it.
And I was like, wait, there's also a Python 3.
And then I was looking more into it, and I was like, wait, Python 3 is the successor.
And, you know, everybody is moving to Python 3.
Even though four years ago, there was a lot more Python 3.
It was still up for debate at that point, yeah.
Yeah.
But, yeah, it's starting to look out like a good choice for you at this point, right?
Yeah.
But I was looking at, like, different things, and I was reading about, like, well, there's
no new features going to be added to Python 2, and Python 3 is being actively developed.
And I was like, I got to make the switch.
So I used, like, 2 to 3 tool, and I wrote it to Python 3.
I didn't really have any users anyway back then.
So I could do whatever I wanted.
Yeah, breaking changes were allowed.
It's fine, right?
Yeah.
And initially, it was actually all using threads.
So I used the thread pool, and we had, like, whenever you would register for listening to an event,
you would just register a function, and we would just pass that function and the event object to a thread pool.
It would execute in a thread and be done.
And this was actually caused sometimes, like, crazy deadlocks because, you know, there would
not be enough threads.
Some threads would be waiting for some work to be done, but that work would not be done because
there were too many threads waiting for work to be done.
It's a classic example.
Those are hard.
Yeah, those problems are hard to solve.
Yeah.
You know kind of what the problem is, but, like, tracing down the details can be painful.
Yeah.
Well, actually, the solution came by switching to AsyncIO.
So nowadays, and I think, yeah, last year, we spent, like, over a year converting to AsyncIO.
So I didn't know any AsyncIO, but there was this engineer from Mozilla, Ben Bangert, who was using AsyncIO at work.
And he stopped by, and he was using Home Assistant, and he was like, our minimum requirement at that point in time was already Python 3.4.
And he was like, if you're using Python 3.4, then AsyncIO is available.
And with AsyncIO, it will be faster.
There will be – we can avoid deadlocks, and it will be predictable.
Because of all the logs and the threads, it was actually at a very unpredictable execution order.
Sure.
And at this point, it's waiting right at the network level, right when it's talking to the device or waiting for a response or something like this, right?
Yeah.
With AsyncIO, you can just – you know, you pause within the work until you get, like, the next piece of information, and it can immediately execute.
Yeah, it's really a nice way to add concurrency, the concurrency you were looking for in the Python 3 world or just the Python world, because you kind of don't have to deal with the GIL very much at that point.
You don't have this thread overhead.
You don't have the deadlocks that come with it for the most part.
It's really nice.
Yeah, I think that once – when AsyncIO was introduced to me, you know, initially when Ben stopped by and he said, you should use AsyncIO, I was like, yeah, okay, great, but I don't know how.
And so, you know, you either come up with a PR or it's done, right?
Yeah.
And he actually delivered.
He came up with a pull request.
It was not fully done yet, but it was very exciting because I was actually learning something new in the Python world instead of, like, you know, every time I do a pull request against Home Assistant or code reviewing this, it was always, like, kind of the same kind of technologies.
And so this was something new.
And so we jumped on it and we managed to get the core converted to AsyncIO.
And then over, like, the course of, like, eight months, we've been converting more and more core pieces of Home Assistant to AsyncIO, to which point now we're fully AsyncIO.
Yeah, that's truly great.
Did that lower, like, the types of devices that could run on?
So before maybe it required, like, a PC, now it could run on, like, a small device or smaller devices than before?
So we always ran well on a Raspberry Pi.
So even though we had, like, tons of threads that did not, and the Raspberry Pi 3, at least, it was, like, running okay.
But right now with AsyncIO, we run, like, blazing fast.
So I think it allows us to even, like, allow for lower power devices to use those for Home Assistant.
Yeah, I'm sure it really does make that more accessible.
That's awesome.
So that's the AsyncIO stuff is obviously, like, how you talk to all the devices instead of threads.
What web framework are you using?
Let me just say what we used before, and then I'll, like...
So initially we started out with something I built myself on top of the standard library HTTP server, which is not a good idea, by the way.
But for me it was kind of, you know, I never built a web framework, and I was like, we actually only have one route, which is the serving up the single-page application.
So, you know, I'll just write something quickly myself, and then, of course, we needed more than one route, and then we needed SSL, and it became very messy.
You're like, oh, what have I done?
Yeah.
Well, for a long time, Home Assistant was my place where I was practicing, like, you know, writing sort of new technologies and et cetera.
And so this was kind of like, yeah, why not?
But then we actually migrated, or somebody actually submitted a PR to migrate us to WorkZook, which is a whiskey framework.
Yeah, part of Flask and all that, yeah?
Yeah, it powers Flask indeed.
And that was great.
And so we were using it on top of threads.
So we used the CherryPie whiskey server to power all of this.
And then we were migrating to AsyncIO, and so when we migrated to AsyncIO, I was like, well, we need a new web framework.
Yeah, because none of those do it.
Yeah.
No, so whiskey is not AsyncIO compatible.
The way it's set up is it's all threading.
And so people have explored seeing if they can make it Async compatible, and that's not possible.
But then I stumbled upon AOHTP, and it's very difficult not to stumble upon it because they pretty much wrote the request for AsyncIO.
So you cannot use requests either.
So you have to use AOHTP.
But it's a great, great library.
It's super fast.
It's actually powered by CITAN under the hood.
So a lot of them are executed in C.
And they did a great job.
They wrote both the client and the server, and they have a framework on top of that.
And so we were able to port our HTTP stack over to using AOHTP.
And because we use AsyncIO, it was actually very trivial for us to add WebSocket support, for example.
WebSocket support is an HTTP standard that starts as a normal request to your HTTP server,
but gets upgraded to become like a long-living connection that you can send messages back and forth.
Right.
Normally, it's message to the web server, response from the web server, done.
Yeah.
Yeah, this is very difficult in a threaded environment.
Because in a threaded environment, if you have like a worker per request,
then all of a sudden that one worker is going to be occupied forever.
And with AsyncIO, there's no such thing as the concept of a worker.
There's just like tasks that have pending work to be done.
So you can scale up way higher.
Yeah, absolutely.
I mean, that's kind of how Node.js got its, how it took off, like that type of programming model.
It's really cool to see it here in Python.
Yeah, and it's working very, very well for us.
I think that like because of AsyncIO and you know that there is no concurrency,
we actually managed to get rid of a lot of locks in our code.
And, you know, when you read from a dictionary and then like two commands later you write to a dictionary,
you know that no one else can mess with it.
Which is, you know, so also we're having less weird bugs because these things can just no longer happen.
Fewer Heisen bugs.
Yeah, so between the awaits, like you have control over it.
Very cool.
All right, so that sounds like such a fun project to be working on.
Are you looking for contributors and stuff like that?
We have a lot of contributors right now.
I think we do a release every two weeks.
And we have between 50 and 60 people contributing code every two weeks.
Wow.
That's really awesome.
Yeah.
So right now it's just like, you know, keeping up with the pull request is the biggest challenge.
Well, maybe you could have some contributors who just try to review the pull requests and just try to like mediate the bugs and feedback and things like that.
Yeah.
We have a few of those, but they are, you know, when you look at like open source contributors,
the people that will help and like the code review and these kind of things, they're rare compared to like the people that will just submit a pull request and get their feature in.
Yeah, of course.
Of course.
There's a lot of people who ask me like, hey, I want to get started in open source.
Like what's a project I could just do something simple in?
And so things like that, maybe if people are listening, they could come volunteer to review some pull requests or something.
Well, I mean, I think if you get into open source, like coming in as like doing some code review definitely helps.
But I think the best first step into open source is usually just making some contributions to the documentation.
Getting like, because that way you also learn the workflow of a project, seeing like who works there and like even who works on it.
And like even like if you hang out in the chat, you can like talk to them.
And once you know the project better, then like start submitting some features, which makes it a lot easier.
Just because in the end, like it's very difficult to, you know, get a pull request of somebody you've never spoken to who has like clearly put a lot of effort into a feature.
And then having to tell that person like this feature is, we're not going to merge this because it's not going to work for like these use cases that you did not think of.
Which if we would have spoken before for just like a minute or two, you know, I could have told you about this.
Yeah, that's a really interesting point.
It would be great if the whole GitFlow PR forking story had like a preliminary step before the work was done, before the PR was submitted.
Like, I'm thinking of this.
Prove my general idea, huh?
Well, yes and no.
Oh, because like sometimes you just, you're also doing it not per se for the project, but just for yourself to learn.
And then at the end, you're like, oh, maybe, maybe this is valuable for someone else.
Sure.
But as a, you know, for me as a maintainer, it's, it's important that like, you know, when I accept a pull request, I also accept responsibility.
Right?
Because like when home assistant breaks, they don't come knocking on the door of that one person who submitted a pull request that contained a bug.
No, they complain like in our chat room and in our forums on Twitter.
So, and then we have to put out a hot fix.
Which is, I'm sure, not fun.
No, it's not.
It's like, it's always hectic because you're like, okay, there's a lot of people angry.
Well, we have a fix.
Okay, good enough.
And then we have to like have all the tests run and then push it to PyPy, update the forums, update the release notes.
And it takes more work than, we've automated a lot, but still, it takes a lot of work.
Yeah, even if maybe like rolling back documentation or something, right?
Yeah, even reverse, it's like, becomes like a mess because you have like all these like, people that later want to like, revert the revert.
It's a mess.
I hear you.
Okay, so let's talk about some of the devices you support.
Let's go from the beginning.
In the beginning, you kind of created this for yourself and you supported the devices you had, right?
So where did it start?
So it started with the Philips Hue light bulbs.
So when they got released in the United States in, I guess, 2013.
And that's when I, maybe, no, I think somewhere in 2012, end of 2012, they got introduced and I bought them.
And I've been, since then I was playing with it.
But I was just writing simple scripts to like turn them on, turn them off.
Later, and it's slowly, that script, just for turning on and off, later, slowly has grown into Home Assistant.
Because then I wanted them to turn on when I came home, but then I didn't want them to turn on when I came home and the sun was up.
And so I have to keep track of more and more pieces of information.
But yeah, the second thing I integrated was the Chromecast.
So that's actually one of the best things I could have ever done because the Chromecast is really taken off.
And it's actually the Google Home.
It's also a Chromecast audio.
So when you start Home Assistant, it automatically detects your TV if you have a Chromecast there.
It will detect your Google Home, any other cast audio devices you have.
And then when you start playing music on your Google Home, it will actually immediately show like the album art inside Home Assistant.
You can pause and play it.
And they have a great protocol where they push every state update to us.
So the moment something happens on the Chromecast, we know about it in Home Assistant.
Right.
So there's not a latency of you pulling the thing or whatever.
Yeah.
Okay.
So that's really cool.
Those are some of the first two.
Now you have more than a handful, right?
Yeah.
So right now we have over like 740 or something devices.
And it just keeps growing.
There's a lot of devices.
Either very old ones like X10 support.
But there are also things of like there was a South African contributor who had some South African startup IoT device in his house.
And he wanted to integrate it.
And so, you know, he submitted a pull request.
And these are the kind of cases.
And this has been like since the beginning.
Getting pull requests for devices that I cannot verify.
It's always kind of like in the beginning I was like super scared.
It's like, what am I doing?
Like, how can I release to people code that like I haven't tested?
Like I have to trust this random person on the internet.
Not only have you not tested, you might be having to even really run it.
Yeah.
I mean, it's crazy, right?
Yeah.
Well, the way home assistant works, you know, I can verify in the code the way things get called to make sure that they don't do anything that goes against the design of the system.
We've actually also put a lot of like warnings in place.
And if certain fetching of certain things take too long, we'll print a warning.
But the reasoning why I decided to actually accept these kind of pull requests is that for a lot of people, it's way easier to fix a bug than to add support for something new.
So this one person might stop by and contribute support for like one version of a router, for example.
And then, you know, we have support for this one version and someone else stops by and actually sees a bug.
And that other person is super easy to just come in and fix one bug.
And then someone else stops by and is like, oh, if you support this version of the router, well, with very little work, we can add this version of the router.
And then, you know, it starts growing and growing.
And we've seen this with like various of our supported protocols and devices where it just keeps growing.
You almost get like many communities inside home assistant of like a few people who are rallying about the Sonos component or the Z-Wave component.
Right.
If their main passion is around the thing that they're integrating to home assistant, like they can form little sub communities around it, right?
Yeah.
Okay.
Yeah.
And I think this is the nice thing about home assistant is that there's a lot of open source software out there that you can't really use at home.
Right.
Because like there's some cool things like Kubernetes or like, I don't know, certain like web frameworks.
But who writes a website for their house?
Not too many people.
Right.
But if you want to at home and you want to play with things, the nice thing with home assistant is that it controls your house.
So there's immediate results.
And so there's immediate like, you know, satisfaction of your work.
This portion of Talk Pythonry is brought to you by us.
As many of you know, I have a growing set of courses to help you go from Python beginner to novice to Python expert.
And there are many more courses in the works.
So please consider Talk Python training for you and your team's training needs.
If you're just getting started, I've built a course to teach you Python the way professional developers learn by building applications.
Check out my Python jumpstart by building 10 apps at talkpython.fm/course.
Are you looking to start adding services to your app?
Try my brand new consuming HTTP services in Python.
You'll learn to work with RESTful HTTP services as well as SOAP, JSON, and XML data formats.
Do you want to launch an online business?
Well, Matt McKay and I built an entrepreneur's playbook with Python for Entrepreneurs.
This 16-hour course will teach you everything you need to launch your web-based business with Python.
And finally, there's a couple of new course announcements coming really soon.
So if you don't already have an account, be sure to create one at training.talkpython.fm to get notified.
And for all of you who have bought my courses, thank you so much.
It really, really helps support the show.
Yeah, and it's pretty low risk, right?
Because you can keep it behind your firewall on your router if you want.
And it's really sort of just for you.
Unlike a lot of the Internet of Things, they maybe have their own security issues.
I mean, yeah, there's a lot of Internet of Things companies starting up all the time.
And they put products out there.
And they have a limited amount of time, a limited amount of money.
So they will try to get to market super fast.
And security is sometimes like an afterthought.
Or after a couple of years, the company goes bankrupt.
And either the cloud shuts down, your device doesn't work anymore.
Or if the device works locally, it doesn't receive any security updates anymore.
Right, which is just a ticking time bomb.
But it's hard to know.
Like my router at home, it has its little light.
And it's green usually.
But if there's an update for it, it'll start blinking yellow.
Like, oh, maybe I should go look.
But I don't know that it's not receiving updates if it weren't anymore.
I just know when there is an update.
I don't know that it didn't check anymore.
You know what I mean?
And so it's really hard to kind of understand that.
But Home Assistant itself can run internally in your house.
In one of these Raspberry Pis, if you want, right?
Are there devices that you can get that's like a Home Assistant device?
Or do I have to get a Raspberry Pi and set it up?
Do I have to 3D print a thing?
Or what's the story about that?
Right now, we're just an open source project.
And so we don't have any devices.
We kind of focus on the Raspberry Pi.
From the statistics that we get, we see actually 70% of our users on Raspberry Pi.
But to make it easy, we're trying to slowly get to where we can either have Home Assistant devices or have a better experience.
So we're working on, we just released today actually, has.io, which is our new operating system for Raspberry Pis.
Yeah, that's a huge announcement.
This is like a brand new thing.
It's not just like, oh, here's some feature.
There's a whole new operating system for it.
Yeah, yeah.
So it's not a 100% operating system.
Like we built from the ground up.
We based it on a Raisin OS, which is an open source operating system to run Docker containers on embedded devices.
And so we use Docker and Raisin OS with SIO to allow a user to flash this to their Raspberry Pi and no longer have to worry about system updates or updating Home Assistant.
All these kind of things can be done from the user interface.
Yeah, that's awesome.
Yeah.
And so this is going to be our approach to kind of get the next so many users because right now our user base is very much, you know, do it with yourself, people, people that know programming, people that were comfortable enough to get a Raspberry Pi, open a terminal SSH into the Raspberry Pi, these kind of things.
Previously, like the setup story was SSH in there, create a virtual environment, pip install some requirements.
Like it was like that level, right?
And now with this announcement, Haas.io, like it's like a web interface that controls and configures and extends Home Assistant, right?
Yeah.
So right now you, once you download Haas.io, you flash it to an SD image and you write, you'll have to edit one text file on the SD image to have it connect to your Wi-Fi if you want.
But you can, of course, also plug in an Ethernet cable into your Raspberry Pi.
But the moment you start up your Raspberry Pi, it will download the latest version of Home Assistant.
It will update the operating system to the latest version.
And you're good to go.
Like after 20 minutes, more or less, it will start up Home Assistant.
Home Assistant will start automatically discovering which devices on your network that it knows how to set up automatically for you.
And you can start automating things.
Yeah, that's, that sounds really cool.
So that's, I'm sure that's going to increase adoption.
And you had said in the early days you wanted to kind of keep it to this techie crowd.
And it feels like this is a major step to like make it general consumer type stuff.
Yeah, it was.
So we used to like very much keep it focused on just the techie crowd because, you know, when something breaks, they can also contribute back.
But we were, we've grown so big now.
We have so much momentum that like, you know, it's a pity if we keep this away from other people as well.
So we want to have more people like exposed to it and more people using it.
And I think, you know, if you look at like the amount of integrations, we support so many things that, you know, we want to get more people on board and like even get more integrations and, you know, become like the ultimate home automation hub that you can run locally.
Yeah, that's awesome.
You have a lot more integrations than many of the, even the commercial ones, right?
Yes.
Yeah.
But that's actually, it kind of makes sense.
As in from the commercial ones, they probably have partnerships with those other companies.
They have, you know, they will test it every time there's one of those companies will update a new product.
They'll have to make sure it's integrated and those APIs have to stay stable.
And we have just like an unlimited size army because we're open source.
And so people will consume any API that's out there and integrate it into a home assistant.
And people are, you know, it's running in their house and they depend on it.
And so they see it's breaking or an update coming up, they will submit a patch to home assistant so that we are also, you know, we're always on the latest.
Always on the latest APIs and always getting better.
Yeah.
It's really a testament to the power of open source.
Like all these people, they have one device.
They have some technical skills.
They really want that one device to go in with the rest of their devices.
And so you can't do that at a commercial one.
You can just send them like a support request.
Please support this device sometime soon.
Yeah.
I like it to, you know.
Yeah, exactly.
And, you know, one other strategy that we've had since the beginning is that we've always made sure that whenever anyone contributed support for a device, that the support itself was actually contained in a standalone Python library that was published to PyPy.
That way, if you don't want to use home assistant but you still want to use that one device, you could still use that library and even end up maybe making improvements to that library or fixing bugs that we then also can consume inside home assistant.
Right.
And that's the way it's still set up now?
Like all these integrations are separate?
Yes.
Every, yeah.
Because if you look at other home automation, even open source ones, they have all this protocol logic inside their own code base.
And it's all coupled with their own way how they are doing things.
And so it makes it difficult to use that code for our project, for example.
Sure.
So what's the story of if I want to, suppose I get a device that's not supported, I want to add support through it.
Take me through the steps of like how do I add a new device to this?
Well, first you start reading the documentation.
For home assistant, right?
For home assistant, yeah.
No, I think the first step is to see if this device has an API.
Okay.
And this might either be a public API or if they have a mobile phone app, some people will use something like Wireshark or something to check out the protocol.
For most things out there, there will be someone who has already done this.
You can find like maybe there's a package for Node, maybe there's a package for Python already.
So actually for most things that you want to integrate, you'll find a library ready to go.
If you have to write one yourself, you'll have to like use those API dumps or their public API to talk to the device.
So once you have a library that can talk to the device, it will be very easy to integrate into home assistant.
So anything that you want to integrate into home assistant is actually based on classes.
So we have, for example, a switch class.
And so you would just extend the switch class.
And then we use the Python properties, class properties.
So you have a property name where you return the name of your device.
You have a property is on that will return a Boolean if the switch is on or off.
And then you have two functions, turn on and turn off.
And if you implement those to fire the correct commands to your device, they're already in.
That's it.
Yeah.
That's awesome.
And all the, to integrate a device, you only have to integrate this class and all the things under the hood,
how like the state machine has the representation and the event bus, all those things you don't have to worry about.
Those things are abstracted away.
They work with your, yeah, they work with your abstract base classes and you don't care.
Yeah.
Nice.
Do you have like multiple inheritance, like something is a switch and it's color adjustable or something like this?
No.
So we, the abstract base class of a switch will have, well, color adjustable would mean that like it's actually a light.
So the switch will have features that are not supported by every device that implements an abstract base class of the switch.
And so we have this property called supported features, which is using like integer bit flags to say which features are supported or not.
And that's actually not being used inside home assistant Python, the core, because if you call turn on and you can pass in the color, it's up to the implementation.
You know, they can just decide not to use the color.
Right.
But the front end will, you know, we have a web interface to control everything.
And the front end, for example, for light that does not support colors will not show a color picker.
Right.
Okay.
Cool.
Yeah.
That makes a lot of sense.
So that sounds pretty easy.
If you can talk to the API, you can implement a couple of methods on an abstract base class.
Like it doesn't get a whole lot easier, right?
I think for like a sensor, if you want to add like a sensor, which is a read only piece of information that you want to pull into home assistant, you can do that in like 20 lines.
Sure.
Wow.
Yeah.
So that's hopefully that's encouraging people to go and integrate something maybe that isn't in that 740 devices.
Yeah.
If people are interested in like adding things to home assistant, I gave a talk at PyCon in Portland last year, 2016, about like, first it describes how home assistant works.
And then the last 20 minutes is how I'm writing a sensor and a switch from scratch that actually interact with the file system as a demo.
Okay.
Yeah.
So check that out if you want to get started.
That's really cool.
So I saw that you have kiosk mode.
What is that?
Yeah.
So actually recently, well, it's not recently.
It's been for a while now.
People, because they invest so heavily in home assistant, so they have home assistant like controlling everything in their house.
And they ended up installing home assistant on tablets and having those tablets being mounted to walls at the entrance of their house or like somewhere else in the house.
And so people were like, you know, the normal home assistant user interface is not optimized for being on a tablet on a wall, which is where you expect like big buttons.
We are, our user interface is optimized for mobile phones.
And so you have, you know, it looks like material design.
You have like the small toggles that you need like a finger and like you need to be close to like, you know, you need some form of precision.
And so for the wall mounts, people are like, well, we need a better approach.
And so we have support for custom panels in home assistant.
So people were writing pages that would already show like bigger buttons or show like a whole floor plan of the house and show like where in the house, which lights are on and which doors are open.
But the kiosk mode now will actually take it one step further.
We'll make sure that the bar on the top is hidden and that the menu is no longer can be opened.
And that way you really have just like a terminal that like controls parts of your house and people cannot like go to the settings and start changing things.
Yeah, that sounds really cool, actually.
So like that's your public one.
And if you really want to change it, you pull it up on your laptop or something.
Yeah.
Okay.
Well, that makes a ton of sense.
So I was thinking of the things that I could automate in my house when I was getting ready to talk to you.
And to be honest, I don't really have many smart things other than like my phone and my laptop and my kids phones and whatnot.
We do have on our doors, we have a keypad entry for all the doors.
So we don't use keys, but they're not they don't have Bluetooth or anything.
They're just literally like a keypad.
But one thing that I am getting is I'm getting an electric car and it has one of those 240 volt charging units.
And that thing has like an app and it has wireless connectivity.
Like, do you integrate with those types of things?
Do you know?
Or is that a PR I should be adding?
That's probably a PR.
I mean, we have well, we have support for Volvo.
So Volvo has like an app for their cars where you can see where the car is.
And I think you can see the mileage and how much gas you have left.
And we actually integrate home.
The home system has support for Volvo.
So you can like see everything in Volvo.
So depending on the make and model of your car, there might be already.
Yeah.
So I'm thinking of getting a Bolt.
I mean, I would love to get a Tesla, but you know, I'd also love a Ferrari.
Like I can wear things.
No, of course.
I don't think we have support for a Volt yet.
But if they have an API that is either accessible or even public accessible, then it should be very straightforward to add support for it.
Awesome.
Well, maybe I'll do some kind of PR for you.
Because, yeah, it's supposed to have like I don't have it yet.
So I don't know, but it's supposed to like go on the Wi-Fi and talk to your app and like warm it up before you go outside.
Like things like that.
Wow.
Well, I think there's this, you know, there will be also like nice things to do.
Like, for example, reminders to charge it, for example.
Like, hey, you were running low when you came home, but you didn't plug it in.
Yeah.
Yeah, for sure.
It's I know it's on the Wi-Fi and it's low.
So you better go pay it at some attention or something like that.
Right.
Yeah.
Awesome.
All right.
Well, that sounds really, really cool.
So let's talk about just a few other things.
We're getting short on time here.
You have just recently started a full on home assistant podcast.
Why don't you tell people what that is, what it's about, how they can like subscribe to you?
Yeah.
So this is three of our community members started this project.
And they it's all about home assistant and things around home assistant that are happening in the IoT space.
We are at episode four or five now.
I think episode four was just launched.
Yeah, I think so.
Yeah.
And it's all about each episode.
They try to invite other members of the community that are either doing very cool stuff with home assistant.
So I think the last episode there was Carlo who has automated his whole house with Alexa and home assistant to control everything.
Where even like if he lives in Florida, so if he left his door open for too long, text to speech, the house would say to everybody inside, oh, there's a door open.
So I'm going to turn off the air conditioning now.
Good luck.
I was there on episode three.
And so they keep talking to other members that are like developing the latest, greatest features for home assistant and kind of like thinks how to use it.
And it's getting quite some popularity.
I think the first episode had like 2,500 listeners or something.
That's amazing for the first episode.
Yeah, that's awesome.
So it's really great.
If people are interested, the URL has podcast.io.
But every episode is also promoted on our blog and Twitter.
Right.
Yeah.
And I subscribe to it.
I just went to Overcast and I typed home assistant and boom, home assistant podcast came straight up.
So yeah, that always works as well.
I'm sure it's on Google Play in addition to that.
Cool.
All right.
So that's really awesome.
And you guys have t-shirts.
Is that right?
Yes.
If I want to automate my home and then like get people to ask me questions about it.
Yeah.
So we've been selling t-shirts since I guess somewhere in the beginning of the year.
Maybe a bit around the time, I think.
Yeah.
And the t-shirts we have right now, 100% of the profits are being donated to the Electronic Frontier Foundation.
That makes it easier for us to not have any, to do anything with like income and taxes and all that stuff.
You know, we also support the Electronic Frontier Foundation, which they're doing awesome work.
Among others, they provide, they started the Let's Encrypt service so that everybody can have an SSL certificate, which a lot of home assistant users are using.
Yeah.
With your house.io, that's like a checkbox or something, right?
Yeah.
We make it super easy to get an SSL certificate to secure your connection to your house.
That's cool.
Yeah.
Very, very cool.
All right.
Well, it's super exciting.
I need a smart thing so I can start playing with home assistant.
Maybe more than one.
I would start with just a Chromecast for television.
Okay.
Because the nice thing about the Chromecast is that it doesn't have a dedicated app that you need to control.
The Chromecast is built into the Netflix app, the Spotify app.
Let's say your browser, you open YouTube and all of a sudden it has a button, play on my TV.
Yeah.
In your phone, it will be like, show my screen on the TV.
Show my photos on the TV.
It's a very powerful little device.
And it's like very cheap.
I think it's like 35 bucks.
Yeah.
It's incredibly cheap for what it is.
Yeah.
Sounds very cool.
All right.
That's a great place for people to get started.
All right, Paulus.
Before I let you out here, let me ask you the two questions we always ask at the end of the show.
One, if you're going to write some Python code, what editor do you open up?
I use Sublime Text.
Okay.
Sublime.
Definitely a good choice.
It's very fast.
And it doesn't do too much, but it does enough.
Sure.
Yeah, absolutely.
That's cool.
And you've got quite a few lists to pick from, like maybe 741 at least.
But how about a notable PyPI package?
Well, actually, I mean, I was thinking about this question before the show started, like what's one that I really like?
And actually, it's one that's now part of the – I really like AsyncIO.
And I know it's now part of the standard library, but I think that asynchronous programming sounds so magical.
But if you actually start looking at the source code, it's super, super straightforward.
It's just like it has a list of tasks.
It has every task.
Do you have something to do?
Okay, do it.
And then it just keeps – it's pretty much like a while through.
And it just keeps going through this list of work.
And the fact that it gets to the basic – it's so basic from the core.
And it, like, makes such a powerful paradigm possible is just amazing.
Yeah, that's a really interesting point about how that simple paradigm really opens things up.
And, you know, even like you said, simplifies, removes a whole class of bugs for you guys.
Awesome.
All right, so final call to action.
People are interested in this.
What do they do?
Get a Raspberry Pi, get a hash.io, and just get up and running.
And then there's some great documentation.
We've got some great videos how to get started.
And if you run into any trouble, make sure to stop by our Discord.
It's our chat community.
And it's where a lot of people hang out.
They're helping out other people to get started and discuss home automation.
All right.
Sounds great.
I'm looking forward to playing around with it.
Paul, thanks for being on the show.
It was great to chat with you and share your story.
Yeah, it was awesome being here.
Thank you.
This has been another episode of Talk Python to Me.
Today's guest was Paulus Shralson.
And this episode has been brought to you by Rollbar and Talk Python Training.
Rollbar takes the pain out of errors.
They give you the context and insight you need to quickly locate and fix errors that might have
gone unnoticed until your users complain, of course.
As Talk Python to Me listeners, track a ridiculous number of errors for free at rollbar.com slash
Talk Python to Me.
Are you or a colleague trying to learn Python?
Have you tried books and videos that just left you bored by covering topics point by point?
Well, check out my online course, Python Jumpstart, by building 10 apps at talkpython.fm slash
course to experience a more engaging way to learn Python.
And if you're looking for something a little more advanced, try my Write Pythonic code course
at talkpython.fm/pythonic.
Be sure to subscribe to the show.
Open your favorite podcatcher and search for Python.
We should be right at the top.
You can also find the iTunes feed at /itunes, Google Play feed at /play, and
direct RSS feed at /rss on talkpython.fm.
Our theme music is Developers, Developers, Developers by Corey Smith, who goes by Smix.
Corey just recently started selling his tracks on iTunes, so I recommend you check it out at
talkpython.fm/music.
You can browse his tracks he has for sale on iTunes and listen to the full-length version
of the theme song.
This is your host, Michael Kennedy.
Thanks so much for listening.
I really appreciate it.
Smix, let's get out of here.
Stay tuned.
Bye.
Rock the best.
First developers.
Developers, developers, developers, developers.
you
Thank you.