 Ok, je vais faire ma présentation en anglais si vous avez des questions aussi à français par la suite, je n'y vous pas. Ok, so this talk is about home assistant. Home assistant is a hub that allows you to automate devices in your home. I've already spent a couple weekends playing with my own home assistant setup. Before that, I was disappointed by the basic features of if this then that. I was also concerned with cloud services that need access to devices in your home. So home assistant, it runs in your house, it often runs on a low-cost computer like a Raspberry Pi, and out of the box it controls devices like Philips Hue highlights, various major players, they will be automatically detected and all of them can be controlled by home assistant. So it can replace platforms like SmartThings, Alexa, HomeKit, Google Assistant, all of those. It can also integrate with those platforms and if you already use them, they can be used in home assistant. So it connects to all of those platforms at the same time, so you finally get a way to have all your devices in your home to talk to each other and work to each other. So what I like most about home assistant is it's an extensible platform, so we can write our own components. Home assistant is a platform that automates devices in your home. It tracks the state of those devices and changes in state trigger events. When a light is turned on, it will trigger an event. When the room temperature is raising by one degree, it will trigger an event. Someone coming back home and connecting to Wi-Fi will trigger another kind of event. So based on events, Home Assistant allows you to define advanced rules to control those devices. When an event occurs, you can specify which accent to perform. For example, when I get home, I want the lights to turn on. You can also set conditions for events to tree actions. If I use the same example of lights turning on, I don't want anything to happen unless it's dark. I could also not want the lights to turn on themselves if there's already someone in the house. So for each trigger, you can define conditions. The names you see on the slides, device tracker.fill, light, living room lamp, are names of what are called entities. To give you some perspective of how Home Assistant looks, here's a screenshot of a responsive word application it provides. The web views can be customized by editing a configuration file. For example, this is exactly the setup I have at home. So even if you don't automate anything, you still get a nice dashboard with all your devices and different services. Under the hood, Home Assistant is a pure Python package. It uses new features from Python 3.5, such as Async IOT, and type hints. Yes! You can download an image for a Raspberry Pi called haiss.io, and it will set up for you that Raspberry Pi has a small appliance. So we'll skip all the basics, jump directly to advanced topics, and this is because Home Assistant can be extended by creating components. This way you can add new types of devices. Well, Home Assistant always supports hundreds of devices, but that's not going to stop us just writing another one. So I'll show you how it's possible to create and integrate a custom component. All the code will be on GitHub, so you can come back to it later at your own time and pace. So one type of device is a sensor. The state of those devices is continuously updated, so by some measurements or external service. Sensors can be switches, security cameras, weather services, and so on. As you can imagine, the definition of a sensor is very open. It goes well outside of the scope of just home devices. For this talk, I'll use data from the Strava API as a new type of sensor. This API provides, for example, athlete stats, such as total running distance since the beginning of the year. Here's an example of how it could end up being used. So we have one entity that comes from the Strava platform. Its state is, for example, the distance run by the athlete. So one thing we can do is attach a trigger. So when the entity state changes, that is the total distance of that athlete, we can have some action to be performed. Some glorious music. So on the right side is an example of what such a trigger would look like. So to create a custom component, we create a new Python module. It's often a single file, and a component will describe a new platform that we want to support and the type of entities that exist under that platform. So, near the top, components defined are Python package dependencies. Home Assistant will install them when needed. If you have defined requirements for a project, this is kind of the same syntax. Our Strava platform has a configuration schema, which is the definition of the format of the configuration information that is required for enabling that platform. Here we specify for that platform that it needs the client ID and the client secret to connect to the Strava API. Entities, finally, represent individual devices. So each instance of devices has a unique name and holds information about the state of that device. Many services that provide a web API to access their data will require some form of authentication or authorization process. This is the case with the Strava API, where we need to add some code to fetch an access token. This token allows our component to fetch and that leads personal data. Hopefully Home Assistant provides an utility called HTTP and a configurator component. With those, we can create a card on the web dashboard that will set up an HTTP called Backhandler that will manage the authorization process. So this is a UI thing. We can put the roadside aside for a minute. This is how a typical component setup looks like. So Home Assistant will call setup platform with a configuration, and the component will use that to create entities and add them as devices. So from there, the system is in a closed loop. Home Assistant will call update method on each sensor entity. It's the responsibility of that entity to fetch up-to-date information. So the simplest way to do this is to rely on a third party, Python package or Python library. In this case, Strava Lib. That allows you to use that particular service. For example, yeah, this. For the Home Assistant project as a whole, it makes a lot of sense. They already have to maintain hundreds of different sensor types. And the project computers don't want to have to maintain all those hundreds of integrations. So they prefer to have third party libraries and just have to bump a requirement version number. So now that we have our code ready, we'll make it available to Home Assistant. So in the configuration file, we had our new sensor. We see that we use the name of the Python module as a sensor platform. After that, we fill information that is required by our component platform schema. And then the platform Zmed is the thing that we had to define our code. If we're not yet authorized to connect to Strava, we will see a configuration card that let us connect to the API or the account. Otherwise, when that's done, a device entity that represents an athlete. And this will show up in the UI. So let's just try. Cool. So for this example, we just did those three steps. Our component is alive. We just didn't run through the whole authorization. Let's see if it works. Not quite. Oh, well. In the pick for trick world, there would be the same card with just the number, which is the number of kilometers that I've run. But it seems that it's a different network than at home. Anyway. Okay. There's a lot of ground I haven't covered in this talk. I didn't explain in much detail what Home Assistant does, how it works, how you can use it. For that, I highly recommend watching Paulus Schaudzin's talk at PyCon. So he goes through, he's one of the core developers of Home Assistant. He gave a talk at PyCon 2016. He goes through the design of the platform, so I highly recommend. The Home Assistant documentation itself is excellent. However, I still struggle with the configuration for the triggers. So probably in the following weeks, I'll spend time discontracting the different automations and triggers I have at home and write some kind of cookbook that anyone could look into to maybe get the basics right. Finally, the code that I use for this demo, it works. So I'll put it on GitHub, too. There is also some custom components I wrote for myself that will be there. So if anyone wants to give a little help, it could even end up being integrated into Home Assistant itself. Thank you. If anyone has some questions, please. Big question. Well, first of all, really looking forward to doing a cookbook. Can you give us just a few ideas of what you've accomplished with it? So the question was roughly what can I accomplish with it? So you can roughly guess on that dashboard, which is exactly the one I have at home. There's a lot of monitoring. And on the center part, there's the people part, which is essentially our mobile phones when we come home and it's detected by Wi-Fi router. So there's nothing about GPS tracking or anything. It's really when the home connects to Wi-Fi. We have some automations like turning the lights on or if it detects movement, but there's nobody home, just don't mind about turning the lights on and so on. Otherwise, it's mostly buttons you can trigger actions manually. So we can turn on all the lights or turn off all the lights most often. And otherwise, it's weather and monitoring for some solar panels. So you have a big one single overview of all the devices regardless of the product or technology, which is really, really cool. How many devices I think a home assistant documentation claims 200 something different platforms. So that's a lot of things, yeah. Kind of roughly the main advantage of using a custom made home assistant setup is that even if you're already using some kind of home automation platform, if you have a second one or you just want to be able to customize it, you just put that on top and you replace all your usage of the current apps you're using with that. It will do all the things you need. And in the end, you just have one single point that it's like pseudo superpowers on your home automations. Cool. Yeah, there's a lot of things. Is that voice input at the top or just imagining that? No, it's really voice input. I just didn't put a microphone on my Raspberry Pi that you can actually have some voice recognition, yeah. I think it isn't. There's another way which is using a home assistant integration. You get Google Home integration into this. It obviously requires some network. Yeah, it all works. Yeah, maybe I can try to show whatever. Yeah, a home assistant will record all the events and the states on the database internally. And you can go back in time and look the weather through the day and how how long your lights are on, whatever. So you get tracking for everything on extra, which is something that I don't think most platforms offer. There was one there. The finances model that I see there, I mean, are you actually trading based on your light? Or you're reducing the light when the finances go down at the base? I could. Could it be possible, I mean? Yeah, why not? What system do you have experience with to improve the lights? Exactly, in this case it's Z-Wave. I'm going through a SmartThings hub because this is how we started. So it just calls to the SmartThings platform and from there it's just a bridge. So essentially it gets feedback on the lights are off and can turn them on off. Maybe something. This is really cool because this is a HTML5 web worker application. So it will run really, really nicely in a web browser. I know in Android you can pull that web page into some kind of app. So it looks like a native app, but essentially it's just HTML5 based. I don't know on an iPhone but I guess it would be really, really neat. OK. Right. Oh, non. OK, c'est OK. Their iOS app is exactly a container like that. OK. There is a wardrobe. Maybe a last question. Yup. It looks a little bit weird to have all your passports in a single file on your Raspberry Pi. Does it support using sCrypt to include all the passports with the single passports at some point in time? I haven't played a lot with the encryption. There's support for storing secrets safely, but for one thing it's a local device that doesn't have an inbound There's no exposed part to the external internet like most of the web automation platform, so in a way it's resistively safe for this reason. Another thing is that it's mostly API keys being stored there so in a way if something bad happens I maybe have to revoke permissions or something like that. It doesn't sound too bad. In a sense it's not much worse than other home automation platforms and I know from the documentation you can go much much better. If you want you can have an encrypted partition and everything you can go wild. Well, thank you very much.