 Thank you very much for joining this session. I know it's been a long day for all of us The topic that getter does here is home automation within QtD. I have so many things that I would like to share with you So I just want to get started on time My name is Lonon Avie. I'm a senior software engineer at consulka group The company is specialized in providing services related to embedded Linux products We have expertise in various open source project Projects. My role there as a senior software engineer is primarily focused on the Octo project and open embedded If you're here on Friday for the Octo Dev Summit I'll have another talk explaining how you can build custom Linux distributions for NVIDIA tegra devices The company is based it has a headquarter in San Jose, California However, we're distributed all around the world. I'm personally coming from poverty Bulgaria the Agenda for the talk today is Of course, we're going to speak about home automation and in QtD How many of you are familiar with in QtD? Can you raise your hands? All right? That's perfect I've got a few slides with introduction to in QtD because this talk is for beginners So even if someone doesn't have an experience with in QtD, that's fine. You're on the right place. We'll do Brief introduction to in QtD. So you have a good understanding about the protocol by the end of this presentation after that, I would like to share with you my experience in Various challenges regarding data serialization and I would like to show you how popular open source projects for home automation such as Home assistant and open hub provide conventions and support Conventions so that your embedded devices internet of things that communicate over in QtD can implement this convention and talk to the popular open source home automation platforms I have a few demonstrations one with home assistant another one with open-hub to I've recorded videos which I would play just to make sure that nothing will go wrong and Finally, we'll do a few conclusions and there will be time for questions and hopefully answers from my side All right. This is these are the trends in protocols for communication between machines In the past ten years as you can see here As you can see the popularity of in QtD is rising. It's rising rapidly compared to Various other protocols and there is explanation for this Keep in mind this a few slides later. I'll explain why this is happening in my opinion also nowadays, there are a lot of Open source home automation platforms which you can install at your home and use like Five or ten years ago. This was not the case and a lot of people created various platforms Often people just started from scratch because there was not an appropriate open source platform for home automation on the market at that time however today The situation is completely different. There are a lot of home automation platforms that are free and open source software and There are some of them that are having a huge community and a lot of a lot of useful features so If you are starting with home automation nowadays, you have you have plenty of choices and The good thing about open source is that you have the freedom to switch from one platform to another so As I've promised a brief introduction to and QtD as a protocol It's a lightweight published subscribe machine to machine protocol on top of TCP IP it has It's a real time near real-time communication. Yeah engineering to speak and it's I think the correct The correct way to present this is near near real-time communication between various clients and a broker QtD has a small source code footprint which makes it convenient not only for devices in which you run Linux, but also for Microcontrollers and a lot of people including me are using QtD on Arduino or Arduino compatible devices There are three versions of The protocol and we're gonna speak about them. There's also MQtD for sensor networks over UDP. This is something that's out of the scope of this presentation and the good thing about MQtD is that it is already supported very well by The popular open source home automation platforms that I've mentioned in the previous slide particularly by home assistant and open hub Also have just a single slide for the mottics at the end. It's the MQtD is also supported in the mottics Let's have a look at the milestones for MQtD. MQtD isn't something new MQtD has been around for 20 years and Since 2010 it has become a royalty free License for the protocol and if you remember the first graphic that I've showed you and the rise of popularity of MQtD in my opinion This is because MQtD nowadays is royalty free and more and more people are using it There are a lot of implementations for clients libraries, of course for free and open source software MQtD brokers Which we'll briefly discuss later on In 2014 MQtD version 3.11 was became a standard. It's also an ISO standard Since April this year we have MQtD version 5 So we have 3.1, 3.11 and 5 Probably some of you are wondering hey, what happened to MQtD 4? Well MQtD 4 doesn't exist because the 8-bit unsigned value that represents the protocol level in the connect packet Package has been already occupied by protocol version 3.11 Therefore the latest version is in QtD 5 By the way all the slides that you see here have been already Uploaded there will be also recordings from this talk you can Go to the Website of the conference to download the slides the same version that you see here MQtD has several important Operations connect obviously this is the first thing that any client has to do it has to connect to the broker When you connect something you should have the option to disconnect it of course MQtD has this operation Subscribe and unsubscribe are In the heart of MQtD because MQtD works with topics each message has a topic and these operation Allow your clients to subscribe to certain topics, which means that they'll start receiving any messages with this these particular Topics or to unsubscribe and of course publish is the operation which allows your client to publish an MQtD message the other interested Clients and the broker is responsible for this Probably This was not the best explanation. Therefore. I did this very very simple diagram So what we have here in the center? We have an MQtD broker. This is important to know about MQtD All the clients connect to an MQtD broker. They publish the MQtD messages to the broker and the broker is the one responsible for delivering those messages to the interested clients based on the subscription that each client has done when he has Connected after he has connected to the broker So this is a very simple example. You see several MQtD clients connected to the MQtD broker each client can Send and receive Messages, however each message is going to the broker in in this scenario So here is a simple explanation of the MQtD message. We have a topic This is the topic here Well, I'll explain you the levels and how the topic is Should be generated in the next slide there is a payload the payload could be text or binary For the particular examples that we're gonna have a look at for home automation will be Dealing with text payloads of the messages Quality of service is something really cool in MQtD So you can mark the quality of service per per message when you're publishing the message to the MQtD broker There are three levels. The first level is zero, which means that the message that you are publishing will be Received by the interested clients at most once and as you can guess this means that some clients might not receive it If you want to make sure that the message is going to be received You can use quality of service one. This means that The message will be received by the interested clients at least once however with quality of service one There's an option that some clients might receive the message more than once And if you want to be sure that the message is going to be received exactly once quality of service Do is what you need? However, keep in mind that depending on the MQtD broker that you are using Some brokers might not support quality of service two and so My recommendation is when you're picking up an open source or non-open source Implementation of MQtD broker check the documentation to make sure that the broker supports The quality of service that you need and there is a retained flag, which is a Boolean value It could be true or false the idea of the retained messages is that The broker stores these messages and The band keeps them so that if a new client subscribe for this message later on later after the message has been sent the broker will take the responsibility and Deliver this message the newly subscribed broker. This is especially convenient for home automation of The most basic example temperature sensor the temperature sensor sends an MQtD Publishes an MQtD message when the temperature has been changed You don't need to change it to publish the the temperature on each second You only need it to be published when the temperature has changed so And sometimes the temperature might stay the same for hours no need to publish again and again a Message, but if you publish this message with the retained flag set to true the broker will keep this This message and when another client interested in finding out the temperature subscribes to the broker The broker will deliver the last known good value of this temperature Another thing is that in certain cases you might need to delete Retained message. It's quite simple to do it. You just Publish another message with the same topic and an empty payload Last will and testament. This is another cool feature that MQtD supports. So when you when you connect your client to the broker you can Create a message as a will and the broker if the broker detects that your Client has been ungracefully disconnected the broker will use this message that has been provided When the your broker connected to notify other interested clients that your your client is no no Not existing anymore This is convenient feature for devices running on batteries because you can you might run out of batteries and your client might disappear Your device might disappear from the network in this case The broker will detect that the device is not over it not available and notified the other interested clients Of course, it's also convenient for detecting failures and power outages for home automation scenarios And the most important thing about MQtD are the MQtD topics The topics are divided Into levels. So when you when you publish an MQtD message you have to specify You you have the option to specify different levels and for home automation. This is really convenient The the topics and the wild cards are important not when you put not that important when you publish But they're super important when you receive messages so when you subscribe for a given for from a given topic you can use a wild card and This wild card. It's like a regular expression will match various topics this way your client will receive not only Messages for certain for a one and only topic but for a various topics that matches these Criteria so here here are the examples the first the first topic here is With bedroom so it's home bedroom. This is for a single room However, you can have the same thing going on for your living room for your kitchen and so on So you can use the single level wild card with the plus sign. This means that you're going to receive all Messages with topics that have this level and this level and whatever level is between them And of course you can have multiple level wild card Like this. This means we'll just you just receive all the messages started with with the prefix home in this example Security is always important in the internet of things people often say that s in iot stands for security And this is not the case with MQtD. MQtD has Security because there is a transport encryption with SSL of the messages You can have authentication with username and password and you also can have authorization with active control lists Which means that you can restrict certain topics and and Users you can define which user has Access to this topic or that topic This is this convenient way when you are creating System with multiple users even in home automation Sometimes you you have multiple users of your home and you would like to Restrict the access on a protocol level and MQtD has these features enabled Of course, they're implemented by the MQtD broker of your choice a Few words about MQtD 5 what's new that new there It has better error reporting. There are some metadata and user properties They are providing a request response interactions, which is something new share subscription and Better performance for scalability In home automation the way I use MQtD Scalability isn't that important because I'm pretty much. I'm running MQtD server at my home for my own needs however, if you're building a Cloud application scalability becomes a problem because you might have Minions of users that are generating Thousands of messages per user which creates a huge amount of messages a Few words about popular open source MQtD brokers mosquito This is my preferred MQtD broker for home automation because it's written in C It's quite fast and quite simple to use it It supports active control lists, so It's a very good choice for home automation if you are planning to Install something just for your own need at home. I would recommend you mosquitos mosquitos written in in JavaScript which is quite modern for all web developers our out there I did another talk a year ago doing a review of all those all those brokers, so And the video of from this presentation is available You can have a look at it if you want to learn more details about certain open source brokers and their communities Also, there are a lot of popular open source MQtD client libraries The Pako project is a project of the Eclipse IOT foundation. It provides implementation for client libraries for MQtD MQtD in various languages Which greatly simplifies the development because you can just grab this open source library and use it without worrying about implementing the the client itself of course there is a Node.js open source library and Arduino open source client which I'm personally using for some internet of things that I have created which I will show you later in the slides so We covered MQtD as a protocol. I hope it's clear for all of us What MQtD is at the beginning I've asked you and I saw that most of you are have previous experience with MQtD As you can as you have seen from these slides MQtD is a great near real-time machine-to-machine protocol it solves the issue how to Send messages and exchange messages between machines. However MQtD does not define a specific Convention for the payload the payload of the MQtD message could be binary. It could be text However, you are free to send any kind of message Freedom is a good thing. However, when you have to do integration between various components You have to work with a convention therefore I would like to show you a couple of conventions here The first one is defined by home assistant home assistant is an open source home automation platform It's written on Python. It started six years ago It has a huge community huge number of contributors Excellent documentation and very active forums The source code is available with GitHub under Apache 2.0 license. It's perfect to run on Raspberry Pi There are a couple of options how to install it on Raspberry Pi the old option was a Distribution called Hasbian as the name the name suggests it's a derivative of Frasbian, which is a derivative of Debian in more modern times The home assistant community came up with something called Hasio Which is a basically an image nowadays built with built route that contains a container and within within this container Home assistant is running Hasio tries to simplify the getting started process for For users of home assistant. There are some plugins that you can configure and install Also, of course, you can manually install home assistant That's another option home assistant images are also available for inter nuke Odroid orange Pi Prime and Virtual machines. So these are devices popular in the maker community. How many of you are using a home assistant? All right, that's a fair number So Home assistant has a lot of features. I'm not even familiar with most of them. However, there are a few Features that I believe are really really special. The first thing is that home assistant already has an integration of thousand components So if you buy a device From a shop most probably this device is already supported by home assistant This is because home assistant has a huge community and a lot of people are putting efforts to integrate devices into it the other important thing an advantage compared to some of the other open source home automation platform is the authentication with user profile and Password as well as the option for a second-phase authentication There are also automatic updates of the default User interface called levelize of course you can modify it if you want you can modify it, but then you have to Be you have to make some extra steps while updating it however, for this particular presentation the important things are automatic discovery of devices and Excellent integration of MQT components. So let's first have a look at the MQT components There are a lot of MQT components that home assistant supports out of the box In this presentation, we'll focus with a few examples about three three of them. These are for regular sensor for binary sensor, which means yes or no sensor and MQT light component because the imputed light component shows you how you can control devices over imputedly that are integrated in home assistant So the home assistant discovery is a feature that allows you to easily configure devices Your new devices in the network. The idea is that you have home assistant running on a device in your local area network at your home, then you buy a device for example, IKEA Trout Free, which I'm also using and Integrate them with home assistant by the automatic discovery, which means that as soon as you plug the new devices and configure them in your network Home assistant will detect them and show show you a notification that you have this new device And the great thing about this is that it supports imputedly so you can make your own device that works with imputedly and Implement the home automation discovery procedure so that your new device will be automatically discovered when you use it So in order this to happen your Internet of Things have to provide over imputedly a specific configuration message Also each device must have an unique identification just to make sure that you are not Just to make sure that you can identify uniquely the device that you're using The imputedly discovery has to be enabled. There are a couple of ways to do it Here the example is in the configuration YAML file, which is the main configuration file for home assistant So you have to go there. You have to put a broker and imputedly broker and After that to enable discovery and to set a discovery prefix if you're using If you're using Hasayo a demonstration that I'm going to show you later on You you don't even need to mess with the configuration file. This is something that you can do From the user interface. However, considering that we are a developer conference probably Configuration file is not a problem for the people in the room Okay, so this is the specific format of the imputedly topic Specifically for the message for the discovery of your device You have the discovery prefix. You saw how it's configured over here After that you have a component the component must be something that's already supported In home assistant with which means this must be a component from the list of components that you saw on the previous slide The node ID is just an optional level. It's not used in home assistant But sometimes might be useful for other systems using these devices within your local area network And of course the object ID is the unique identification of your device Here is an example with an open-source hardware development board that I have designed with kick at super simple board ESP 8266 DHT 22 sensor. It's a maker board the The default firmware that I've wrote and it's written It's running on the on the board Sends a topic to home assistant Slash sensor slash device ID here in red. I just put a fake idea of the device However, the device ID is generated out of the device ID provided by ESP 8266 And after that with MD5 I'm creating a hash so that nobody will understand the actual Hopefully nobody will understand the actual device ID and Below is the payload of the message pretty much the payload describes. What kind of component is this what Should be done and so on. I have to say thanks to the people contributing to this project because It's an entirely open-source project and actually initially the home assistant discovery Procedure was added not by me, but by contributors from the community and Here here is how you have to enable MQTD and to configure it in home assistant in easy steps This is from Hasaiyo from the plugins you have to install MQTD broker. There's a plugin for me for the MQTD broker after that You have to define these configurations saying what is the the user name that the MQTD broker should use and finally when it's done you start getting information from the devices within your Within your network, however, of course you go through the step that automatically those those Devices are discovered and you have to press finish to make sure that they will appear a few words about each of them Three examples sensors that I would trim example MQT components that I would like to review the first one is The most simple MQTD sensor. This is the one that I'm using to implement the reading of the temperature. It It requires a configuration of the state topic, which means you have to say what is the topic on you on which you'll get the information from The paywall that the message is the sensor value. It could be plain text or JSON. It's a matter of configuration There are a number of other of other configurations that you can set for example the Unit of measurement so you can say whether The value that's coming is in Fahrenheit or Celsius depending on the region where you live This was introduced in home assistant zero seven. So this is long ago and There is a perfect documentation on the link below. So here is the example how it actually work Here is a topic starting with a prefix work group followed by the next level the identification of the device After that, I'm saying that it measures the air temperature is instead of air It could be water because I can to this specific board. I can also attach DS 18 B 20 sensor that is waterproofed and measured temperature in let's say a fish tank It says a payload as an MQT very straightforward and also the humidity He's having a similar configuration with topic and Jason payload super simple and super efficient The binary sensor is another type of sensor. It's even more simpler. It's useful for Sensors that act as an alarm alarm, which means it has only two states on and off The example here is with another open source hardware board that I'm using with MQ 135 gas sensor for monitoring indoor air quality So this sensor is it's a cheap sensor. That's not very accurate However, with good calibration, you can detect for example that there is a smoke and then race an alarm An alarm. So the payload in this case is just the plain text on and off imputed he light allows you To define imputed component that is capable of turning on and off the lights. It's a port three different Message schemas. It's particularly convenient for controlling 12 or 5 volt addressable or non addressable LAD strips Because homosystem has integration with Smart speakers such as Alexa you can after after doing an imputed integration of an imputed light Component you can after that use voice control to say for example Alexa turn on the lights Here are the supported MQT lights schemas So there are plenty of things that you can do of course the most simple is just to set the color of the RGB LAD strip. So here is an example. I have a board again with ESP 8266 Which communicates with home assistant over imputed? Here is an example with the command topic in red on the first line is the Example identification of the device So the payload is the cover RGB values for the cover and when you send this payload the Internet of think in this case would receive the message through the broker and set the cover that you want and There are a couple of photos. The first photo is the plane configuration where you just have The this Internet of things think Controlling 12 volt RGB led strip This is the most simple and non-addressable LAD strip that you can find on the market and in the other setup is with Alexa so that you can turn it on and off with voice commands So far we've covered home assistant and the convention that home assistant defines for MQT components I'm personally a huge fan of home assistant convention primarily because I'm I have been using it for a while So I'm used to it. However In the open source world other convention exists and one of those conventions is the homey convention It does exactly the same thing define a Standard format of the MQT payload so that various internet of things can follow it to integrate together It has been started in 2015 it exists in the github. Everything is there. It has a very good documentation Again, there is a specific from format of the configuration in QTT topic with which you can Again implement an automatic discovery of the device here. You get have an identification of the physical device A node and of course a specific property The paywall and the QTT message It can be one of the following value types It can be a string integer float boolean anum or a cower Of course cower is the most interesting because there are a lot of things that you can adjust in the cower a quick example again it's It's pretty much the same example that you've already seen with the convention defined by home assistant This is with the homey convention again We have a specific topic according to the convention and the payload is the actual value So open up to is another open source home automation platform Which uses? Both the home assistant and the homey convention. How many of you are using open up? Just a few of you. All right. I'm personally using both Open up and home assistant. I used it for a while But I plan to continue doing it after a few months So open hub is particularly popular in Europe It's a it's an old project. It's written in Java They have been major changes between open hub version one and two and since version 2.5. There's an excellent 2.4. There's an excellent support for impunity. There are a lot of supported things Thousands of supported things a big community again Open up to can be installed pretty much on any machine that runs Java including Microsoft Windows Mac OS and Linux distributions. Of course, it's another distribution that's perfect to run on Raspberry Pi There are also mobile applications for Android and iOS. This is an advantage compared to some of the other open source systems out there So open up to supports both the homey convention and the home assistant You have the option to select which one of those conventions to use the process for adding MQT broker in Internet of Things in In open hub is easy. Here are a few Slides you can how you can do it you define the broker this way open hubs connect to this broker after that You define the Internet of Things or discover them manually or discover them automatically these slides are Explaining how you can do this manually Last but not least the mottics. It's another popular open source home automation platform It's written in C++ again perfect to run on my favorite Raspberry Pi started seven years ago The source code is available in GitHub However, the support for MQT in the mottics. It's a little bit more tricky because basically you have two topics Two default topics the mottics in and the mottics out So this is how the mottics communicates with all devices within that your network over in QtD It's compared to to the other two that examples that we already had reviewed I don't think this is so convenient. However, they have a good documentation which you have a look You can have a look for details So now I would like to show you a quick demo Second so these are two videos pre-corded videos. All right, this is how I configure Hasayo, this is This is installation a raspberry pi zero in general It's not a good idea to implement it on a raspberry pi zero, but I have done it It's not a good idea because it runs slowly. It's okay for testing However, you better use raspberry pi 3 or a 3b or b plus This is implementation of The Wi-Fi manager library for Arduino very popular library that creates an access point on your internet a thing and provides you a user-friendly interface on your smartphone Personal computer or tablet so that you can connect to the device and set credentials to the MQT broker for later on and You select your Wi-Fi network and also the MQT broker and It also provides you information about the device ID Once you have connected your internet a thing to the network and home assistant You need to do the integration which means to because The first thing that you saw was installation of the mosquito broker then you need to do the installation The integration of MQT. I'm doing it right here typing in the IP of the broker in my In my network The username and the password here is enable discovery They work out from the first time even on the video However, I didn't cut it out because I'll show you the real thing Once the discovery is done automatically you see the device that has been already configured so you just press finish and It will appear in your network over here. Yeah, and you can follow the temperature and This is just a quick test to show that yeah, actually this sensor works You can see here the Raspberry Pi the sensor itself and a hairdryer Perfect setup on the other in the other demonstration and the other demonstration is with open hop It's similar procedure. However, I'm doing the steps manually here to add the device again Adding the MQT binding before that I have installed mosquito as a broker Although open hop is coming with moquette, which is an implement another implementation of MQT broker But as I told you during the slides I prefer Prefer Mosquito again the standard configurations for the broker the port of the broker one thing I didn't mention but it's important the brokers most of the brokers also support WebSocket communication so you can receive and publish and Qt message is directly from your HTML five pages nowadays Now I'm adding here JavaScript transformation Well, this transformation is used to transform the data for between Farahar and Celsius to make it More user-friendly in the home assistant In the home assistant sorry in the open hop user interface In the particular particular demonstration I'm using the paper UI because open hop provides several user interfaces and you can switch between them This is how I installed the JavaScript that does the transformation and finally, I'm adding the generic thing Just just to repeat that open hop also supports automatic discovery But this is just a different approach because I want to show you what is happening If you decide to do it manually Now these are the the channels for the temperature and humidity on which we will receive data and The bridge of course is the MQT broker So I'm here receiving setting that I'm gonna receive a text value and after that the JavaScript transformation that I have already Installed will take care to transform this value in the value that I want to be properly represented in Open hop interface I'm showing you all this to show you that actually if you have An option for automatic discovery for the end user. It's far easier to do this approach Let's switch back to the slides a Few conclusions, so obviously MQT is a great Protocol for new real communication between machines However, we need a convention to to make sure that we can integrate various devices from various vendors in various open source platforms home assistant Already has This convention done also homie of course these can conventions are evolving over the time The automatic discovery of devices is one of the I would call keyword features for internet of things because this makes things easier for end users Thank you very much These are a few useful Links all the slides are already available. We're a little bit ahead of schedule But this is the last talk in this room. So if you have any questions, I would love to hear them You