Summary
Don’t you wish you could make all of your devices talk to each other? Check out Home Assistant, the Python 3 platform for unified automation. Paulus Schoutsen shares the story of how the project got started, what makes it tick, and how you can use it today!
Introduction
- Hello and welcome to Podcast.__init__, the podcast about Python and the people who make it great.
- I would like to thank everyone who has donated to the show. Your contributions help us make the show sustainable.
- When you’re ready to launch your next project you’ll need somewhere to deploy it. Check out Linode at linode.com/podcastinit and get a $20 credit to try out their fast and reliable Linux virtual servers for running your awesome app.
- Visit our site to subscribe to our show, sign up for our newsletter, read the show notes, and get in touch.
- To help other people find the show you can leave a review on iTunes, or Google Play Music, and tell your friends and co-workers
- Join our community! Visit discourse.pythonpodcast.com for your opportunity to find out about upcoming guests, suggest questions, and propose show ideas.
- Your host as usual is Tobias Macey and today I’m interviewing Paulus Schoutsen about Home Assistant, the Python 3 platform for unifying your home automation.
Interview
- Introductions
- How did you get introduced to Python?
- What is Home Assistant and what was the initial frustration that inspired you to create it?
- How useful would home assistant be for someone who doesn’t have a lot of the so-called ‘smart home’ technology?
- Given the fact that the intended context for Home Assistant is in the user’s house or apartment, how do you ensure that their data and privacy are safe?
- Reading through the documenation for installing and configuring Home Assitant, it seems prohibitively complex for someone who is not technically inclined. Has any work been done to try to package the project in a way that is more friendly to a casual user?
- What are some of the most difficult challenges that you have faced while building Home Assistant?
- Why did you choose Python 3 as the technology for building this platform?
- The list of supported services and integrations is quite impressive. How does the current architecture allow for that kind of growth?
- How has the architecture of Home Assistant evolved from when you first started it?
- What are some of the products or platforms that you consider to be competitors of Home Assistant and how do you differentiate yourself?
- What are some of the most interesting or unexpected uses of Home Assistant that you have seen?
- What do you see as some of the most promising and the most troubling trends in the future of home automation?
Keep In Touch
Picks
- Tobias
- Paulus
- Read a Newspaper
Links
- Mycroft
- Let’s Encrypt
- Voluptuous
- JSON-Schema
- Home Assistant PyCon Presentation
- asyncio
- Open HAB
- Merai Botnet
The intro and outro music is from Requiem for a Fish The Freak Fandango Orchestra / CC BY-SA
[00:00:14]
Unknown:
Hello, and welcome to podcast dot in it, the podcast about Python and the people who make it great. I would like to thank everyone who has donated to the show. Your contributions help us make the show sustainable. When you're ready to launch your next project, you'll need somewhere to deploy it, so you should check out linode@linode.com slash podcast init and get a $20 credit to try out their fast and reliable Linux virtual servers for running your app or trying out a project you hear about on the show. You You can visit the site at www.podcastinnit.com to subscribe to the show, sign up for the newsletter, read the show notes, and get in touch. And to help other people find the show, you can leave review on Itunes or Google Play Music, tell your friends and coworkers, and share it on social media. Your host as usual is Tobias Macy, and today I'm interviewing Paulus Houtzen about Home Assistant, the Python 3 platform for unifying your home automation. So, Paulus, could you please introduce yourself?
[00:00:57] Unknown:
Yeah. So my name is Paulus I'm a software engineer living in San Diego, and I'm the the lead of, the open source project Home Assistant, Python 3 project that is, all about home automation to observe, control, and automate your things in your house.
[00:01:15] Unknown:
And how did you first get introduced to Python?
[00:01:17] Unknown:
I got first introduced to Python in in college. I was just, you know, looking into new languages, trying out different things, and then came across Python. I liked it. Used it for a few projects, you know, just at school. And I was trying out some web stuff because I was always interested in the web. And then I think Google App Engine, they got, support for Python. So that was, like, a reason for me to, like, you know, play a bit more and try some web stuff with it.
[00:01:41] Unknown:
So could you share a bit about what Home Assistant is and what the initial frustration was that led you to create it? Yeah. So Home Assistant is
[00:01:50] Unknown:
a framework that can integrate anything. So it can integrate lights, switches, anything in your house. It's just like providing data, but it's not per se limited to anything in your house. It also can read data from Twitter, your calendar, just anything that has data, comes together with Home Assistant. And then Home Assistant will process the data, show it to you nicely in a user interface. It allows you to write automation on top of it. So a person coming home can trigger that the light's being turned on, for example. I started riding it like 3, 3 and a half years ago, I think now, when the Philips Hue lights came out. So when the Philips Hue lights came out, I was like, this is amazing. Smart lights. So I bought them right away and, somebody reverse engineered the API in Python. And so I was playing with it and I was like, man, it would be awesome if the lights go on if the sun is setting. So I found like a Python library to track the sun, set up a simple timer, and when the sun was setting, bam, turn on the lights. But then I slowly started to realize, like, wait, that's when I'm not at home, the lights are being turned on now. And so, okay. Well, I guess I have to look into presence detection. And then I was like, well, actually, if the lights are being turned on at sunset, that's actually too late because the when the sun is setting, we're already losing light. And so you actually want the lights to, like, come fade in or be turned on like earlier. And so I just kept iterating on this, also kept learning, more and more Python along the way. And eventually, it became a framework which is now Home Assistant.
[00:03:21] Unknown:
And it sounds a lot like some of the things that a virtual or AI assistant can help with similar to a lot of the things that are coming out with Google's HomeKit and, the Amazon Alexa. And then also other Python projects like the Mycroft project that I had an interview about a little while back. So I'm wondering what sort of integration you have with those kinds of platforms or what the sort of intersection is or overlap between Home Assistant and what they can provide.
[00:03:49] Unknown:
So there's actually, like, there's some overlap where, like, the so I see those, devices mainly as, like, a voice interface. And so the main part is a voice interface where they can interpret your voice and convert it to commands. And then, you know, to make that voice interface more attractive, they've been integrating more and more home automation things and shopping lists and music players. And and I think it's a natural extension for Home Assistant. Like, it's not something that we aim to provide. We really aim at providing a a place where all your devices get integrated so we know how to read them read the data and control them and provide an animation layer on top. But, you know, we integrate with, the Google Home and, the Amazon Alexa. So we allow users to just turn on or turn off any, device in your house through these voice interfaces. And also for Amazon Echo, we have support for people to create their own skills, and then you can virtually do anything. So you can have any voice commands be tied to any command inside home assistance. And I think it's also these kind of interfaces is kind of like the future of, of home automation for a certain part. Because a lot of people, you know, they are super, like, excited because they get, like, smart, smart devices in their houses. But they don't realize that a lot of the things that a smart device offers is actually more cumbersome than normally. So for example, if you are entering your house and you can no longer use your light switch, but you have to get your phone out of your pocket, you're actually losing time. Like, this smart light has not, like, saves you anything. With voice interfaces, on the other hand, anytime you, like, walk by, you don't have to get your phone out of your pocket. You can, like, command it to do things in your house. So for example, you can ask, hey. Send my wife a message because I'm running late. Or and so these kind of voice extensions really help bringing home automation actually to a level that it's usable for most people.
[00:05:43] Unknown:
Yeah. I was looking through the documentation a bit and noticing that even though I don't have a number of the different, quote, unquote, smart home products, that there were still some capabilities built into home assistant that I would find particularly useful, especially around the presence capabilities in terms of, 1 of the examples saying, you know, you can send yourself a text message at a certain time of day to remind you to go home because I know that as a developer, I can often find myself deep down into a problem and then look up and realize that I'm 15 or 20 minutes late from when I wanted to leave. Or, also occasionally, I'll leave work and forget to send a message to my wife that I'm on my way home. And so being able to automate that and not have to think about it would be particularly useful. And I noticed that those are some of the examples you have in the documentation. But in general, for somebody who, like myself, doesn't have a lot of the different smart home technologies, how useful in general would Home Assistant be? And, I guess, what are some of the best use cases for Home Assistant both with and without that technology?
[00:06:41] Unknown:
So I think where Home Assistant really shines is the automation. So you're pretty much can automate anything. So 1 thing, like, you mentioned is, like, presence detection. So if you wanna, you know, I think the 1 thing that happens a lot is, like, people have zones. So, geofencing on a map. So when you enter certain areas, you can have automation trigger that you enter or leave a zone. The example you just mentioned, like, uses time combined with that. But I mean, you can like if you want to get notified, for example, when certain things are being said, like are being added to your calendar or there's a lot of data that we pull in from different services. And, you know, it's also very easy to extend to integrate more services.
So I think people added, like, for example, who's playing which game on Steam. And so you could, for example, get a notification when 1 of your friends is playing a certain game that you are that you wanna play with this, person, for example.
[00:07:37] Unknown:
And given the fairly capable automation utilities that you've got built into home assisted, assisted. Where do you see the dividing line between something like that and some of the more work oriented automation platforms? Something in terms of something like SaltStack or, any of these sort of cloud automation capabilities? Because it seems like there's some potential overlap there as well.
[00:07:58] Unknown:
I think that there is definitely a lot of overlap with, these services. I think the the major differentiator is that Home Assistant is run locally in your house. So you don't have to share any of your information with any cloud or any third party. So all the data enters your house, and only certain data will leave if you decide to, like, send a notification about it, for example. But in the end, you know, it's it's very similar, except that we have to besides because we also run locally, we're also able to include, devices that we communicate locally over, so instead of via the cloud. So for example, the the Z Wave home automation protocol, by integrating with it locally, we get super fast response times. And, the super fast response times are necessary, for example, for things like motion detectors. If you want to start recording when motion is detected, if it goes to the cloud and end up with a 5 second delay, you might miss the important part.
[00:08:56] Unknown:
Yeah. And 1 of the things that you touched on as well is the fact that it is running locally or at least intended to be so is the privacy factor. So because of the fact that Home Assistant is intended to be used in people's place of residence and interacting with a lot of the different services that can potentially collect and own a lot of data about people's habits. How do you ensure that there is appropriate data and privacy controls in place to prevent, intrusion or leaking of that privileged data?
[00:09:26] Unknown:
Well, I mean, when we the Home Assistant itself doesn't, deal too much with, like, how the data is stored. We have by default, it stores things in a SQLite database, but you can choose to, you know, store it in MySQL, for example, or any other SQL related database, then password protected using crypto tablespaces, these kind of things. When it comes to, like, you know, the only thing that Home Assistant exposes to the world is, the web interface. The web interface itself does not contain any we make sure that we not have any option for people to run, like, arbitrary, like, shell commands or something like this. But we don't do any, encryption out of the box. This is mainly also to get it, like, easier to set up because, and also do like 1 thing and do 1 thing well. So with web services, it's very common that you run the web service locally, but you have, for example, Nginx in front of it to provide a layer of authentication or encryption. For actually SSL, we do have it built in. So we have an extensive guide how to use Let's Encrypt to get a free SSL certificate. And we also actually talk about privacy. We work with the people of Tor to get home assistant exposed as it's possible to be exposed as like a a Tor surface so that it gets a special Tor address and you can only access it using the Tor browser. But these are all things that you kind of like build on top of Home Assistant.
[00:10:41] Unknown:
Yeah. I can definitely appreciate the desire to not pull SSL encryption into it out of the box because if you are just using it at your home and you're not exposing it for access outside of that, then there's not a great need to have SSL enabled. I mean, it certainly wouldn't hurt, but it's not, it's not as necessary as if you were to be using the web interface from somewhere outside of your home network.
[00:11:04] Unknown:
Well, actually, that's not completely true because, a lot of the latest, standards on the web, like service workers and voice API, those are require for you to have, the website to be served over an encrypted connection. So Home Assistant, leverages a lot of these web technologies to make sure that, loading is very fast. So like it stores the whole web application offline on your phone. But we can only do this if, the page is served over a secure connection.
[00:11:34] Unknown:
Well, given the fact that it's using those more recent technologies, it sounds like it would also require some of the more modern browsers. So what, what are some of the browsers that it supports? Or I guess what are the oldest browsers that it supports?
[00:11:46] Unknown:
Let me just live check this because I'm, so we we use promises. So we have, I think that's the oldest technology that I love to to to be that's kind of like on the edge. So we, we we support all the modern browsers. So this is, Microsoft Edge, Firefox, Chrome, and Safari. I try to, like, not use too many modern technologies. And if we do, we transpile them back to to the older technologies. This is all front end, related. But most modern browsers will, will work with home assistants. I know that some, for example, some older iPhones, they no longer get updates, are stuck with the older Safari, which will not work. But if you use Chrome or Firefox or Microsoft Edge, you should be all good.
[00:12:29] Unknown:
And touching again on the sort of broad capabilities of Home Assistant, do you often see it used in a sort of office or business context?
[00:12:40] Unknown:
Not well, not locally. Like, not myself or any of my friends, but I've seen, like I think in New Zealand, there was a group of farmers that was working on farm assistance. So they used it to keep track of, like, the level of, I don't know, chemicals in their tanks and, like, what the temperature was. I know that there was someone in Colorado who was, using it to monitor, the marijuana growing and see, like, how the plants were doing and use those as a security system. But I think that a lot of the more the big office spaces, they they they are like commercial equivalents of Home Assistant. And then you get, like, the support and everything works nicely out of the box. So I don't think it will be too useful for office spaces.
[00:13:24] Unknown:
So when I was reading through the documentation to get ready for the show, I noticed that installing and configuring Home Assistant, while it's not as difficult as a number of projects I've looked at, it does seem somewhat prohibitively complex for somebody who isn't very technically inclined. So I'm wondering if there has been or if there is any work planned to be done to try to package the project in a way that makes it more friendly to a casual user, maybe just maybe even as a Raspberry Pi image or something like that?
[00:13:48] Unknown:
Well, so we actually do have a Raspberry Pi image that comes, pre installed with Home Assistant. But, I mean, just getting it on a Raspberry Pi is not the most difficult part. I think that, you know, the challenge with Home Assistant is to get it, like, configured the way you want to be. The only way to configure it right now is a text interface. So So we have text configuration files. For a long time, this was intentional, because by making it a little steep to use, you make sure that the people that are using home assistance are all technically inclined. Also, when they find a bug, they can easily fix it. And, like, it was my focus on this group, we were able to attract a lot of contributors, started moving pretty fast.
Beginning of last year, we're like, okay, we wanna get, you know, we want to make it easier for people to use. But because our integrations are constantly being added and growing, it was like, well, where do we start? You know, the easiest would be to make an online text editor that edits the config files, but, you know, then we would still focus on that more technical capable group. And so we started using, this Python library called Voluptius. It's a data validation library. And through this, library, every integration was able to express how much like, what kind of data and what format and, it needed. And, like, if it was a file, validate the file exchange. If it was a number, make sure the numbers are within certain ranges, etcetera.
This took a long time because I think we had a couple of people work on it for a couple of months just to get it added to every integration. And right now, it's also enforced on every new integration that gets added to the platform. So now that we have this data validation in place, the ideas are there's no 1 committed to it yet, but is to read in these validations from Voluptuous, convert it to something like JSON schema, for example, which is a standard for, JSON data validation. And then there are several projects available that will automatically create forms that look nice with, like, inputs and, like, drop downs for the front end for the browser. So the long term planning is, yes, we want to get to a configuration panel, but we had to get to a place where this could be done by people building their own integrations and will automatically generate a config because having a standalone configuration project that is aware of every integration would not be a maintainable solution.
[00:16:09] Unknown:
Yeah. Particularly given the fact that there is such disparity in the standards and protocols and sort of data formats used by all of these different home automation technologies and all of the other web services that can be tied into them. So touching on that, what are some of the most difficult challenges that you faced while building Home assistant?
[00:16:29] Unknown:
I think the biggest challenge when it comes to home automation is that even if you think for something as simple as a switch, it's not simple when it comes to home automation. Because there will be different vendors that, have different, like, you know, implementations of a switch. So for example, there's the the WEMO inside switch, which can measure how much, voltage is being used by the product. And then it has, like, a different, like, threshold than if the device is using less than the threshold that it, like, is measuring. Then instead of saying that the switch is off or on, it will say the switch is in standby because the product that's attached to the switch is in standby. So now all of a sudden, the switch is not no longer a binary thing. It's something that has 3 states. Besides even just like expressing the the state of something, it has like every product matches different things with different attributes. There will be switches that measure how much voltage is being used. Others will express it as like kilowatts and hours. And just the challenge is to, like, how are we all standardizing this? Because as a Home Assistant, to be able to allow a generic interface to any switch, we have to decide this is how we want the switch to be. This is what a switch is. And then every integration has to kind of, like, fit into the switch, format that we, that we make available, and then it'll just work. But mapping all the time, you know, different products on, like, a generic class can be very tricky. I mean, the switch is still relatively easy. But when it comes to thermostats, we had an integration of the thermostat or, like, just something that well, I kind of like winged it. Like, I didn't have any experience with thermostats. So we just created a base class with thermostats.
But then, you know, somebody introduced like, well, I've got an air conditioner. Is it also a thermostat? And we're like, well, you know, it's not it has a thermostat, but it can also act on it. And so in the end, we we had a for a while, we had a air conditioner integration as a standalone thermostat, but then late last year, we decided to merge it. And, like, now we have a climate component. But these kind of things were, like, you don't know what the device is like, how the device just because you know what device are available today doesn't mean that you know what kind of devices will be there tomorrow in this category. So how are you gonna model it that you support everything from today till tomorrow till forever? And I think another challenge that also relates to this is that, testing. So when I just started Home Assistant, every integration we had was because I owned that device. But then, like, at some day, I was still pretty new to open source. Like, I got this pool request. Somebody found it and wanted to add support for, some device that I didn't have. And this is like, you know, I had to make this choice at that point in time. It's like, okay, well, I cannot test that this code works. I mean, I can look at it. I can see that it could work, and I can verify that it's synthetically correct. I just don't know if the integration with this device works. But that's where I was like, the only way forward is to accept these things.
And if it is broken, it's always easier for a developer to fix something that's broken than to start from scratch. So I just accepted it, and actually it worked well for like a year or something. And then at some point, something broke, and another developer fixed it. And this happened more and more and more integrations where, like, you know, people come in and say, I want to add this integration. Like, okay, something breaks or, you know, the developer that creates integration is only 1 type of switch, but there are 5 different types of switches for that vendor. And so someone else has a different switch of the vendor, and they enhances the platform. And so it just keeps growing.
[00:19:59] Unknown:
Yeah. It's definitely difficult to figure out how to design and evolve a framework like that because of the fact that there are so many different integration points. And as you said, testing, particularly hardware integration, is 1 of the more difficult forms of testing because unit testing, you know what the expected inputs and outputs are. But when you're dealing with a hardware device or a software interface that you don't have the documentation or the equipment to actually run the tests against then you're like you said, you you have to put your faith in the people who contributed it.
[00:20:30] Unknown:
Yeah. And so although we decided, you know, we're not writing any tests for integrations, we do make sure that, like, the core of Home Assistant and the more the bigger integrations, are all 100% test covered. So that's like, you know, at least when you're writing the integration, you can be guaranteed that the things you're interfacing with are working.
[00:20:51] Unknown:
Yeah. Given the fact that you have been able to evolve the project to incorporate all these different platforms, it must have a fairly flexible architecture. So it seems that it was at least designed pretty well upfront in that respect despite the fact that there is such movement and evolution in terms of the actual interfaces that are being plugged into it. So I don't know if you can dig a bit into what that architecture looks like and maybe some of the interfaces that are exposed for people to write plugins against.
[00:21:18] Unknown:
Yeah. So the interface, the architecture actually the the data types that we have in Home Assistant actually have not changed since the beginning. I don't know if this was, like, insight from my part or just a lucky shot, but we have 2 different data types. It's kind of like everything evolves around. The first 1 is an event. An event name can be anything arbitrary, and attached to an event are attributes, which is just a dictionary with a key value, of data. On top of the event, are states. So every well, not states, I must say entity. And so an entity has a state. And so a state is something like if you would like observe a light, that's you observe the current state of a light. And so for example, for a light, every state is organized around like the core string that describes the state and then it has extra attributes that, like, tell you more about the state. So if you look at a light, it's either on or off. And then if you look at, like, extra attributes, the light that is on might have a certain color. It might have a certain brightness. And so everything in the homo system revolves around states and events. So whenever a state changes of an entity, we will fire an event, state changed. So if you wanna if if your piece of code wants to stay, in the loop whenever an entity is changing, you just have to listen to the event. You don't even have ever have to interact with the the states. They will just be handed to you when it's ready. And on top of these, of this core are are components.
And so components provide an abstraction layer on top of home assistant, and have create, like, an abstract base class for what that component, entails. So for example, the light component will create a an abstract base class. It represents an entity that is a light, and it has a few things that integration has to implement. So for example, for light, you have to implement the a property is on, the method turn on, and the method turn off. If you can implement these 3 things, then you can implement the light for Home Assistant. And so when you're writing something like the Philips Hue integration, you would import this abstract base class of light. You would import the Philips Hue library to communicate with, the lights, and then you just pretty much map them. So you fetch all the lights, and for each light, you add a a light to the to the system. And then automations, which are mainly configured through, text files, they will based on the text files, it will just listen for certain events on the event bus. And when these events happen, it will call some, some code or service.
[00:23:49] Unknown:
And what does that event bus look like? Are you using something like 0MQ or RabbitMQ or something like that? Or is it something that's just being implemented in memory in pure Python?
[00:23:59] Unknown:
It's just, pure Python in memory. Initially, I had it very much modeled after Java, because that's what I was most familiar with at that point in time in the beginning. But now, I mean, it's it's just very simple, a dictionary with event type and then a list of functions that get called whenever that event happens.
[00:24:18] Unknown:
So what kind of an event loop are you using to be able to process those events as they come in? And, have you ever run into any sort of scaling issues because of being flooded with too many events? Or I guess what is the processing loop look like for that? So, when I initially wrote it, I wrote it with a bunch of threats and with,
[00:24:37] Unknown:
with logs. And then the the system would run. So every second, we fire, like, a time change event. So this is how the system moves forward. So everything is always driven by events. So there is, it's either outside signals or an event that can cause a change to the system. And so it used to be that, like, whenever a time change event happens, I would say, okay, it's been 5 o'clock. And then and now it's 1 second after 5. So we fire a time change event every second. Then there will be listeners, for example, the light, the Philips Hue lights, they do not report the state, but we have to, like, fetch the state from time to time. And so the light component defaults to, like, check-in with Philips Hue, like, every 20 seconds. So the light component, who is aware of the Philips Hue lights, will listen to the event bus when does the time change and when the time is like, oh, 20 seconds has elapsed. Okay. Now let me ask the Philips Hue lights for their state and then write this to the state machine. Then if the states have changed, these will fire state change events and the event bus has listeners. And so these listeners are just, so like I said before, are functions. And so it would just add put this into the thread pool. So the word we would have, like, 10 or 20 threads running. We're just waiting for jobs to be added to the queue. And whenever a job is happened, came in, it would contain of the event object and of the event handler and the thread we just call this. And so this was the, the old architecture was, we had a very unpredictable execution pattern. So once if you fire an event that the 2 threats, you would never know well, it was a queue. So you know which 1 would start executing faster, but you wouldn't know which 1 would hit the lock faster.
And so we had a few logs in the core of the system. And this also could result in a deadlock sometimes, which will be very, very tough to debug. So late last not late last year. I think in the summer of last year, Ben Bangert joined the Home Assistant, and he's done a lot of work with asynchronous programming in Python. And so he was like, wait, Home Assistant's minimum supported version is Python 3.4, which is also the minimum version that introduces asyncio. Why are we not gonna try to, like, convert this to asyncio? So I wasn't myself, I didn't know much asyncio, but I started learning it pretty quickly. And so together with Ben, we rewrote the core to be completely asynchronous. We were able to put a to keep the old API intact as like a kind of like a service layer on top of the asynchronous core so all the components just could keep working. So now what is happening is that because everything is asynchronous, there are no longer threads fighting for logs. But, instead, there's 1 thread that just list all the jobs in sequence, and jobs will be able to suspend itself whenever they're waiting for input, output. So now the asyncio event loop is what is pushing our, system.
[00:27:31] Unknown:
And have you noticed any drop in the resource requirements since the switch to async IO from threads?
[00:27:38] Unknown:
Oh, yeah. A lot. So when we were using threads, I kind of had this like weird algorithm. It's like, okay, if we add like another integration, we're going to add another thread to our pool because kind of was like the idea was like, Python has the global interpreter lock. So more threats is not better, especially if you exhaust your cores. But if they're doing IO and they're waiting for the network, then it could actually speed it up. So if you add your Philips Hue, we add another thread. If you add like your z wave sensors, we would add another thread. So people would end up with, like, 40, 50 threads sometimes, which, you know, that completely swamps the Raspberry Pi, especially if they're all, like, trying to acquire locks. So now they say, hey, yo, we still have a thread pool, but it's only 5 or 10 threads, actually. I don't know exactly, which is only to support the legacy, legacy components.
But most components have been, especially the automation, they have all been converted to asyncio. So, like, we we start up like it used to be like a startup of Home Assistant could take like 10 seconds. That's now down to like 2 or 3 depending, of course, on your configuration as well. But it's and also the, the web server. It used to use a threaded web server, from Cherry Pie, cherry pie whiskey, server. But that 1 only had 10 handlers. So it means that only, 10 people could be simultaneously visiting your site, the Home Assistant UI, because we also have a stream that is always active. So 1 work always has to be active. And so now with ACKL, you can have thousands of people at your home assistant instance at the same time. Not a very common use case, but it's actually something that we tested last December. There's this YouTube channel called Bra Automation. They make they make a lot of videos about how to use Home Assistant.
And Ben, who runs this channel, he set up his Christmas tree at home to be controllable by home assistant, which he publicly, exposed. And then he had, like, a webcam on his Christmas tree so that people could, like, in Home Assistant, change, the settings of his Christmas tree, and then on the webcam could see his Christmas tree, change.
[00:29:44] Unknown:
I think I saw that actually. Maybe I was seeing something else, but it was an IPV 6 enabled Christmas tree. Yeah. Okay. That could have been it. What are some of the products or platforms that you consider to be competitors of Home Assistant? And how do you differentiate yourself from that perceived competition?
[00:30:00] Unknown:
So if I look at, like, the biggest competitor will be open HAB. This is a home automation, framework written in Java. They've been around for a long, long time. They actually had their, 2.0 released today, which is great because they released a bunch of awesome features that will heat up the competition 2 frameworks. Yeah. I think how do we differentiate ourselves is 1 is being written in Python. The other thing is that, like, because we're written in Python, we're a bit more flexible with our core interaction with 1 another. So we are, homosystyns based on a lot of conventions of, like, how do you describe the brightness of a light? This is, you know, typed. The key is just brightness as a string, for example. And so it's because of its, a lot more convention over, like, strict rules, it's easier to develop for Home And I think because it's easy to develop, we also do more frequent releases to get all this work out. So right now, Home Assistant is on a 2 week release schedule. And so every 2 weeks, there's like a bunch of changes coming out. And so every and because we release every 2 weeks, it forces us to, as a project, like, okay, we have to get all the documentation in shape. We have to, like, make sure that things are bug free and then get everything aligned, and then we can publish a new version. So I think our main differentiator is speed and easy to develop for.
[00:31:16] Unknown:
Were those some of the reasons that you chose Python initially for the project, or were there other motivating factors?
[00:31:22] Unknown:
At that time, it was like I was, playing with Python at work as well. I was like, I wanna play more with it. And now after 3 years of doing a lot of Python development, I don't think I would pick any other language anymore. But back in the days, it was more luck than, anything else.
[00:31:39] Unknown:
And when you did choose Python, was there why did what made you choose Python 3 rather than deciding to try and support Python 2?
[00:31:47] Unknown:
Well, so actually, I didn't. So I started out in Python 2.7. It was mainly because, like, I was researching online and, like, you know, all the tutorials, all the websites, you always learn about, like, Python 2.7. But as I, like, as Home Assistant was, like, in the beginning phases, I was also using I was reading up like what are Python best practices and these kind of things. And I was learning about PAP 8 and how to test your project and these kind of things. And at some point, I stumbled upon like, you know, Python 3. I knew about it but I always like ignored it because the websites, Some websites said, like, don't use it, etcetera. And so at some point, I was like, wait a second. Python 3 sounds like it's better than Python 2. Like so I started reading about it, like, what is the difference and what are pros and cons? And the other thing that, like, pretty much made the deal like, made me decide I'm going to go for Python 3 was that you know, Python 2 is gonna be end of life. There is no there's not gonna be any Python 2.8. And so, yes, it's gonna be tougher with, like, libraries, but eventually, it will all catch up. And I wasn't, like, such a good Python programmer that I could like to both do both Python 2 and do Python 3. So I was like, I'm the only user. I don't care. So I went for Python 3. Then I pretty much ended up with Python 3.4 as minimum version because I did some I used some functions to, load Python files on demand because Home Assistant doesn't load all the integrations that we currently have. Whenever you start Home Assistant, it, like, loads integrations on demand. And if those require certain, Python dependencies, we'll actually use PIP to install those dependencies, on the fly. So we ended up with Python 3.4, which for a long time was actually pretty annoying because Debian Stable, didn't have Python 3.4. So anyone on the Raspberry Pi that wanted to use Home Assistant had to compile Python themselves. But now, I think somewhere last year, Debbie and Jesse got released with Python, 3.4, available. And that is, like, that is great for new users.
[00:33:46] Unknown:
You touched on a couple of examples earlier on, but what are some of the most interesting or unexpected uses of Home Assistant that you've seen?
[00:33:53] Unknown:
So 1 of the I mean, 1 of the things that I do, which I like is that, you know, I live, like, 4 stories high and so I have like a zone of like a mile around my house. It's like a geo fencing zone. So that's when I when I enable this automation and I enter the area of, like, getting close to my house, it will send a message to my wife being like, Paulus is on its way. Better go down now. In case, like and it's only, of course, when I'm, like, picking her up to, like, go to a restaurant, for example. So otherwise, I would have to, like, text and drive or I would have to wait downstairs. But I mean, there's, like, people that, like, will track their kids go to work.
There are people that optimize growing their marijuana. I thought the Christmas tree was really cool. But yeah, there's just so many things. We have somebody now added support for license plates, which I think is very cool. So you can have, like, a camera, recording, like, in the front of your house. And then, like, when somebody parks in front of your house, it can detect if there's a car on the picture and if there's, like, a license plate. And then, like, if it's a certain license plate, you can get notified. We're actually enhancing this now. So we have, we now have a pull request open to also feed our images to the Microsoft face recognition API so you can see if there's, like, a certain person knocking on your door, for example.
[00:35:13] Unknown:
Yeah. That sounds similar to the product I did for my senior year of college where we were actually using Python and the simple CV library to use an IP camera to detect whether or not there is somebody at your front porch, and then, send an alert to an Android app to notify you of that fact. And then record video of the next, you know, 30 seconds or so to so you could see who came and what they were doing. But having something like home assistant sounds like it would have been made by life a lot easier.
[00:35:40] Unknown:
I bet.
[00:35:42] Unknown:
So given that you're working in the space of home automation and dealing with of these smart devices, what do you see as some of the most promising and potentially some of the most troubling trends in the future of home automation?
[00:35:53] Unknown:
So I think the the the biggest troubling trend is that, like, people don't really or, like, not people, companies, are not really focusing on security, but instead of focusing on time to market. I think Qualcomm put out a research that 70% of all the IoT products will be produced by like, they were produced last year, are being put in the market by companies that are, like, less than 5 years old. So when you buy such a product, you don't know if it's gonna be supported in the future. And every time they find, like, a fly, like some SSL library or something else, a potential that your, device might be compromising. This actually happened now recently, with a lot of IP cameras. So, like, the cheaper IP cameras that you can buy, they have known weaknesses. And so when you connect them to the Internet, it's like so people wrote, like, whole blog posts about it. Like, within 90 seconds, there were 2 different, like, hackers entering his IP camera and installing, like, worms. And so you saw even the, the bigger DDoS attacks last year where all their botnets are now IP cameras because, you know, people connect their IP cameras to the cloud. They have no insight what is going on inside their cameras. And, you know, it's a camera, so you make sure that it is connected to a good Internet connection because that's the uploaded stream. But it means it's also perfect weapon to bring websites down. So I think a troubling concern is just the focus on security. There should be more focus on security.
I think it would definitely help if there's more standardized platforms that people can build on top of. But it seems right now that a lot of, companies, they, you know, they they install some bare bones Linux, and they get it working, and then they just ship it. What I think that, like, some cool innovations come into home automation is that we're gonna probably see more smarter integration. So right now, setting up an automation is still, like, cumbersome. Like, you have to see, you know, you have to see 1st, you have to find something that you wanna automate, and then the automation also has to be a 100% right. Because if you have an automation at like 20% of the times, it's like not what you want. You have to open your phone to like turn a light off. It was accidentally turned on or the other way around. You get an audio. You turn off your automation. I think the cheaper like processing power becomes that you can have in your home, the better you can start analyzing the data that, like, a system like Home Assistant is gathering. And we should be able to, like, derive automation rules based on your usage patterns of, like, when are you home, which room are you in, which device are you using, how are you using these devices, and what can we do to help? So for example, if we notice that you always turn on the heating and turn on these lights or some close these curtains when you get home, well, maybe we can suggest that we do this automatically for you.
[00:38:32] Unknown:
So for anybody who wants to get involved in the project, what are some of the things that you're most in need of help with?
[00:38:40] Unknown:
I think our biggest need right now is actually not too much Python related. It's, we have also a lot of documentation, but we don't have, like, a good coherent story of, like, you know, if you want to get started, these are the exact steps. And, you know, the the problem we have is that everybody has, like, different devices, etcetera. And so I've been having this plan in my head where I wanna, like, kind of revolve a website around, like, how to get started on the Raspberry Pi because I think it's the most common and most accessible low end computing device that people can, acquire right now. And so, I mean, if if the thing where we need most help is just getting the documentation and probably we got a bunch of spelling mistakes too because most of our documentation writers, including myself, we're not native English speakers. So, you know, we just wing it. But when it comes to, like, the the Python side of things, it's just like we we always try to, like, improve, like, the experience for the users. And so this is where, like, you know, the configuration UI, these kind of things is like what's gonna be on the roadmap for this year, I hope. And so that's also where, we could use some help.
[00:39:42] Unknown:
So are there any other topics that you think we should cover before we close out the show? No. I don't think so. Alright. So for anybody who wants to get in touch with you or follow what you're up to, I'll have you send me your preferred contact information, and I'll put that in the show notes. And with that, I'll bring us to the picks. My pick for today is a movie I watched recently called miss Peregrine's Home For Peculiar Children. And it was just a really interesting fantasy kind of story that was just very visually appealing and just a very well done storyline. Pretty intriguing. So definitely recommend taking a look at that. It was very well done. And with that, I'll pass it to you. Do you have any picks for us today, Palos?
[00:40:20] Unknown:
I don't really have, like, a specific pick. According to my wife, my movie taste is horrible, so I'll not recommend anything there. I could just recommend, like, read newspapers. I think, nowadays, too many people get their news from things like Facebook or Twitter, and that's probably not the best place to get your news.
[00:40:38] Unknown:
It's a it's a good PSA. Alright. Well, I appreciate you taking the time out of your day to tell me about Home Assistant. I'm sure that a number of listeners will be pretty interested, and we'll start checking it out right away. I've definitely seen a few uses for it myself, so I'm sure I'll probably be installing it so I can experiment with some of the location capabilities of it. So I appreciate that, and I hope you enjoy the rest of your night. Yeah. Thank you. And I think so we have a pretty active
[00:41:02] Unknown:
chat community, host on Gitter. So if people want to get started with Home Assistant and they run into trouble, make sure to check out our chat room and our forum for help. People are generally very helpful. Well, thank you again and I hope you enjoy the rest of your evening. Yeah. Thank you.
Hello, and welcome to podcast dot in it, the podcast about Python and the people who make it great. I would like to thank everyone who has donated to the show. Your contributions help us make the show sustainable. When you're ready to launch your next project, you'll need somewhere to deploy it, so you should check out linode@linode.com slash podcast init and get a $20 credit to try out their fast and reliable Linux virtual servers for running your app or trying out a project you hear about on the show. You You can visit the site at www.podcastinnit.com to subscribe to the show, sign up for the newsletter, read the show notes, and get in touch. And to help other people find the show, you can leave review on Itunes or Google Play Music, tell your friends and coworkers, and share it on social media. Your host as usual is Tobias Macy, and today I'm interviewing Paulus Houtzen about Home Assistant, the Python 3 platform for unifying your home automation. So, Paulus, could you please introduce yourself?
[00:00:57] Unknown:
Yeah. So my name is Paulus I'm a software engineer living in San Diego, and I'm the the lead of, the open source project Home Assistant, Python 3 project that is, all about home automation to observe, control, and automate your things in your house.
[00:01:15] Unknown:
And how did you first get introduced to Python?
[00:01:17] Unknown:
I got first introduced to Python in in college. I was just, you know, looking into new languages, trying out different things, and then came across Python. I liked it. Used it for a few projects, you know, just at school. And I was trying out some web stuff because I was always interested in the web. And then I think Google App Engine, they got, support for Python. So that was, like, a reason for me to, like, you know, play a bit more and try some web stuff with it.
[00:01:41] Unknown:
So could you share a bit about what Home Assistant is and what the initial frustration was that led you to create it? Yeah. So Home Assistant is
[00:01:50] Unknown:
a framework that can integrate anything. So it can integrate lights, switches, anything in your house. It's just like providing data, but it's not per se limited to anything in your house. It also can read data from Twitter, your calendar, just anything that has data, comes together with Home Assistant. And then Home Assistant will process the data, show it to you nicely in a user interface. It allows you to write automation on top of it. So a person coming home can trigger that the light's being turned on, for example. I started riding it like 3, 3 and a half years ago, I think now, when the Philips Hue lights came out. So when the Philips Hue lights came out, I was like, this is amazing. Smart lights. So I bought them right away and, somebody reverse engineered the API in Python. And so I was playing with it and I was like, man, it would be awesome if the lights go on if the sun is setting. So I found like a Python library to track the sun, set up a simple timer, and when the sun was setting, bam, turn on the lights. But then I slowly started to realize, like, wait, that's when I'm not at home, the lights are being turned on now. And so, okay. Well, I guess I have to look into presence detection. And then I was like, well, actually, if the lights are being turned on at sunset, that's actually too late because the when the sun is setting, we're already losing light. And so you actually want the lights to, like, come fade in or be turned on like earlier. And so I just kept iterating on this, also kept learning, more and more Python along the way. And eventually, it became a framework which is now Home Assistant.
[00:03:21] Unknown:
And it sounds a lot like some of the things that a virtual or AI assistant can help with similar to a lot of the things that are coming out with Google's HomeKit and, the Amazon Alexa. And then also other Python projects like the Mycroft project that I had an interview about a little while back. So I'm wondering what sort of integration you have with those kinds of platforms or what the sort of intersection is or overlap between Home Assistant and what they can provide.
[00:03:49] Unknown:
So there's actually, like, there's some overlap where, like, the so I see those, devices mainly as, like, a voice interface. And so the main part is a voice interface where they can interpret your voice and convert it to commands. And then, you know, to make that voice interface more attractive, they've been integrating more and more home automation things and shopping lists and music players. And and I think it's a natural extension for Home Assistant. Like, it's not something that we aim to provide. We really aim at providing a a place where all your devices get integrated so we know how to read them read the data and control them and provide an animation layer on top. But, you know, we integrate with, the Google Home and, the Amazon Alexa. So we allow users to just turn on or turn off any, device in your house through these voice interfaces. And also for Amazon Echo, we have support for people to create their own skills, and then you can virtually do anything. So you can have any voice commands be tied to any command inside home assistance. And I think it's also these kind of interfaces is kind of like the future of, of home automation for a certain part. Because a lot of people, you know, they are super, like, excited because they get, like, smart, smart devices in their houses. But they don't realize that a lot of the things that a smart device offers is actually more cumbersome than normally. So for example, if you are entering your house and you can no longer use your light switch, but you have to get your phone out of your pocket, you're actually losing time. Like, this smart light has not, like, saves you anything. With voice interfaces, on the other hand, anytime you, like, walk by, you don't have to get your phone out of your pocket. You can, like, command it to do things in your house. So for example, you can ask, hey. Send my wife a message because I'm running late. Or and so these kind of voice extensions really help bringing home automation actually to a level that it's usable for most people.
[00:05:43] Unknown:
Yeah. I was looking through the documentation a bit and noticing that even though I don't have a number of the different, quote, unquote, smart home products, that there were still some capabilities built into home assistant that I would find particularly useful, especially around the presence capabilities in terms of, 1 of the examples saying, you know, you can send yourself a text message at a certain time of day to remind you to go home because I know that as a developer, I can often find myself deep down into a problem and then look up and realize that I'm 15 or 20 minutes late from when I wanted to leave. Or, also occasionally, I'll leave work and forget to send a message to my wife that I'm on my way home. And so being able to automate that and not have to think about it would be particularly useful. And I noticed that those are some of the examples you have in the documentation. But in general, for somebody who, like myself, doesn't have a lot of the different smart home technologies, how useful in general would Home Assistant be? And, I guess, what are some of the best use cases for Home Assistant both with and without that technology?
[00:06:41] Unknown:
So I think where Home Assistant really shines is the automation. So you're pretty much can automate anything. So 1 thing, like, you mentioned is, like, presence detection. So if you wanna, you know, I think the 1 thing that happens a lot is, like, people have zones. So, geofencing on a map. So when you enter certain areas, you can have automation trigger that you enter or leave a zone. The example you just mentioned, like, uses time combined with that. But I mean, you can like if you want to get notified, for example, when certain things are being said, like are being added to your calendar or there's a lot of data that we pull in from different services. And, you know, it's also very easy to extend to integrate more services.
So I think people added, like, for example, who's playing which game on Steam. And so you could, for example, get a notification when 1 of your friends is playing a certain game that you are that you wanna play with this, person, for example.
[00:07:37] Unknown:
And given the fairly capable automation utilities that you've got built into home assisted, assisted. Where do you see the dividing line between something like that and some of the more work oriented automation platforms? Something in terms of something like SaltStack or, any of these sort of cloud automation capabilities? Because it seems like there's some potential overlap there as well.
[00:07:58] Unknown:
I think that there is definitely a lot of overlap with, these services. I think the the major differentiator is that Home Assistant is run locally in your house. So you don't have to share any of your information with any cloud or any third party. So all the data enters your house, and only certain data will leave if you decide to, like, send a notification about it, for example. But in the end, you know, it's it's very similar, except that we have to besides because we also run locally, we're also able to include, devices that we communicate locally over, so instead of via the cloud. So for example, the the Z Wave home automation protocol, by integrating with it locally, we get super fast response times. And, the super fast response times are necessary, for example, for things like motion detectors. If you want to start recording when motion is detected, if it goes to the cloud and end up with a 5 second delay, you might miss the important part.
[00:08:56] Unknown:
Yeah. And 1 of the things that you touched on as well is the fact that it is running locally or at least intended to be so is the privacy factor. So because of the fact that Home Assistant is intended to be used in people's place of residence and interacting with a lot of the different services that can potentially collect and own a lot of data about people's habits. How do you ensure that there is appropriate data and privacy controls in place to prevent, intrusion or leaking of that privileged data?
[00:09:26] Unknown:
Well, I mean, when we the Home Assistant itself doesn't, deal too much with, like, how the data is stored. We have by default, it stores things in a SQLite database, but you can choose to, you know, store it in MySQL, for example, or any other SQL related database, then password protected using crypto tablespaces, these kind of things. When it comes to, like, you know, the only thing that Home Assistant exposes to the world is, the web interface. The web interface itself does not contain any we make sure that we not have any option for people to run, like, arbitrary, like, shell commands or something like this. But we don't do any, encryption out of the box. This is mainly also to get it, like, easier to set up because, and also do like 1 thing and do 1 thing well. So with web services, it's very common that you run the web service locally, but you have, for example, Nginx in front of it to provide a layer of authentication or encryption. For actually SSL, we do have it built in. So we have an extensive guide how to use Let's Encrypt to get a free SSL certificate. And we also actually talk about privacy. We work with the people of Tor to get home assistant exposed as it's possible to be exposed as like a a Tor surface so that it gets a special Tor address and you can only access it using the Tor browser. But these are all things that you kind of like build on top of Home Assistant.
[00:10:41] Unknown:
Yeah. I can definitely appreciate the desire to not pull SSL encryption into it out of the box because if you are just using it at your home and you're not exposing it for access outside of that, then there's not a great need to have SSL enabled. I mean, it certainly wouldn't hurt, but it's not, it's not as necessary as if you were to be using the web interface from somewhere outside of your home network.
[00:11:04] Unknown:
Well, actually, that's not completely true because, a lot of the latest, standards on the web, like service workers and voice API, those are require for you to have, the website to be served over an encrypted connection. So Home Assistant, leverages a lot of these web technologies to make sure that, loading is very fast. So like it stores the whole web application offline on your phone. But we can only do this if, the page is served over a secure connection.
[00:11:34] Unknown:
Well, given the fact that it's using those more recent technologies, it sounds like it would also require some of the more modern browsers. So what, what are some of the browsers that it supports? Or I guess what are the oldest browsers that it supports?
[00:11:46] Unknown:
Let me just live check this because I'm, so we we use promises. So we have, I think that's the oldest technology that I love to to to be that's kind of like on the edge. So we, we we support all the modern browsers. So this is, Microsoft Edge, Firefox, Chrome, and Safari. I try to, like, not use too many modern technologies. And if we do, we transpile them back to to the older technologies. This is all front end, related. But most modern browsers will, will work with home assistants. I know that some, for example, some older iPhones, they no longer get updates, are stuck with the older Safari, which will not work. But if you use Chrome or Firefox or Microsoft Edge, you should be all good.
[00:12:29] Unknown:
And touching again on the sort of broad capabilities of Home Assistant, do you often see it used in a sort of office or business context?
[00:12:40] Unknown:
Not well, not locally. Like, not myself or any of my friends, but I've seen, like I think in New Zealand, there was a group of farmers that was working on farm assistance. So they used it to keep track of, like, the level of, I don't know, chemicals in their tanks and, like, what the temperature was. I know that there was someone in Colorado who was, using it to monitor, the marijuana growing and see, like, how the plants were doing and use those as a security system. But I think that a lot of the more the big office spaces, they they they are like commercial equivalents of Home Assistant. And then you get, like, the support and everything works nicely out of the box. So I don't think it will be too useful for office spaces.
[00:13:24] Unknown:
So when I was reading through the documentation to get ready for the show, I noticed that installing and configuring Home Assistant, while it's not as difficult as a number of projects I've looked at, it does seem somewhat prohibitively complex for somebody who isn't very technically inclined. So I'm wondering if there has been or if there is any work planned to be done to try to package the project in a way that makes it more friendly to a casual user, maybe just maybe even as a Raspberry Pi image or something like that?
[00:13:48] Unknown:
Well, so we actually do have a Raspberry Pi image that comes, pre installed with Home Assistant. But, I mean, just getting it on a Raspberry Pi is not the most difficult part. I think that, you know, the challenge with Home Assistant is to get it, like, configured the way you want to be. The only way to configure it right now is a text interface. So So we have text configuration files. For a long time, this was intentional, because by making it a little steep to use, you make sure that the people that are using home assistance are all technically inclined. Also, when they find a bug, they can easily fix it. And, like, it was my focus on this group, we were able to attract a lot of contributors, started moving pretty fast.
Beginning of last year, we're like, okay, we wanna get, you know, we want to make it easier for people to use. But because our integrations are constantly being added and growing, it was like, well, where do we start? You know, the easiest would be to make an online text editor that edits the config files, but, you know, then we would still focus on that more technical capable group. And so we started using, this Python library called Voluptius. It's a data validation library. And through this, library, every integration was able to express how much like, what kind of data and what format and, it needed. And, like, if it was a file, validate the file exchange. If it was a number, make sure the numbers are within certain ranges, etcetera.
This took a long time because I think we had a couple of people work on it for a couple of months just to get it added to every integration. And right now, it's also enforced on every new integration that gets added to the platform. So now that we have this data validation in place, the ideas are there's no 1 committed to it yet, but is to read in these validations from Voluptuous, convert it to something like JSON schema, for example, which is a standard for, JSON data validation. And then there are several projects available that will automatically create forms that look nice with, like, inputs and, like, drop downs for the front end for the browser. So the long term planning is, yes, we want to get to a configuration panel, but we had to get to a place where this could be done by people building their own integrations and will automatically generate a config because having a standalone configuration project that is aware of every integration would not be a maintainable solution.
[00:16:09] Unknown:
Yeah. Particularly given the fact that there is such disparity in the standards and protocols and sort of data formats used by all of these different home automation technologies and all of the other web services that can be tied into them. So touching on that, what are some of the most difficult challenges that you faced while building Home assistant?
[00:16:29] Unknown:
I think the biggest challenge when it comes to home automation is that even if you think for something as simple as a switch, it's not simple when it comes to home automation. Because there will be different vendors that, have different, like, you know, implementations of a switch. So for example, there's the the WEMO inside switch, which can measure how much, voltage is being used by the product. And then it has, like, a different, like, threshold than if the device is using less than the threshold that it, like, is measuring. Then instead of saying that the switch is off or on, it will say the switch is in standby because the product that's attached to the switch is in standby. So now all of a sudden, the switch is not no longer a binary thing. It's something that has 3 states. Besides even just like expressing the the state of something, it has like every product matches different things with different attributes. There will be switches that measure how much voltage is being used. Others will express it as like kilowatts and hours. And just the challenge is to, like, how are we all standardizing this? Because as a Home Assistant, to be able to allow a generic interface to any switch, we have to decide this is how we want the switch to be. This is what a switch is. And then every integration has to kind of, like, fit into the switch, format that we, that we make available, and then it'll just work. But mapping all the time, you know, different products on, like, a generic class can be very tricky. I mean, the switch is still relatively easy. But when it comes to thermostats, we had an integration of the thermostat or, like, just something that well, I kind of like winged it. Like, I didn't have any experience with thermostats. So we just created a base class with thermostats.
But then, you know, somebody introduced like, well, I've got an air conditioner. Is it also a thermostat? And we're like, well, you know, it's not it has a thermostat, but it can also act on it. And so in the end, we we had a for a while, we had a air conditioner integration as a standalone thermostat, but then late last year, we decided to merge it. And, like, now we have a climate component. But these kind of things were, like, you don't know what the device is like, how the device just because you know what device are available today doesn't mean that you know what kind of devices will be there tomorrow in this category. So how are you gonna model it that you support everything from today till tomorrow till forever? And I think another challenge that also relates to this is that, testing. So when I just started Home Assistant, every integration we had was because I owned that device. But then, like, at some day, I was still pretty new to open source. Like, I got this pool request. Somebody found it and wanted to add support for, some device that I didn't have. And this is like, you know, I had to make this choice at that point in time. It's like, okay, well, I cannot test that this code works. I mean, I can look at it. I can see that it could work, and I can verify that it's synthetically correct. I just don't know if the integration with this device works. But that's where I was like, the only way forward is to accept these things.
And if it is broken, it's always easier for a developer to fix something that's broken than to start from scratch. So I just accepted it, and actually it worked well for like a year or something. And then at some point, something broke, and another developer fixed it. And this happened more and more and more integrations where, like, you know, people come in and say, I want to add this integration. Like, okay, something breaks or, you know, the developer that creates integration is only 1 type of switch, but there are 5 different types of switches for that vendor. And so someone else has a different switch of the vendor, and they enhances the platform. And so it just keeps growing.
[00:19:59] Unknown:
Yeah. It's definitely difficult to figure out how to design and evolve a framework like that because of the fact that there are so many different integration points. And as you said, testing, particularly hardware integration, is 1 of the more difficult forms of testing because unit testing, you know what the expected inputs and outputs are. But when you're dealing with a hardware device or a software interface that you don't have the documentation or the equipment to actually run the tests against then you're like you said, you you have to put your faith in the people who contributed it.
[00:20:30] Unknown:
Yeah. And so although we decided, you know, we're not writing any tests for integrations, we do make sure that, like, the core of Home Assistant and the more the bigger integrations, are all 100% test covered. So that's like, you know, at least when you're writing the integration, you can be guaranteed that the things you're interfacing with are working.
[00:20:51] Unknown:
Yeah. Given the fact that you have been able to evolve the project to incorporate all these different platforms, it must have a fairly flexible architecture. So it seems that it was at least designed pretty well upfront in that respect despite the fact that there is such movement and evolution in terms of the actual interfaces that are being plugged into it. So I don't know if you can dig a bit into what that architecture looks like and maybe some of the interfaces that are exposed for people to write plugins against.
[00:21:18] Unknown:
Yeah. So the interface, the architecture actually the the data types that we have in Home Assistant actually have not changed since the beginning. I don't know if this was, like, insight from my part or just a lucky shot, but we have 2 different data types. It's kind of like everything evolves around. The first 1 is an event. An event name can be anything arbitrary, and attached to an event are attributes, which is just a dictionary with a key value, of data. On top of the event, are states. So every well, not states, I must say entity. And so an entity has a state. And so a state is something like if you would like observe a light, that's you observe the current state of a light. And so for example, for a light, every state is organized around like the core string that describes the state and then it has extra attributes that, like, tell you more about the state. So if you look at a light, it's either on or off. And then if you look at, like, extra attributes, the light that is on might have a certain color. It might have a certain brightness. And so everything in the homo system revolves around states and events. So whenever a state changes of an entity, we will fire an event, state changed. So if you wanna if if your piece of code wants to stay, in the loop whenever an entity is changing, you just have to listen to the event. You don't even have ever have to interact with the the states. They will just be handed to you when it's ready. And on top of these, of this core are are components.
And so components provide an abstraction layer on top of home assistant, and have create, like, an abstract base class for what that component, entails. So for example, the light component will create a an abstract base class. It represents an entity that is a light, and it has a few things that integration has to implement. So for example, for light, you have to implement the a property is on, the method turn on, and the method turn off. If you can implement these 3 things, then you can implement the light for Home Assistant. And so when you're writing something like the Philips Hue integration, you would import this abstract base class of light. You would import the Philips Hue library to communicate with, the lights, and then you just pretty much map them. So you fetch all the lights, and for each light, you add a a light to the to the system. And then automations, which are mainly configured through, text files, they will based on the text files, it will just listen for certain events on the event bus. And when these events happen, it will call some, some code or service.
[00:23:49] Unknown:
And what does that event bus look like? Are you using something like 0MQ or RabbitMQ or something like that? Or is it something that's just being implemented in memory in pure Python?
[00:23:59] Unknown:
It's just, pure Python in memory. Initially, I had it very much modeled after Java, because that's what I was most familiar with at that point in time in the beginning. But now, I mean, it's it's just very simple, a dictionary with event type and then a list of functions that get called whenever that event happens.
[00:24:18] Unknown:
So what kind of an event loop are you using to be able to process those events as they come in? And, have you ever run into any sort of scaling issues because of being flooded with too many events? Or I guess what is the processing loop look like for that? So, when I initially wrote it, I wrote it with a bunch of threats and with,
[00:24:37] Unknown:
with logs. And then the the system would run. So every second, we fire, like, a time change event. So this is how the system moves forward. So everything is always driven by events. So there is, it's either outside signals or an event that can cause a change to the system. And so it used to be that, like, whenever a time change event happens, I would say, okay, it's been 5 o'clock. And then and now it's 1 second after 5. So we fire a time change event every second. Then there will be listeners, for example, the light, the Philips Hue lights, they do not report the state, but we have to, like, fetch the state from time to time. And so the light component defaults to, like, check-in with Philips Hue, like, every 20 seconds. So the light component, who is aware of the Philips Hue lights, will listen to the event bus when does the time change and when the time is like, oh, 20 seconds has elapsed. Okay. Now let me ask the Philips Hue lights for their state and then write this to the state machine. Then if the states have changed, these will fire state change events and the event bus has listeners. And so these listeners are just, so like I said before, are functions. And so it would just add put this into the thread pool. So the word we would have, like, 10 or 20 threads running. We're just waiting for jobs to be added to the queue. And whenever a job is happened, came in, it would contain of the event object and of the event handler and the thread we just call this. And so this was the, the old architecture was, we had a very unpredictable execution pattern. So once if you fire an event that the 2 threats, you would never know well, it was a queue. So you know which 1 would start executing faster, but you wouldn't know which 1 would hit the lock faster.
And so we had a few logs in the core of the system. And this also could result in a deadlock sometimes, which will be very, very tough to debug. So late last not late last year. I think in the summer of last year, Ben Bangert joined the Home Assistant, and he's done a lot of work with asynchronous programming in Python. And so he was like, wait, Home Assistant's minimum supported version is Python 3.4, which is also the minimum version that introduces asyncio. Why are we not gonna try to, like, convert this to asyncio? So I wasn't myself, I didn't know much asyncio, but I started learning it pretty quickly. And so together with Ben, we rewrote the core to be completely asynchronous. We were able to put a to keep the old API intact as like a kind of like a service layer on top of the asynchronous core so all the components just could keep working. So now what is happening is that because everything is asynchronous, there are no longer threads fighting for logs. But, instead, there's 1 thread that just list all the jobs in sequence, and jobs will be able to suspend itself whenever they're waiting for input, output. So now the asyncio event loop is what is pushing our, system.
[00:27:31] Unknown:
And have you noticed any drop in the resource requirements since the switch to async IO from threads?
[00:27:38] Unknown:
Oh, yeah. A lot. So when we were using threads, I kind of had this like weird algorithm. It's like, okay, if we add like another integration, we're going to add another thread to our pool because kind of was like the idea was like, Python has the global interpreter lock. So more threats is not better, especially if you exhaust your cores. But if they're doing IO and they're waiting for the network, then it could actually speed it up. So if you add your Philips Hue, we add another thread. If you add like your z wave sensors, we would add another thread. So people would end up with, like, 40, 50 threads sometimes, which, you know, that completely swamps the Raspberry Pi, especially if they're all, like, trying to acquire locks. So now they say, hey, yo, we still have a thread pool, but it's only 5 or 10 threads, actually. I don't know exactly, which is only to support the legacy, legacy components.
But most components have been, especially the automation, they have all been converted to asyncio. So, like, we we start up like it used to be like a startup of Home Assistant could take like 10 seconds. That's now down to like 2 or 3 depending, of course, on your configuration as well. But it's and also the, the web server. It used to use a threaded web server, from Cherry Pie, cherry pie whiskey, server. But that 1 only had 10 handlers. So it means that only, 10 people could be simultaneously visiting your site, the Home Assistant UI, because we also have a stream that is always active. So 1 work always has to be active. And so now with ACKL, you can have thousands of people at your home assistant instance at the same time. Not a very common use case, but it's actually something that we tested last December. There's this YouTube channel called Bra Automation. They make they make a lot of videos about how to use Home Assistant.
And Ben, who runs this channel, he set up his Christmas tree at home to be controllable by home assistant, which he publicly, exposed. And then he had, like, a webcam on his Christmas tree so that people could, like, in Home Assistant, change, the settings of his Christmas tree, and then on the webcam could see his Christmas tree, change.
[00:29:44] Unknown:
I think I saw that actually. Maybe I was seeing something else, but it was an IPV 6 enabled Christmas tree. Yeah. Okay. That could have been it. What are some of the products or platforms that you consider to be competitors of Home Assistant? And how do you differentiate yourself from that perceived competition?
[00:30:00] Unknown:
So if I look at, like, the biggest competitor will be open HAB. This is a home automation, framework written in Java. They've been around for a long, long time. They actually had their, 2.0 released today, which is great because they released a bunch of awesome features that will heat up the competition 2 frameworks. Yeah. I think how do we differentiate ourselves is 1 is being written in Python. The other thing is that, like, because we're written in Python, we're a bit more flexible with our core interaction with 1 another. So we are, homosystyns based on a lot of conventions of, like, how do you describe the brightness of a light? This is, you know, typed. The key is just brightness as a string, for example. And so it's because of its, a lot more convention over, like, strict rules, it's easier to develop for Home And I think because it's easy to develop, we also do more frequent releases to get all this work out. So right now, Home Assistant is on a 2 week release schedule. And so every 2 weeks, there's like a bunch of changes coming out. And so every and because we release every 2 weeks, it forces us to, as a project, like, okay, we have to get all the documentation in shape. We have to, like, make sure that things are bug free and then get everything aligned, and then we can publish a new version. So I think our main differentiator is speed and easy to develop for.
[00:31:16] Unknown:
Were those some of the reasons that you chose Python initially for the project, or were there other motivating factors?
[00:31:22] Unknown:
At that time, it was like I was, playing with Python at work as well. I was like, I wanna play more with it. And now after 3 years of doing a lot of Python development, I don't think I would pick any other language anymore. But back in the days, it was more luck than, anything else.
[00:31:39] Unknown:
And when you did choose Python, was there why did what made you choose Python 3 rather than deciding to try and support Python 2?
[00:31:47] Unknown:
Well, so actually, I didn't. So I started out in Python 2.7. It was mainly because, like, I was researching online and, like, you know, all the tutorials, all the websites, you always learn about, like, Python 2.7. But as I, like, as Home Assistant was, like, in the beginning phases, I was also using I was reading up like what are Python best practices and these kind of things. And I was learning about PAP 8 and how to test your project and these kind of things. And at some point, I stumbled upon like, you know, Python 3. I knew about it but I always like ignored it because the websites, Some websites said, like, don't use it, etcetera. And so at some point, I was like, wait a second. Python 3 sounds like it's better than Python 2. Like so I started reading about it, like, what is the difference and what are pros and cons? And the other thing that, like, pretty much made the deal like, made me decide I'm going to go for Python 3 was that you know, Python 2 is gonna be end of life. There is no there's not gonna be any Python 2.8. And so, yes, it's gonna be tougher with, like, libraries, but eventually, it will all catch up. And I wasn't, like, such a good Python programmer that I could like to both do both Python 2 and do Python 3. So I was like, I'm the only user. I don't care. So I went for Python 3. Then I pretty much ended up with Python 3.4 as minimum version because I did some I used some functions to, load Python files on demand because Home Assistant doesn't load all the integrations that we currently have. Whenever you start Home Assistant, it, like, loads integrations on demand. And if those require certain, Python dependencies, we'll actually use PIP to install those dependencies, on the fly. So we ended up with Python 3.4, which for a long time was actually pretty annoying because Debian Stable, didn't have Python 3.4. So anyone on the Raspberry Pi that wanted to use Home Assistant had to compile Python themselves. But now, I think somewhere last year, Debbie and Jesse got released with Python, 3.4, available. And that is, like, that is great for new users.
[00:33:46] Unknown:
You touched on a couple of examples earlier on, but what are some of the most interesting or unexpected uses of Home Assistant that you've seen?
[00:33:53] Unknown:
So 1 of the I mean, 1 of the things that I do, which I like is that, you know, I live, like, 4 stories high and so I have like a zone of like a mile around my house. It's like a geo fencing zone. So that's when I when I enable this automation and I enter the area of, like, getting close to my house, it will send a message to my wife being like, Paulus is on its way. Better go down now. In case, like and it's only, of course, when I'm, like, picking her up to, like, go to a restaurant, for example. So otherwise, I would have to, like, text and drive or I would have to wait downstairs. But I mean, there's, like, people that, like, will track their kids go to work.
There are people that optimize growing their marijuana. I thought the Christmas tree was really cool. But yeah, there's just so many things. We have somebody now added support for license plates, which I think is very cool. So you can have, like, a camera, recording, like, in the front of your house. And then, like, when somebody parks in front of your house, it can detect if there's a car on the picture and if there's, like, a license plate. And then, like, if it's a certain license plate, you can get notified. We're actually enhancing this now. So we have, we now have a pull request open to also feed our images to the Microsoft face recognition API so you can see if there's, like, a certain person knocking on your door, for example.
[00:35:13] Unknown:
Yeah. That sounds similar to the product I did for my senior year of college where we were actually using Python and the simple CV library to use an IP camera to detect whether or not there is somebody at your front porch, and then, send an alert to an Android app to notify you of that fact. And then record video of the next, you know, 30 seconds or so to so you could see who came and what they were doing. But having something like home assistant sounds like it would have been made by life a lot easier.
[00:35:40] Unknown:
I bet.
[00:35:42] Unknown:
So given that you're working in the space of home automation and dealing with of these smart devices, what do you see as some of the most promising and potentially some of the most troubling trends in the future of home automation?
[00:35:53] Unknown:
So I think the the the biggest troubling trend is that, like, people don't really or, like, not people, companies, are not really focusing on security, but instead of focusing on time to market. I think Qualcomm put out a research that 70% of all the IoT products will be produced by like, they were produced last year, are being put in the market by companies that are, like, less than 5 years old. So when you buy such a product, you don't know if it's gonna be supported in the future. And every time they find, like, a fly, like some SSL library or something else, a potential that your, device might be compromising. This actually happened now recently, with a lot of IP cameras. So, like, the cheaper IP cameras that you can buy, they have known weaknesses. And so when you connect them to the Internet, it's like so people wrote, like, whole blog posts about it. Like, within 90 seconds, there were 2 different, like, hackers entering his IP camera and installing, like, worms. And so you saw even the, the bigger DDoS attacks last year where all their botnets are now IP cameras because, you know, people connect their IP cameras to the cloud. They have no insight what is going on inside their cameras. And, you know, it's a camera, so you make sure that it is connected to a good Internet connection because that's the uploaded stream. But it means it's also perfect weapon to bring websites down. So I think a troubling concern is just the focus on security. There should be more focus on security.
I think it would definitely help if there's more standardized platforms that people can build on top of. But it seems right now that a lot of, companies, they, you know, they they install some bare bones Linux, and they get it working, and then they just ship it. What I think that, like, some cool innovations come into home automation is that we're gonna probably see more smarter integration. So right now, setting up an automation is still, like, cumbersome. Like, you have to see, you know, you have to see 1st, you have to find something that you wanna automate, and then the automation also has to be a 100% right. Because if you have an automation at like 20% of the times, it's like not what you want. You have to open your phone to like turn a light off. It was accidentally turned on or the other way around. You get an audio. You turn off your automation. I think the cheaper like processing power becomes that you can have in your home, the better you can start analyzing the data that, like, a system like Home Assistant is gathering. And we should be able to, like, derive automation rules based on your usage patterns of, like, when are you home, which room are you in, which device are you using, how are you using these devices, and what can we do to help? So for example, if we notice that you always turn on the heating and turn on these lights or some close these curtains when you get home, well, maybe we can suggest that we do this automatically for you.
[00:38:32] Unknown:
So for anybody who wants to get involved in the project, what are some of the things that you're most in need of help with?
[00:38:40] Unknown:
I think our biggest need right now is actually not too much Python related. It's, we have also a lot of documentation, but we don't have, like, a good coherent story of, like, you know, if you want to get started, these are the exact steps. And, you know, the the problem we have is that everybody has, like, different devices, etcetera. And so I've been having this plan in my head where I wanna, like, kind of revolve a website around, like, how to get started on the Raspberry Pi because I think it's the most common and most accessible low end computing device that people can, acquire right now. And so, I mean, if if the thing where we need most help is just getting the documentation and probably we got a bunch of spelling mistakes too because most of our documentation writers, including myself, we're not native English speakers. So, you know, we just wing it. But when it comes to, like, the the Python side of things, it's just like we we always try to, like, improve, like, the experience for the users. And so this is where, like, you know, the configuration UI, these kind of things is like what's gonna be on the roadmap for this year, I hope. And so that's also where, we could use some help.
[00:39:42] Unknown:
So are there any other topics that you think we should cover before we close out the show? No. I don't think so. Alright. So for anybody who wants to get in touch with you or follow what you're up to, I'll have you send me your preferred contact information, and I'll put that in the show notes. And with that, I'll bring us to the picks. My pick for today is a movie I watched recently called miss Peregrine's Home For Peculiar Children. And it was just a really interesting fantasy kind of story that was just very visually appealing and just a very well done storyline. Pretty intriguing. So definitely recommend taking a look at that. It was very well done. And with that, I'll pass it to you. Do you have any picks for us today, Palos?
[00:40:20] Unknown:
I don't really have, like, a specific pick. According to my wife, my movie taste is horrible, so I'll not recommend anything there. I could just recommend, like, read newspapers. I think, nowadays, too many people get their news from things like Facebook or Twitter, and that's probably not the best place to get your news.
[00:40:38] Unknown:
It's a it's a good PSA. Alright. Well, I appreciate you taking the time out of your day to tell me about Home Assistant. I'm sure that a number of listeners will be pretty interested, and we'll start checking it out right away. I've definitely seen a few uses for it myself, so I'm sure I'll probably be installing it so I can experiment with some of the location capabilities of it. So I appreciate that, and I hope you enjoy the rest of your night. Yeah. Thank you. And I think so we have a pretty active
[00:41:02] Unknown:
chat community, host on Gitter. So if people want to get started with Home Assistant and they run into trouble, make sure to check out our chat room and our forum for help. People are generally very helpful. Well, thank you again and I hope you enjoy the rest of your evening. Yeah. Thank you.
Introduction and Guest Introduction
Paulus Houtzen's Introduction to Python
What is Home Assistant?
Integration with AI Assistants
Home Assistant's Use Cases and Capabilities
Privacy and Security in Home Automation
Challenges in Home Automation
Home Assistant's Architecture
Competitors and Differentiation
Future Trends in Home Automation
Getting Involved with Home Assistant
Closing Remarks and Picks