 So this is Leon, he's going to tell you about turning on the lights with Home Assistant and MQTT and the rest he'll explain it to you. Thank you very much for joining. My name is Lonon Avie and I'm a senior software engineer at a company called Consulco Group. The company provides open source software consultancy services for popular projects such as the Yocto project, automotive grade Linux, Linux kernel, Uboot. And actually for me, working with embedded devices is not just a full-time job, it's a hobby. And I'm here to speak with you about an open source project that I'm having that I'm doing as a hobby in my free time. It's using Home Assistant and MQTT and I would like to show you a quick demo with it. How many of you are familiar with Home Assistant? All right, perfect, almost everyone. So we're starting with the demo. It's very simple and after that I'll show you how it works. So here we have an RGB LED strip and I'm going to control it from Home Assistant. As soon as in real time I'm changing the colors and you see the result. All right. So now I would like to show you that this thing also works with Alexa. So this is a demo that I shoot at home. It's pretty much the same that I did here. But the additional thing is that I've integrated voice control using Alexa. So just one minute and in this minute you see how it works with Alexa. The thing is that set up in here Alexa takes a little bit longer. So I'm not bringing Alexa with me. That's the demo. And probably you're wondering how does it work? It's a very simple demo but it includes several open source projects as well as a bunch of hardware. Obviously a Raspberry Pi 3. I have designed an open source hardware out on board for Raspberry Pi 3 to control the RGB lights. I'm also working on another open source hardware on board for doing the same thing with a microcontroller. I have an RGB LED strip, 12 volt power supply for the RGB LED strip. Another power supply, standard power supply for Raspberry Pi. And Amazon Echo Dot for the thing that we saw with Alexa. This is the open source hardware board that I have designed. I have created it using Kickat. Kickat is a free and open source software tool. And in my opinion there is a huge value in making open source hardware only if it's done with free and open source software. That's why I created it with Kickat. Yesterday I had a talk which focused more on the hardware side of things. Today I'm just showing and doing a little bit deeper dive in the software. So this is an out on board that works with any model and version of Raspberry Pi with 40 pin header. It has an EE prom with the device strip fragment on it. And furthermore it has slots to put some sensors like per motion sensor or various I2C sensor modules for detecting collide, temperature, humidity, or even gestures. The schematics are available in GitHub. I'm also running a small crowdfunding campaign to CrowdSupply which is a great platform for open source hardware products. How does it work? So it's a very simple demo but behind it there are a lot of open source components. As I said it's a hobby project and all the components that you see here are open source including the hardware that I have designed. Raspberry Pi of course is unfortunately not open source hardware. So we have Home Assistant with a couple of components. I'm using the MQTD protocol and MQTD broker that you're probably familiar with, Mosquito. I have written a small C application that takes care of the incoming commands through the MQTD protocol and executing them by changing the covers of the RGB LED which is attached to the hardware. By the way all the slides are already available at Fosn.org. So let's have a look at the various components that we have. First with Home Assistant. I saw that a lot of you are already familiar with it. Actually I started using it recently. I needed something to control my hardware. I needed something that's open source and Home Assistant is quite popular. It's been there for like five years. There's a huge community and there are a lot of components. So if you want to control an existing Internet of Things on the market like Philips Huey, Keatrat Free and so on, there are components for this in Home Assistant. And furthermore there are components like MQTD, JSON light component which I'm using for my demonstration. The source code is in GitHub and as I said there is a huge community of both users and contributors to the project. There are numerous ways to install Home Assistant on Raspberry Pi. And since Raspberry Pi is a very popular board, Home Assistant is perfect to run on it. And by the way Home Assistant is written in Python 3. This is something that I forgot to mention. So there are two straightforward ways to get started with Home Assistant on Raspberry Pi. The first one is called HasIO which is an operating system based on raising IOS. And the second one is called Hasbian. And as you probably have the guess, it originates from Raspbian. And Raspbian is the official domain distribution of the Raspberry Pi foundation for Raspberry Pi which is based on Debian. So basically Hasbian is based on Raspbian and adds on top of it Home Assistant and some nice scripts to make things easier. And I'm personally for the demo that I've showed you and the demo that you should see here, I'm using Hasbian. The protocol on which the whole demo is relying is called Amputity. Are you using Amputity? Okay, a few people. So I'm a huge fan of Amputity because it's a lightweight machine-to-machine protocol that requires a broker. So the broker is distributing the messages to several different clients that are subscribed on topics. The protocol has some great advantages for embedded devices. It has a small footprint so you can deploy it on pretty much any device. There are a lot of open source Amputity implementations of brokers like Mosquito that's written in C, HiveMQ that I believe is written in Java, Moska that's written in Node.js, so you can pick an Amputity broker that's YouTube best in its open source. My choice, my preferred choice for Amputity broker is Mosquito. I really love it, it's very simple. It supports Amputity protocol version 3.1 and 3.11 including WebSocket support, which means that you can directly send from the JavaScript in your web browser. You can directly publish the messages from the JavaScript in your web browser to the Amputity broker. It's available for Linux on popular Linux distributions. There are packages, so if you want to install it, you can just, for example, Raspbian or Debian, you can just type up to get install Mosquito and it will be there. It's also available for Windows, FreeBSD and Mac. It's a project of the Eclipse Foundation and this is the website to learn more details. So in order to have all these things working together, I needed to create a small piece of software that integrates all the parts in this demonstration together. It's called AnavidD. Back in the past I had some legal issues with the names of my hobby projects, so from now on I'm just using my surname just to avoid any legal issues with that type of things. The D comes from Demon. It's open source, it's available at GitHub under GPO V3 license and it relies on a lot of popular open source libraries. Pako and Qtdc, the Pako project provides implementations and Qtdc clients. I'm going to share a little bit more details for it after that. PGPAL is a library for Raspberry Pi that allows me to control with PUS with modulation the colors of the RGB strip. And Warring Pi is a popular library that I'm personally using for reading data from I2C sensors and to publish messages with Qtdc data about it. So the installation of AnavidD, for the moment there are two ways to install it. The first one is just to build a source code. This is the thing that I'm doing but obviously it's not very convenient because I decided to make a Debian package using debute and the installation comes to single line. After installing it, there's a configuration of file. You can skip that and if you skip it, it will work with default configurations which probably means that it won't work in your setup but you have to configure this any file. So let's have a look at the various projects that I'm using in order to write my software. The first one is the Eclipse Pakho project. The Eclipse Pakho project provides MQtdc client libraries written in the most popular languages. There is an implementation in C++, Java, JavaScript, Python, Go, Rust and C-Sharp. It's another project of the Eclipse Foundation just like the Mosquito Broker. So in order to use it, first I have to create an MQtdc connection. After that, I have to set a callbacks because basically the MQtdc communication is asynchronous. An event can occur at any time and the MQtdc broker should notify the client, my client, that this event has appeared and my client should take the necessary actions. If my client wants to publish an MQtdc message, this is the function that is coming from Pakho MQtdc implementation in order to publish the message. I'm doing this for sensors. If there is a change in the temperature, I'm publishing the message. The PGPL library is something really, really important for my project because it allows me to set the color of the RGB LED strip. It offers a socket and a pipe interface in the underlying C library. It's available again in GitHub and what I'm basically doing is that the RGB LED strip has the three main colors, red, green and blue. I have to set a value between 0 and 255 for each of these colors, which means that there are more than 60 million combinations. In order to do this, I need to use Pulse Width Modulation. Fortunately, Raspberry Pi has only one pin with a hardware Pulse Width Modulation and obviously for the three colors, I need three pins. What I'm doing is the software-defined Pulse Width Modulation, which is actually done by the PGPL library, so I'm just using it to set the appropriate color. I'm relying on SystemD. I know that maybe some people hate it. Don't hate me, I'm just using it. Oh, I have developed this SystemD service. Basically, just to say that SystemD is one of the unit systems in Linux. It's designed to replace System5. This is the service that I'm having that's running on the Raspberry Pi to make sure that as soon as I turn on the Raspberry Pi, my simple application that accepts the in-cuting messages is going to be running. It requires the PGPL service, which starts the GPIO demon, and after that, it's a very simple service that starts the binary on failure. It restarts on every 10 seconds and it's launched at SystemStartup. Here's how to manage the SystemD service. How many of you are using SystemD? Okay, perfect. So you know how it works, right? By default, when installing the Debian package, it's going to be enabled, but if you want to disable or enable the SystemD service at boot, this is how to do it. You can start, stop it, have a look at the status if it's running, and have a look at the lock files. Fortunately, my demo is working, so I didn't need it to check the locks today, but sometimes I need to do it especially during development. Machine ID is another thing that's coming from SystemD. There is a SystemD service that initialized the Machine ID in this file, and I'm using it to identify the devices, because obviously this is a very simple demo with one light, but my plan is to have numerous lights like this in my apartment, and obviously I need to identify each one of the lamps, and I'm using the Machine ID to do it. At the moment, I'm using it in a very unprofessional way and not secure way because the documentation says that this thing should not be exposed on the network and I'm exposing it, but I'm going to fix that with a cryptographic function just for security purposes. So, how does it work in Home Assistant? After installing Home Assistant, there is an MQTD JSON light component, which I'm configuring in the configuration YAML file of Home Assistant. This is the main configuration file of Home Assistant where all components has to be listed, including the MQTD broker. So, this is the name of my device. You can put whatever you want. Furthermore, you can create groups in Home Assistant and control a group of devices. So, if you have like five lamps in your living room, you can control them all together. This is the MQTD topic. Obviously the Machine ID comes here in order to identify each of the devices. MQTD JSON light allows me to adjust the brightness or the specific color. Here are the messages. After sending MQTD message to the following topic, my client should read the brightness data. It's from zero to this value. So, this is the full brightness. Zero is turning off the lamp. And if the user wants to set a specific color, this is the JSON message that has to be sent over MQTD. It's very straightforward and very simple. The end result is something that you already saw. Home Assistant out of the box provides a user-friendly web UI that works on a smartphone, on a tablet or a personal computer. And you can control it. Furthermore, it's something that I've shown you as a video. Home Assistant has one really cool component which is emulating Hue Bridge. And it allows me to connect my solution and Home Assistant to Alexa. This is something that works out of the box with Home Assistant and Alexa. So, basically Alexa had a built-in feature to control Philips Hue lights, which allows us to control other devices that are already integrated in Home Assistant. Unfortunately, it's just a very simple control for turning on and off. But this is done by adding the following configuration in the configuration email of Home Assistant. So, the end result is simple commands Alexa turn on or turn off, depending on the name that you have configured for your device in Home Assistant configuration file. Obviously, putting a Raspberry Pi in each lamp is a little bit expensive. And I need one Raspberry Pi to run Home Assistant, but obviously that's enough. And I want to have more devices and I want to cut the cost. So, what I'm working on is another device. It's still working progress, open source hardware. The thing is in GitHub, so you can go there and use it. It's developed with KitKat. So, basically what I have in GitHub is the whole KitKat project that you can download, have a look at the schematics, modify it. I'm using KitKat on Ubuntu with the stable version for Ubuntu. So, this is using the Magical Chinese chip ESP8266, which has a microcontroller with a Wi-Fi and the magic comes from its price. It's like less than two years' doors. This is the model ESP12, 12 volts power supply. Again, the microcontroller, this is a button that is connected to GPIO0. So, if you want to put it in a flash mode, you have to press this button. Here is a UART pin and three I2C slots, so you can plug I2C sensor modules, like the ones that I'm having on Raspberry Pi. The software on this microcontroller is still under development. That's why I'm showing you only the Raspberry Pi. But it's doing the same thing in a different manner because I'm using the Arduino environment and these popular libraries. I have this ESP.GetChipID method, which provides me an identification of the device and I can do the same thing with the MQTD topics, like the machine ID that I was doing coming from SystemD. Again, I'm using PUSWIT modulation. What is the difference between the two boards? Obviously, the main difference is that the ESP board that I'm designing is a standalone product that doesn't require anything else, while the other thing is another board for a Raspberry Pi. The rest is pretty much the same. The Raspberry Pi FAT has a peer motion sensor, unlike the controller based on ESP. So, just a few conclusions and I'm wrapping this talk. Obviously, the integration of embedded devices with the MQTD JSON component is straightforward but it requires quite a lot of steps and I'm working to improve this and to make it possible for more people to set up this solution because it's super easy to use it but the setup is a little bit annoying even for me, although I'm the developer. Using a microcontroller like ESP8266 will cut the cost and will make it more affordable for more people. The last thing is more like a state of mind, in my opinion, combining open source hardware with free and open source software makes a great benefit for the whole community because anyone can study, modify the project and the knowledge can be really shared between all of us. Thank you very much. We still have a few minutes. If you have any questions, I'll be around. I'll be also around the AGO stand in this building so if you want, you can go there and talk to me as well. Thank you. The questions always repeat the questions in the video. Do we have any questions? We have a few more minutes for questions. Yes, sure. Just a few points. I'd like to play around with ESP8266 as well. There's a library you can get for ESP8266 that allows you to have an update page and you can dump it. It gives you a web form. You can upload a binary and it reflashes the device itself so you don't actually need to keep putting queries. Which is really nice. This is a suggestion. I have to repeat it for the live stream. This is a suggestion saying that there is already open source software for ESP8266 which allows firmware updates done from a web interface. Just to mention that basically the first time when I'm flushing it, I'm using the same procedure. The other thing is if you thought about the, I can't remember the exact game with the MQTT, rather than having a machine name, actually setting up location. So I've been looking into sensor networks, the same kind of thing. So I started doing some like home slash room slash functionality. It allows me to break down control a little bit easier. Okay, so the question I found familiar with the MQTT system that helps to identify devices, right? No, sorry, I'm not familiar with that. Any other questions? Maybe we have time for one question? Yeah. So do you have the ESP8266 that is using MQTT and it is connected to a broker? The broker is still running in the Raspberry Pi. Okay, so the question is, do I have the ESP8266 connected to a broker that's running on the Raspberry Pi? Absolutely, this is the idea. This setup, everything is working on the Raspberry Pi and the idea is to have this setup and to add ESP's modules around it. Hopefully if I'm ready with the things that I'm working on, maybe next year I can show them. Okay, thank you very much for joining.