{"id":20297,"date":"2023-03-16T05:00:00","date_gmt":"2023-03-16T04:00:00","guid":{"rendered":"https:\/\/sii.pl\/blog\/?p=20297&#038;category=hard-development"},"modified":"2023-03-14T13:34:47","modified_gmt":"2023-03-14T12:34:47","slug":"how-to-turn-an-ordinary-device-into-a-smart-one","status":"publish","type":"post","link":"https:\/\/sii.pl\/blog\/en\/how-to-turn-an-ordinary-device-into-a-smart-one\/","title":{"rendered":"How to turn an ordinary device into a SMART one?"},"content":{"rendered":"\n<p>As you may remember from the <a href=\"https:\/\/sii.pl\/blog\/en\/smart-home-in-the-open-source-version-how-i-built-a-smart-home\/?category=soft-development&amp;tag=iot-en,after-hours-project-2,smart-home-2,open-source-2,iot-2\" target=\"_blank\" aria-label=\" (opens in a new tab)\" rel=\"noreferrer noopener\" class=\"ek-link\">previous article<\/a> I have changed, using open-source tools and with a minimal financial cost, an ordinary lightning into SMART lightning in my home. When I saw how many benefits I got out of it, I decided it wouldn&#8217;t be the last thing I did.<\/p>\n\n\n\n<p>In this text I will focus on turning a not-yet-smart device into a smart one! I&#8217;ll take care of the device that at my place has been on non-stop for several months and I can&#8217;t imagine not having it. The 4-in-1 sterilizer! If you are a parent, you know what I am writing about \ud83d\ude00<\/p>\n\n\n\n<p>From this article you will learn i.e.:<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li>why I wanted o change a sterilizer into a smart device<\/li><li>what I need to have a smart device<\/li><li>what element turns an ordinary device into a smart one<\/li><li>how integration between apps works<\/li><li>what is the power consumption in time<\/li><li>about the algorithm<\/li><li>about the sterilization operation algorithm and sending a notification to the phone<\/li><\/ul>\n\n\n\n<p>Before I move on, I will reveal what I&#8217;ve changed in my home since <a href=\"https:\/\/sii.pl\/blog\/en\/smart-home-in-the-open-source-version-how-i-built-a-smart-home\/?category=soft-development&amp;tag=iot-en,after-hours-project-2,smart-home-2,open-source-2,iot-2\" target=\"_blank\" aria-label=\" (opens in a new tab)\" rel=\"noreferrer noopener\" class=\"ek-link\">the last article<\/a> to make it smarter. Well, the bathroom fan turns on\/off depending on the humidity (here I relied on the deviation and delta from recent measurements), I control the humidifier via my phone (I did reverse engineering), and the washing machine tells me when the laundry is done.<\/p>\n\n\n\n<p>Every modification mentioned could be easily described in a separate article. With each one I had a lot of problems: from writing a correct algorithm, to readings and bypassing interference from devices.<\/p>\n\n\n\n<p>All of them involved many emotions: from frustration to excitement. If you want me to share my adventures \u2013 leave a comment and write, what interests you \ud83d\ude0a<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><strong><strong>Why did I want to change a sterilizer into a smart device?<\/strong><\/strong><\/h2>\n\n\n\n<p>With an infant, a person is task-oriented. As they complete all the tasks, they want a peace of mind and the right amount of sleep. And if they forget something &#8211; this harmony is disturbed. That&#8217;s why, if I can, I use automation to make my life easier and take advantage of the devices I have. I own a Neno 4-in-1 sterilizer.<\/p>\n\n\n\n<p>Mainly I use 3 functions:<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li>heating up milk\/food<\/li><li>defrosting food<\/li><li>sterilization.<\/li><\/ul>\n\n\n\n<p>And while I don\u2019t forget about the heating, I ALWAYS forget about the end of the sterilization, and I have to sterilize the same thing again, which results in going to bed at 11.30 p.m. or later, not at 10.00 p.m. \ud83d\ude09 I thought that I always have my phone with me, so it would be useful if notifications regarding the end of sterilization were sent from the device to my phone. How much time I could save with it!<\/p>\n\n\n\n<p>And that was my first goal \u2013 sending a notification from the device to my phone.<\/p>\n\n\n\n<p><strong>Spoiler alert:<\/strong> as of the date of writing this article, I can already control the sterilizer by phone (both as a separate module and from the level of notifications), which required hardware change. However, I will focus on one functionality here.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>What do I need to have a smart device?<\/strong><\/h2>\n\n\n\n<p>To turn this device into a smart one, you have to change the hardware or add a physical component that will monitor the device\u2019s operation and send information. As I wanted to do it <strong>well, quickly and cheaply<\/strong>, I have chosen the second solution.<\/p>\n\n\n\n<p>Changes that needed to happen:<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li>purchase of a device, which can monitor the power consumed by the target device and send data,<\/li><li>proper integration of the device and the app, so that I have access to the data,<\/li><li>understanding the logs, to see what is being sen from the monitoring device,<\/li><li>Creation of an algorithm responsible for sending the notifications to the phone.<br><\/li><\/ul>\n\n\n\n<p>As you already know from the <a href=\"https:\/\/sii.pl\/blog\/en\/smart-home-in-the-open-source-version-how-i-built-a-smart-home\/?category=soft-development&amp;tag=iot-en,after-hours-project-2,smart-home-2,open-source-2,iot-2\" target=\"_blank\" aria-label=\" (opens in a new tab)\" rel=\"noreferrer noopener\" class=\"ek-link\">previous article<\/a>, I am mostly interested in the Zigbee protocol, and I use 4 apps to control the Smart Home:<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li>HomeAssistant,<\/li><li>Node-RED,<\/li><li>Zigbee2MQTT,<\/li><li>Mosquito.<\/li><\/ul>\n\n\n\n<h2 class=\"wp-block-heading\"><strong><strong>An element that turns ordinary devices into smart ones<\/strong><\/strong><\/h2>\n\n\n\n<p>Let\u2019s begin with the first point. There are various solutions available on the market, but the simplest is to buy a socket-plug. For me, the choice was: a Zigbee 16A plug from the company RTX.<\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter size-full is-resized\"><a href=\"https:\/\/sii.pl\/blog\/wp-content\/uploads\/2023\/03\/1-2.png\"><img decoding=\"async\" src=\"https:\/\/sii.pl\/blog\/wp-content\/uploads\/2023\/03\/1-2.png\" alt=\"ZigBee 16A plug\" class=\"wp-image-20132\" width=\"413\" height=\"346\" srcset=\"https:\/\/sii.pl\/blog\/wp-content\/uploads\/2023\/03\/1-2.png 649w, https:\/\/sii.pl\/blog\/wp-content\/uploads\/2023\/03\/1-2-300x251.png 300w\" sizes=\"(max-width: 413px) 100vw, 413px\" \/><\/a><figcaption>Fig. 1 Zigbee 16A plug<\/figcaption><\/figure><\/div>\n\n\n\n<p>There are plugs on the market that have both WiFi and Zigbee connection, but I am only interested in the Zigbee protocol. Additionally, at the time of the purchase, the price was 49 PLN.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>Integration with apps<\/strong><\/h2>\n\n\n\n<p>The integration with the sterilizer is easy \u2013 you simply put the plug between the socket and the device. In order for the data to be visible in the app, you need to properly configure the Zigbee2MQTT with the socket.<\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter size-large\"><a href=\"https:\/\/sii.pl\/blog\/wp-content\/uploads\/2023\/03\/2-2.png\"><img decoding=\"async\" width=\"1024\" height=\"64\" src=\"https:\/\/sii.pl\/blog\/wp-content\/uploads\/2023\/03\/2-2-1024x64.png\" alt=\"Zigbee2MQTT configuration\" class=\"wp-image-20134\" srcset=\"https:\/\/sii.pl\/blog\/wp-content\/uploads\/2023\/03\/2-2-1024x64.png 1024w, https:\/\/sii.pl\/blog\/wp-content\/uploads\/2023\/03\/2-2-300x19.png 300w, https:\/\/sii.pl\/blog\/wp-content\/uploads\/2023\/03\/2-2-768x48.png 768w, https:\/\/sii.pl\/blog\/wp-content\/uploads\/2023\/03\/2-2-1536x96.png 1536w, https:\/\/sii.pl\/blog\/wp-content\/uploads\/2023\/03\/2-2.png 1762w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/a><figcaption>Fig. 2 Zigbee2MQTT configuration<\/figcaption><\/figure><\/div>\n\n\n\n<p>By looking at the logs in Zigbee2MqTT, I could see what information is being sent and which of it I can use to accomplish my goal.<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><a href=\"https:\/\/sii.pl\/blog\/wp-content\/uploads\/2023\/03\/3-2.png\"><img decoding=\"async\" width=\"1024\" height=\"82\" src=\"https:\/\/sii.pl\/blog\/wp-content\/uploads\/2023\/03\/3-2-1024x82.png\" alt=\"Logs in Zigbee2MQTT\" class=\"wp-image-20136\" srcset=\"https:\/\/sii.pl\/blog\/wp-content\/uploads\/2023\/03\/3-2-1024x82.png 1024w, https:\/\/sii.pl\/blog\/wp-content\/uploads\/2023\/03\/3-2-300x24.png 300w, https:\/\/sii.pl\/blog\/wp-content\/uploads\/2023\/03\/3-2-768x61.png 768w, https:\/\/sii.pl\/blog\/wp-content\/uploads\/2023\/03\/3-2.png 1224w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/a><figcaption>Fig. 3 Logs in Zigbee2MQTT<\/figcaption><\/figure>\n\n\n\n<p>For me, the most important information is located below the <em>power<\/em> parameter. It is the amount of electric energy used in a given moment [expressed in watts]. After the configuration, the plug connected to the sterilizer should be visible both in the HomeAssistant app and in Node-RED.<\/p>\n\n\n\n<p>So, it is time to see how the sterilizer behaves in two modes:<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li>heating food,<\/li><li>sterilization.<a><\/a><\/li><\/ul>\n\n\n\n<h2 class=\"wp-block-heading\"><strong><strong>Analysis of the power consumption by the device, that is how much power the device draws<\/strong><\/strong><\/h2>\n\n\n\n<p>You can check the power consumption either in individual logs in Zigbee2MQTT or in the history of the HomeAssistant app, where you will find a chart. I have chosen the chart. Entering the device history and selecting a specified time frame, I checked the operation characteristics of the sterilizer. The vertical axis indicates the amount of electricity [W], the horizontal axis the hour.<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><a href=\"https:\/\/sii.pl\/blog\/wp-content\/uploads\/2023\/03\/4-1.png\"><img decoding=\"async\" width=\"1024\" height=\"322\" src=\"https:\/\/sii.pl\/blog\/wp-content\/uploads\/2023\/03\/4-1-1024x322.png\" alt=\"Power consumption in time\" class=\"wp-image-20138\" srcset=\"https:\/\/sii.pl\/blog\/wp-content\/uploads\/2023\/03\/4-1-1024x322.png 1024w, https:\/\/sii.pl\/blog\/wp-content\/uploads\/2023\/03\/4-1-300x94.png 300w, https:\/\/sii.pl\/blog\/wp-content\/uploads\/2023\/03\/4-1-768x241.png 768w, https:\/\/sii.pl\/blog\/wp-content\/uploads\/2023\/03\/4-1-1536x483.png 1536w, https:\/\/sii.pl\/blog\/wp-content\/uploads\/2023\/03\/4-1.png 1565w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/a><figcaption>Fig. 4 Power consumption in time<\/figcaption><\/figure>\n\n\n\n<p>What was happening during these time frames? I turned on the device only at about 6.20 p.m., so the water in it was in a room temperature. Then, I turned on the food heating function. I didn\u2019t turn off the sterilizer after taking out the bottle, and around 8.40 p.m. I began sterilizing the bottles.<\/p>\n\n\n\n<p>To sum up: between 6.20 p.m. and 2.00 a.m. 2 functions were used:<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li>heating\/maintaining the water at 40 degrees C,<\/li><li>sterilization, where water is heated to 100 degrees C, and then maintained at this temperature for 10 minutes.<br><br>Can you guess which bar is responsible for what? Let\u2019s take a closer look.<\/li><\/ul>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>Heating<\/strong><\/h3>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter size-full\"><a href=\"https:\/\/sii.pl\/blog\/wp-content\/uploads\/2023\/03\/5-1.png\"><img decoding=\"async\" width=\"870\" height=\"476\" src=\"https:\/\/sii.pl\/blog\/wp-content\/uploads\/2023\/03\/5-1.png\" alt=\"Zu\u017cycie energii podczas podgrzewania\" class=\"wp-image-20141\" srcset=\"https:\/\/sii.pl\/blog\/wp-content\/uploads\/2023\/03\/5-1.png 870w, https:\/\/sii.pl\/blog\/wp-content\/uploads\/2023\/03\/5-1-300x164.png 300w, https:\/\/sii.pl\/blog\/wp-content\/uploads\/2023\/03\/5-1-768x420.png 768w\" sizes=\"(max-width: 870px) 100vw, 870px\" \/><\/a><figcaption>Fig. 5 Power consumption while heating<\/figcaption><\/figure><\/div>\n\n\n\n<p>In the chart between 6.20 p.m. and 6.40 p.m., you can see that when you turn on the device, in which the water temperature is less than 40 degrees C, the water is heated to that temperature. The power consumption is about 238 W. To maintain the temperature between 7 p.m. and 8.30 p.m., the device heats the water every 10 minutes with the power of 118 watts for a time of 2.5 minutes. Additionally, you can see the unstable state during the switch (something similar to electrical noise) around 7.20, 7.30 and 7.55 p.m.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>Sterilization<\/strong><\/h3>\n\n\n\n<p>Depending on what the water temperature in the device is, the duration of the cycle may vary. It is best seen up close:<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><a href=\"https:\/\/sii.pl\/blog\/wp-content\/uploads\/2023\/03\/6-1.png\"><img decoding=\"async\" width=\"871\" height=\"481\" src=\"https:\/\/sii.pl\/blog\/wp-content\/uploads\/2023\/03\/6-1.png\" alt=\"Zu\u017cycie energii podczas sterylizacji\" class=\"wp-image-20143\" srcset=\"https:\/\/sii.pl\/blog\/wp-content\/uploads\/2023\/03\/6-1.png 871w, https:\/\/sii.pl\/blog\/wp-content\/uploads\/2023\/03\/6-1-300x166.png 300w, https:\/\/sii.pl\/blog\/wp-content\/uploads\/2023\/03\/6-1-768x424.png 768w\" sizes=\"(max-width: 871px) 100vw, 871px\" \/><\/a><figcaption>Fig. 6 Power consumption during sterilization<\/figcaption><\/figure>\n\n\n\n<p>It can be noted that around 10.00 p.m. the water was cold enough that the sterilizer needed more time to complete the sterilization cycle. At 10.28 p.m. (that is about 7 minutes after the last action), the device needed less time to perform its function. In addition, for the device to work in the sterilization function, it needs about 473 watts for a longer time.<\/p>\n\n\n\n<p>Thanks to the analysis above, a pattern can be seen, which will be helpful to create an algorithm to send notifications when the sterilization is completed.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><strong><strong>The algorithm of sterilization operation and sending notifications to the phone<\/strong><\/strong><\/h2>\n\n\n\n<p>We now know how much power the device consumes for specific actions and for how long. So let\u2019s plan out what we will additionally need, to conclude that the sterilization has been completed.<\/p>\n\n\n\n<p>My plan was to collect information from the last 4 minutes and check, whether the power value was higher than 400 W for a longer time, and after that changed to 0. And that was a good plan! If only I had an assurance that the device sends such information every X seconds. However, after analyzing<\/p>\n\n\n\n<p>logs from Zigbee2MQTT, it turned out that the plug sends information once every 2 seconds, and another time every 2 minutes. Regardless of whether the device is on, sterilizing or heating.<\/p>\n\n\n\n<p>So, instead of relying on the time buffer, I chose the option: last 10 results. As you know, I like automation in Node-RED and here I have also used this app to create such an algorithm. The finished algorithm:<\/p>\n\n\n\n<figure class=\"wp-block-image size-large is-resized\"><a href=\"https:\/\/sii.pl\/blog\/wp-content\/uploads\/2023\/03\/6a.png\"><img decoding=\"async\" src=\"https:\/\/sii.pl\/blog\/wp-content\/uploads\/2023\/03\/6a-1024x175.png\" alt=\"Algorithm in Node-RED\" class=\"wp-image-20145\" width=\"840\" height=\"143\" srcset=\"https:\/\/sii.pl\/blog\/wp-content\/uploads\/2023\/03\/6a-1024x175.png 1024w, https:\/\/sii.pl\/blog\/wp-content\/uploads\/2023\/03\/6a-300x51.png 300w, https:\/\/sii.pl\/blog\/wp-content\/uploads\/2023\/03\/6a-768x131.png 768w, https:\/\/sii.pl\/blog\/wp-content\/uploads\/2023\/03\/6a.png 1221w\" sizes=\"(max-width: 840px) 100vw, 840px\" \/><\/a><figcaption>Fig. 7 Algorithm in Node-RED<\/figcaption><\/figure>\n\n\n\n<p>Already knowing what the main assumptions are, it is time to think about <strong>what can go wrong<\/strong>.<\/p>\n\n\n\n<p>A good tester looks right away at the boundary values, before moving on to implementation, as electrical noises can occur (I recommend learning about the debouncing occurrence). Fortunately it is a known phenomenon and it can be easily reduced in the automation app. Next, on the basis of a value we should detect a change of state. If for 40 minutes the power consumption is at 473 watts, or if there are fluctuations in power consumption, it can already be concluded that this is not the right parameter. But the time unit indeed is.<\/p>\n\n\n\n<p>The last issue is this: how we will calculate whether the change of state was momentary (e.g. momentary power drop) or whether the action has been completed. It will be programmed in the state calculation function.<\/p>\n\n\n\n<p>We know what needs to be done, we are aware of what can go wrong, <strong>so let\u2019s move on to the specifics!<\/strong><\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>Actions step-by-step<\/strong><\/h2>\n\n\n\n<p>Information from the plug is sent to Zigbee2MQTT, so Node-RED should be configured to be able to use it. In the app I have several operations adapter to Zigbee2MQTT.<\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter size-full\"><a href=\"https:\/\/sii.pl\/blog\/wp-content\/uploads\/2023\/03\/7-1.png\"><img decoding=\"async\" width=\"157\" height=\"227\" src=\"https:\/\/sii.pl\/blog\/wp-content\/uploads\/2023\/03\/7-1.png\" alt=\"Devices configuration\" class=\"wp-image-20147\"\/><\/a><figcaption>Fig. 8 Devices configuration<\/figcaption><\/figure><\/div>\n\n\n\n<p>At the moment of configuration I am interested in the IN operation, which is responsible for retrieving the messages from the queue. The figure below shows the activity configuration.<\/p>\n\n\n\n<p>The most important aspects are: server (in my case called Mosquito), device (Sterylizator(TS011F_plug_1)), and then specifying what interesting we can pull out of the logs. In this case I have chosen the power parameter.<\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter size-full is-resized\"><a href=\"https:\/\/sii.pl\/blog\/wp-content\/uploads\/2023\/03\/8-1.png\"><img decoding=\"async\" src=\"https:\/\/sii.pl\/blog\/wp-content\/uploads\/2023\/03\/8-1.png\" alt=\"Activity configuration\" class=\"wp-image-20149\" width=\"575\" height=\"539\" srcset=\"https:\/\/sii.pl\/blog\/wp-content\/uploads\/2023\/03\/8-1.png 575w, https:\/\/sii.pl\/blog\/wp-content\/uploads\/2023\/03\/8-1-300x281.png 300w\" sizes=\"(max-width: 575px) 100vw, 575px\" \/><\/a><figcaption>Fig. 9 Activity configuration<\/figcaption><\/figure><\/div>\n\n\n\n<p>As I wanted to rely on the time parameter in the further steps, it was necessary to modify the forwarded message. Using the function operation and JavaScript, I have replaced the message.<\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter size-full\"><a href=\"https:\/\/sii.pl\/blog\/wp-content\/uploads\/2023\/03\/9-1.png\"><img decoding=\"async\" width=\"209\" height=\"53\" src=\"https:\/\/sii.pl\/blog\/wp-content\/uploads\/2023\/03\/9-1.png\" alt=\"prepare payload\" class=\"wp-image-20151\"\/><\/a><\/figure><\/div>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter size-full\"><a href=\"https:\/\/sii.pl\/blog\/wp-content\/uploads\/2023\/03\/10-1.png\"><img decoding=\"async\" width=\"774\" height=\"317\" src=\"https:\/\/sii.pl\/blog\/wp-content\/uploads\/2023\/03\/10-1.png\" alt=\"Message replacement\" class=\"wp-image-20153\" srcset=\"https:\/\/sii.pl\/blog\/wp-content\/uploads\/2023\/03\/10-1.png 774w, https:\/\/sii.pl\/blog\/wp-content\/uploads\/2023\/03\/10-1-300x123.png 300w, https:\/\/sii.pl\/blog\/wp-content\/uploads\/2023\/03\/10-1-768x315.png 768w\" sizes=\"(max-width: 774px) 100vw, 774px\" \/><\/a><figcaption>Fig. 10 Message replacement<\/figcaption><\/figure><\/div>\n\n\n\n<p>Deciphering the code above:<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li>I am creating a new message with a specific body,<\/li><li>I am creating 3 parameters:<ul><li>power,<\/li><li>timestamp,<\/li><li>timechanges.<\/li><\/ul><\/li><\/ul>\n\n\n\n<p>The most interesting one may be timechanges. It is a parameter, which will be used in the next step and is responsible for the elimination of events excess.<\/p>\n\n\n\n<p>The next step is debounce, which is the reduction of electrical noise. I will rely on the created timechanges parameter in it.<\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter size-full\"><a href=\"https:\/\/sii.pl\/blog\/wp-content\/uploads\/2023\/03\/11-1.png\"><img decoding=\"async\" width=\"199\" height=\"68\" src=\"https:\/\/sii.pl\/blog\/wp-content\/uploads\/2023\/03\/11-1.png\" alt=\"Debounce\" class=\"wp-image-20155\"\/><\/a><\/figure><\/div>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter size-full\"><a href=\"https:\/\/sii.pl\/blog\/wp-content\/uploads\/2023\/03\/12-1.png\"><img decoding=\"async\" width=\"495\" height=\"252\" src=\"https:\/\/sii.pl\/blog\/wp-content\/uploads\/2023\/03\/12-1.png\" alt=\"Zmniejszenie szumu elektrycznego i parametr timechanges\" class=\"wp-image-20157\" srcset=\"https:\/\/sii.pl\/blog\/wp-content\/uploads\/2023\/03\/12-1.png 495w, https:\/\/sii.pl\/blog\/wp-content\/uploads\/2023\/03\/12-1-300x153.png 300w\" sizes=\"(max-width: 495px) 100vw, 495px\" \/><\/a><figcaption>Fig. 11 Electrical noise reduction and timechanges parameter<\/figcaption><\/figure><\/div>\n\n\n\n<p>This way I am taking into account the message from the sterilizer that is no younger than 10 seconds from the last one. Having already determined, which values are important to me and what should be their frequency, I move on to the subject of storing them in temporary memory. I choose the last 10.<\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter size-full is-resized\"><a href=\"https:\/\/sii.pl\/blog\/wp-content\/uploads\/2023\/03\/13-1.png\"><img decoding=\"async\" src=\"https:\/\/sii.pl\/blog\/wp-content\/uploads\/2023\/03\/13-1.png\" alt=\"\" class=\"wp-image-20159\" width=\"141\" height=\"55\"\/><\/a><\/figure><\/div>\n\n\n\n<p>With the configuration above, these are the results after at least 100 seconds. Therefore, time sufficient to determine whether the sterilization has been completer or not.<\/p>\n\n\n\n<p>Already having data, on which it is possible to perform computational operations, I can use the function operation again and write a function in JavaScript that will check whether the last message contains a value for the power parameter equal to 0. As you remember from the chart, such a value is sent when the device has stopped working.<\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter size-full\"><a href=\"https:\/\/sii.pl\/blog\/wp-content\/uploads\/2023\/03\/14.png\"><img decoding=\"async\" width=\"768\" height=\"401\" src=\"https:\/\/sii.pl\/blog\/wp-content\/uploads\/2023\/03\/14.png\" alt=\"Sprawdzanie parametru power\" class=\"wp-image-20161\" srcset=\"https:\/\/sii.pl\/blog\/wp-content\/uploads\/2023\/03\/14.png 768w, https:\/\/sii.pl\/blog\/wp-content\/uploads\/2023\/03\/14-300x157.png 300w\" sizes=\"(max-width: 768px) 100vw, 768px\" \/><\/a><figcaption>Fig. 12 Checking the power parameter<\/figcaption><\/figure><\/div>\n\n\n\n<p>Describing the code above:<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li>I am saving the last result from the temporary memory,<\/li><li>if it is equal to 0, I am checking for how many elements the power was higher than 400 W,<\/li><li>if the power was higher, I am adding +1 to the temporary parameter,<\/li><li>I am summing up how many results match the above-mentioned criteria,<\/li><li>if at least 6 logs match the criteria, I am setting a new message to forward,<\/li><li>otherwise, it returns nothing to me. Thanks to that no notification would go any further.<\/li><\/ul>\n\n\n\n<p>The last step is <strong>sending the message to the phone<\/strong>. With the help of the HomeAssistant plug-in for the Node-RED app, I have an operation called cell service, which allows sending a notification to HomeAssistant. Thanks to that, and installing the HomeAssistand app on my phone, I will reach my goal!<\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter size-full\"><a href=\"https:\/\/sii.pl\/blog\/wp-content\/uploads\/2023\/03\/15.png\"><img decoding=\"async\" width=\"255\" height=\"68\" src=\"https:\/\/sii.pl\/blog\/wp-content\/uploads\/2023\/03\/15.png\" alt=\"sterilization state\" class=\"wp-image-20164\"\/><\/a><\/figure><\/div>\n\n\n\n<figure class=\"wp-block-image size-large\"><a href=\"https:\/\/sii.pl\/blog\/wp-content\/uploads\/2023\/03\/16.png\"><img decoding=\"async\" width=\"1024\" height=\"425\" src=\"https:\/\/sii.pl\/blog\/wp-content\/uploads\/2023\/03\/16-1024x425.png\" alt=\"Activity configuration\" class=\"wp-image-20166\" srcset=\"https:\/\/sii.pl\/blog\/wp-content\/uploads\/2023\/03\/16-1024x425.png 1024w, https:\/\/sii.pl\/blog\/wp-content\/uploads\/2023\/03\/16-300x125.png 300w, https:\/\/sii.pl\/blog\/wp-content\/uploads\/2023\/03\/16-768x319.png 768w, https:\/\/sii.pl\/blog\/wp-content\/uploads\/2023\/03\/16.png 1083w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/a><figcaption>Fig. 13 Activity configuration<\/figcaption><\/figure>\n\n\n\n<p>With the data contained in the Data parameter, I control what will be displayed on the phone.<\/p>\n\n\n\n<p>And now, time for the last step! <strong>A screenshot after the completed sterilization.<\/strong><\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter size-large is-resized\"><a href=\"https:\/\/sii.pl\/blog\/wp-content\/uploads\/2023\/03\/17.jpg\"><img decoding=\"async\" src=\"https:\/\/sii.pl\/blog\/wp-content\/uploads\/2023\/03\/17-1024x1004.jpg\" alt=\"Sterilization completion\" class=\"wp-image-20168\" width=\"499\" height=\"489\" srcset=\"https:\/\/sii.pl\/blog\/wp-content\/uploads\/2023\/03\/17-1024x1004.jpg 1024w, https:\/\/sii.pl\/blog\/wp-content\/uploads\/2023\/03\/17-300x294.jpg 300w, https:\/\/sii.pl\/blog\/wp-content\/uploads\/2023\/03\/17-768x753.jpg 768w, https:\/\/sii.pl\/blog\/wp-content\/uploads\/2023\/03\/17.jpg 1080w\" sizes=\"(max-width: 499px) 100vw, 499px\" \/><\/a><figcaption>Fig. 14 Sterilization completion<\/figcaption><\/figure><\/div>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>Summary<\/strong><\/h2>\n\n\n\n<p>The goal has been achieved. The article above described an instruction for the device and apps configuration and the decision-making process, so that the notification about the completion of sterilization can be sent. Now I can confidently say that I have another smart device. Additionally, thanks to the information sent in the logs, I know exactly how much power the device consumes. And that\u2019s that! \ud83d\ude0a<\/p>\n\n\n\n<p>However, to have an even smarter device, able to control turning on specific programs, I had to hack the hardware. For this, I could have used the NodeMCU module or, known from the previous article, successful one-time purchase of CC2531.<\/p>\n\n\n\n<p>Who knows, who knows \ud83d\ude00<\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter size-large is-resized\"><a href=\"https:\/\/sii.pl\/blog\/wp-content\/uploads\/2023\/03\/18.jpg\"><img decoding=\"async\" src=\"https:\/\/sii.pl\/blog\/wp-content\/uploads\/2023\/03\/18-1024x768.jpg\" alt=\"Tajemnica na koniec \ud83d\ude09\" class=\"wp-image-20170\" width=\"591\" height=\"443\" srcset=\"https:\/\/sii.pl\/blog\/wp-content\/uploads\/2023\/03\/18-1024x768.jpg 1024w, https:\/\/sii.pl\/blog\/wp-content\/uploads\/2023\/03\/18-300x225.jpg 300w, https:\/\/sii.pl\/blog\/wp-content\/uploads\/2023\/03\/18-768x576.jpg 768w, https:\/\/sii.pl\/blog\/wp-content\/uploads\/2023\/03\/18-1536x1152.jpg 1536w, https:\/\/sii.pl\/blog\/wp-content\/uploads\/2023\/03\/18.jpg 2048w\" sizes=\"(max-width: 591px) 100vw, 591px\" \/><\/a><figcaption>Fig. 15 Secret at the end \ud83d\ude09<\/figcaption><\/figure><\/div>\n\n\n\n<p>Would an article about hardware change and creation of more algorithms be interesting to you? Let me know in the comments! \ud83d\ude0a<\/p>\n\n\n<div class=\"kk-star-ratings kksr-auto kksr-align-left kksr-valign-bottom\"\n    data-payload='{&quot;align&quot;:&quot;left&quot;,&quot;id&quot;:&quot;20297&quot;,&quot;slug&quot;:&quot;default&quot;,&quot;valign&quot;:&quot;bottom&quot;,&quot;ignore&quot;:&quot;&quot;,&quot;reference&quot;:&quot;auto&quot;,&quot;class&quot;:&quot;&quot;,&quot;count&quot;:&quot;3&quot;,&quot;legendonly&quot;:&quot;&quot;,&quot;readonly&quot;:&quot;&quot;,&quot;score&quot;:&quot;5&quot;,&quot;starsonly&quot;:&quot;&quot;,&quot;best&quot;:&quot;5&quot;,&quot;gap&quot;:&quot;11&quot;,&quot;greet&quot;:&quot;&quot;,&quot;legend&quot;:&quot;5\\\/5 ( votes: 3)&quot;,&quot;size&quot;:&quot;18&quot;,&quot;title&quot;:&quot;How to turn an ordinary device into a SMART one?&quot;,&quot;width&quot;:&quot;139.5&quot;,&quot;_legend&quot;:&quot;{score}\\\/{best} ( {votes}: {count})&quot;,&quot;font_factor&quot;:&quot;1.25&quot;}'>\n            \n<div class=\"kksr-stars\">\n    \n<div class=\"kksr-stars-inactive\">\n            <div class=\"kksr-star\" data-star=\"1\" style=\"padding-right: 11px\">\n            \n\n<div class=\"kksr-icon\" style=\"width: 18px; height: 18px;\"><\/div>\n        <\/div>\n            <div class=\"kksr-star\" data-star=\"2\" style=\"padding-right: 11px\">\n            \n\n<div class=\"kksr-icon\" style=\"width: 18px; height: 18px;\"><\/div>\n        <\/div>\n            <div class=\"kksr-star\" data-star=\"3\" style=\"padding-right: 11px\">\n            \n\n<div class=\"kksr-icon\" style=\"width: 18px; height: 18px;\"><\/div>\n        <\/div>\n            <div class=\"kksr-star\" data-star=\"4\" style=\"padding-right: 11px\">\n            \n\n<div class=\"kksr-icon\" style=\"width: 18px; height: 18px;\"><\/div>\n        <\/div>\n            <div class=\"kksr-star\" data-star=\"5\" style=\"padding-right: 11px\">\n            \n\n<div class=\"kksr-icon\" style=\"width: 18px; height: 18px;\"><\/div>\n        <\/div>\n    <\/div>\n    \n<div class=\"kksr-stars-active\" style=\"width: 139.5px;\">\n            <div class=\"kksr-star\" style=\"padding-right: 11px\">\n            \n\n<div class=\"kksr-icon\" style=\"width: 18px; height: 18px;\"><\/div>\n        <\/div>\n            <div class=\"kksr-star\" style=\"padding-right: 11px\">\n            \n\n<div class=\"kksr-icon\" style=\"width: 18px; height: 18px;\"><\/div>\n        <\/div>\n            <div class=\"kksr-star\" style=\"padding-right: 11px\">\n            \n\n<div class=\"kksr-icon\" style=\"width: 18px; height: 18px;\"><\/div>\n        <\/div>\n            <div class=\"kksr-star\" style=\"padding-right: 11px\">\n            \n\n<div class=\"kksr-icon\" style=\"width: 18px; height: 18px;\"><\/div>\n        <\/div>\n            <div class=\"kksr-star\" style=\"padding-right: 11px\">\n            \n\n<div class=\"kksr-icon\" style=\"width: 18px; height: 18px;\"><\/div>\n        <\/div>\n    <\/div>\n<\/div>\n                \n\n<div class=\"kksr-legend\" style=\"font-size: 14.4px;\">\n            5\/5 ( votes: 3)    <\/div>\n    <\/div>\n","protected":false},"excerpt":{"rendered":"<p>As you may remember from the previous article I have changed, using open-source tools and with a minimal financial cost, &hellip; <a class=\"continued-btn\" href=\"https:\/\/sii.pl\/blog\/en\/how-to-turn-an-ordinary-device-into-a-smart-one\/\">Continued<\/a><\/p>\n","protected":false},"author":274,"featured_media":20182,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"_editorskit_title_hidden":false,"_editorskit_reading_time":10,"_editorskit_is_block_options_detached":false,"_editorskit_block_options_position":"{}","inline_featured_image":false,"footnotes":""},"categories":[1319],"tags":[1649,1650,1651,1616,1583],"class_list":["post-20297","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-soft-development","tag-smart-home-en","tag-inteligentny-dom-en","tag-poradnik-en","tag-iot-en","tag-after-hours-project-2"],"acf":[],"aioseo_notices":[],"republish_history":[],"featured_media_url":"https:\/\/sii.pl\/blog\/wp-content\/uploads\/2023\/03\/Jak-zmienic-zwykle-urzadzenie-w-SMART.jpg","category_names":["Soft development"],"_links":{"self":[{"href":"https:\/\/sii.pl\/blog\/en\/wp-json\/wp\/v2\/posts\/20297"}],"collection":[{"href":"https:\/\/sii.pl\/blog\/en\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/sii.pl\/blog\/en\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/sii.pl\/blog\/en\/wp-json\/wp\/v2\/users\/274"}],"replies":[{"embeddable":true,"href":"https:\/\/sii.pl\/blog\/en\/wp-json\/wp\/v2\/comments?post=20297"}],"version-history":[{"count":2,"href":"https:\/\/sii.pl\/blog\/en\/wp-json\/wp\/v2\/posts\/20297\/revisions"}],"predecessor-version":[{"id":20301,"href":"https:\/\/sii.pl\/blog\/en\/wp-json\/wp\/v2\/posts\/20297\/revisions\/20301"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/sii.pl\/blog\/en\/wp-json\/wp\/v2\/media\/20182"}],"wp:attachment":[{"href":"https:\/\/sii.pl\/blog\/en\/wp-json\/wp\/v2\/media?parent=20297"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/sii.pl\/blog\/en\/wp-json\/wp\/v2\/categories?post=20297"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/sii.pl\/blog\/en\/wp-json\/wp\/v2\/tags?post=20297"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}