How to Build a Smart Home and Not Go Crazy

image

Smart furniture, which itself takes care of the order in the house, is a must-have for almost any futuristic picture. In fact, a self-regulating climate, automatic on and off lights and voice control of household appliances - all this can be configured now. But it will take a little experience, basic knowledge in the field of technology and sometimes programming, as well as a whole sea of ​​fantasy. In my case, I did so that only fantasy is enough, but first things first ...

I became interested in the idea of ​​a “smart home” about five years ago. At first I made the simplest system. She controlled the light in the corridor and the bathroom by the motion sensor, the hood by the humidity sensor, and also the weather station - at that time everyone was crazy about them. Every self-respecting DIY-box had to make a weather station.

First of all, I equipped the apartment with a controlled relay to automatically turn on the light in the corridor and bathroom. It looked like this: one sensor stood in the hallway, the second in the bathroom.

If someone went to the bathroom, then the corridor sensor detected his movement and immediately turned on the light in the corridor and in the bathroom. At the same time, if no one entered the bathroom, then this was already fixed by the sensor located inside the bathroom. After 15 seconds, the light turned off there. If a person entered the bathroom, then the light in the corridor turned off after a minute. 

I also thought over such cases if someone was thinking too much while sitting on a “white friend” in the bathroom (I had a combined bathroom). For this, the light in the bathroom was divided into two groups. One turned off 3 minutes after the sensor in the bathroom stopped detecting movements, the other after 5 minutes. So for more than five minutes to stay motionless in the bathroom in the light did not work. Very disciplining. However, you could always move your hand and continue to think about the essentials.

A humidity sensor also worked in the bathroom, which automatically started the hood if the humidity exceeded 50%. As soon as the room was ventilated to 45% humidity, the hood turned off. 

Management went - or rather tried to go - through the Arduino platform. 


Photo taken from the manufacturer's website

Almost immediately, it became clear that this platform was not entirely about creating a smart home. The main disadvantage of working with Arduino was that the platform worked without a network, and without it, no truly unified ecosystem could be obtained. Of course, I could redo the Arduino and add network support, but why? I chose a simpler path and changed this platform to another. 

Having played enough with Arduino, I reconnected the house to the ESP-8266 board. In fact, this is the same Arduino, but with Wi-Fi + it is more compact in size. This module is still popular with manufacturers of gadgets for smart homes. 


Photo taken from the Internet

In parallel, I tried to make the smart home even smarter. For example, solve the problem of round-the-clock underfloor heating or an air conditioner that is always on. For this, I bought Beok Chinese WiFi thermostats. They allowed to turn off the floor heating remotely, but had to do it through a special application in the phone. 

I solved the problem of remote control of the air conditioner using the Broadlink RM Pro infrared signal emulator. Nothing complicated: you record a signal from the air conditioning control panel to the emulator (there can be any technique controlled by the remote control), and then on the phone you press a button in the application, and the emulator plays the previously recorded signal. In the case of the air conditioner, I got the opportunity to turn it on and off, set the operation mode and set other parameters remotely.  

Also installed Livolo switches. With their help, I could also turn the lights on and off over the air. 



Of the minuses: for control, I had to install a separate application again and there was no feedback, that is, I could not see that the light was on if it was turned on or off by someone manually using a conventional switch. 

Various controlled WiFi relays such as Sonoff or Tuya and even the expensive Danalock for locking the apartment, which also required a separate application, also appeared in the house. Almost all these little things (with the exception of Danalock) I bought on the Chinese site Aliexpress, where they cost a penny and allowed me to experiment without serious investments. 

One of the first relatively serious purchases was the Tion breather. With automatic CO2 control, he more or less coped, but the temperature of the air heating in the winter constantly had to be adjusted manually. And again - to manage it was necessary to install a separate application. 


The photo was taken from the manufacturer’s website .

All the sensors and controllers that I tried then, I can’t even remember. My smartphone was clogged with applications to manage them. It was a whole zoo, which constantly had to follow. I tried to combine the management of these applications through all sorts of aggregators like HomeBridge / MajorDomo, etc. But everyone showed their significant shortcomings:

  • unfriendly interface, and sometimes just a terrible interface
  • lack of support for all used applications
  • complex connection

The search for an application for centralized management of such a volume of sensors, controllers and other control systems has not led to success. Then I tried to independently bring to mind one of the “smart” devices - the very Tion breather. I wrote a script to automatically control the heating temperature depending on the room temperature. The fact is that the ventilation system did not have an automatic adjustment of the air heating temperature. It turned out that the room was either super-hot or super-cold. There was no way to achieve a middle ground. Here, with the help of a written script and breather, this problem was solved. 

Success with a script for the breather prompted me to create my own application for managing a smart home. The main goal was to create a program with convenient integration of smart devices, multi-level automation conditions and the ability to manage all devices in the house. 

For about a year, I myself was engaged in back-end and front-end application development. 

The server side is written in NodeJS. The choice in favor of NodeJS was made due to the developed community, in which there are implemented protocols for almost all devices on the market. The client part is written in Angular (Ionic) and runs on Android / iOS. In general, the classic client-server architecture.

On a note:In the process of working on the application, I got a technical insight about the use of impurities when writing device drivers. I don’t know, maybe for some it’s elementary, but it really became easier for me to breathe.

I rewrote device drivers many times until I came to something like this:

Example code of one of the devices
import {XiaomiSubdeviceV2} from '../xiaomi.subdevice.v2';
import {load_power} from '../capabilities/load_power';
import {power_plug} from '../capabilities/power_plug';
import {PowerPurpose} from '../../base/PowerPurpose';
import {Relay} from '../../base/types/Relay';
import {HomeKitAccessory} from '../../hap/HomeKitAccessory';
import {Lightbulb2Accessory} from '../../hap/Lightbulb2Accessory';
import {Yandex} from '../../yandex/Yandex';
import {YandexLightOrSwitch} from '../../yandex/YandexLightOrSwitch';

export class LumiPlug extends XiaomiSubdeviceV2.with(Relay, power_plug, load_power, PowerPurpose,
  HomeKitAccessory, Lightbulb2Accessory,
  Yandex, YandexLightOrSwitch) {

  onCreate() {
    super.onCreate();
    this.model = 'Mi Smart Plug';
    this.class_name = 'lumi.plug';
    this.driver_name = 'Mi Smart Plug';
    this.driver_type = 3;
    this.parent_class_name = 'lumi.gateway';
  }

  getIcon() {
    return 'socket';
  }
}


The bottom line is that despite the abundance of different devices, they all do approximately the same thing and provide approximately the same information. Therefore, all the capabilities of the devices were placed in separate impurities, of which the final driver ultimately consists. For example, the application supports many devices that have the on / off function. It is made in a separate impurity and is used identically for all devices. Elementary, Watson!

What did this result in: any driver of a new device is written quite quickly and easily, because everything is standardized and there is no need to worry about further storage of the received information. For completely new protocols (which I did not have yet), impurities are also written that are based on existing ones. They already receive device information and transmit it further down the chain. This approach allowed us to reduce the amount of code by tens of times (initially, each driver was a copy of a similar driver).

So gradually I went through all the circles of hell to finish backing and the front. When the application acquired a fairly tolerable look, I thought: why not share your development with the public? Partners were found for the project and assistants to bring the application to mind. 

First of all, it was necessary to bring to mind the design of the application. To do this, I had to turn to professional designers. I naively believed that it would take 3-4 months, but in the end the process dragged on. Despite the fact that the structure of the application has not changed much from the original source, literally everything had to be redone.

In parallel, I - not alone, but with a team of project partners - bought up the most popular devices for a smart home and added an application if it did not support these gadgets. Soon, however, it became clear that there was not enough money for all smart devices, so we decided to talk with existing players in the market and agree on free test samples of equipment for free. We were not denied, and Wirenboard and MiMiSmart became the first serious suppliers.

So, together with the guys, I created a new application for smart home automation with a classic client-server architecture, which is put on any platform, and with a convenient modern design. Meet the BARY *.

* The name did not come from the name of Bari Alibasov, but from the character of Arthur C. Doyle’s book “The Hound of the Baskervilles” by Barrymore’s butler - your personal “smart butler”. 

What happened: description of the application with beautiful pictures and cats


The main screen is a convenient dashboard with the ability to view and manage parameters of automated rooms. Convenient - this is the key word, because dashboards in those applications that I tried to work with myself had to be manually configured. Not the most pleasant pastime. The



house can be divided into zones, and zones - into rooms. Each room has various parameters: temperature, humidity, current electricity consumption, etc., as well as selected actions. If we click on the room, we will fall into the list of devices connected to it:



Here you can turn on / off the device, and also see its main parameter. When switching to a device, more detailed control with a full list of functions will be available. 

All devices are connected using the same settings. For many devices there is a connection wizard. No configs for those who like hotter! Basically, it comes down to specifying the IP address of the device (for many devices there is an auto search). If the IP address suddenly changes, then it's okay, the server will find it at the new address automatically.



There is integration with Apple HomeKit, it is used for voice control through Siri. All devices supported in BARY integrate with Apple HomeKit with a single tick (hello to HomeBridge fans). Not without the support of Yandex Alice. She was more friendly in terms of interface commands. For example, Siri does not want to close the curtains with the command “close the curtains”, cannot set a certain volume level on TV and so on. Yandex.Alice does not have such kookies. 

For the convenience of managing smart lands, automation has been implemented: the rules for the execution of any actions when fulfilling a set of conditions. Automations are logical, multi-level, i.e. you can do something like: “Condition 1 and (Condition 2 or Condition 3).” All in a beautiful logical automation editor:



Personally, I already had a hundred automation programs, and any of them can be quickly found, because everything is grouped by room and device:



Scripts are also supported in the application. A scenario is a complex of actions that is performed under some condition from automation. For my smart home, I use only the standard set:



I have left home / return home via Apple TV - it turns on / off automatically when everyone left home, or someone returned home. You come home, and the announcer with sad eyes from Channel 1 already meets you there. Well, great?

Well, what kind of smart home without the ability to watch a cat?



You can connect any camera that is capable of delivering an RTSP stream. 

Separately, I want to say about the statistics block. It turned out quite informative:



In the legend, the red bar is the deviation from the average values ​​for the last six months, the gray bar is the flow rate within the average values.

In the picture, my statistics for September. It was cold, the heating had not yet been given, so the heating was constantly turned on at the ventilation.

You can also see statistics for any connected device:



By the way, the availability of automation and statistics have reduced electricity costs by more than 2 times.

All occurring events are stored and can be viewed:



Also on the main page there is a special tab that collects all the main indicators selected by the user:



By the way, water metering is implemented through the Xiaomi door / window open sensor. To do this, instead of a reed switch, the output from the pulse counter is soldered to a special contact, and a virtual counter is created in BARY, in which you can specify this sensor as the source of pulses.

Architecture and Security


The client-server exchange is encrypted using AES technology, and the server is located directly inside the automated room. In my opinion, this maximally protects the system from third-party unwanted interventions.

If there is no white IP address, then you can connect the cloud. It will act as an intermediary, without the ability to decrypt commands, because keys are on the server. 

Where to get


The server side can be run on almost any existing platform - thanks NodeJS. For the most common platforms, we have prepared scripts that will do all the work automatically.

For Raspberry Pi based on Debian Stretch:

wget -qO- "http://bary.io/install?target=pi" | sudo bash

The target parameter is responsible for the target platform and can have the following values:
Raspberry Pi (Debian Stretch)
pi
Raspberry Pi (Debian Buster)
pi_buster
Tinker Board (Debian Stretch)
tb
Wiren Board (Debian Stretch)
wb

If someone wants to install on another platform, write to us and we will update the script. If you encounter any difficulties - also write. We really need feedback. 

The application is freely available on Google Play and the App Store . Perhaps by the end of the year, the application will become paid.

Conclusion


Why did I write this article? The main goal is to get feedback from you.

Currently, the project is developing rapidly, and our entire team is trying to maximize the list of supported equipment available on the market. Although I’m not alone working on the project, the tasks remained the same - to create the most convenient application that takes into account the wishes and solves the problems of everyone who was involved in the independent installation of smart solutions for the home.

We are open to dialogue on possible integrations and are ready to implement equipment support from companies interested in partnership as soon as possible. You get a ready-made application and do not waste time developing software. And we get a wide range of supported devices for every taste and color. All is well. 

Immediate plans and rainbow Wishlist


Currently, my team and I are actively engaged in the development of a video storage unit. It will be possible to place the video in your home storage or in a cloud service. I think at the beginning of next year it will be possible to talk about a new release. Should it be possible to review the best pearls of a cat entertaining himself while the owners are not at home? 

Next year we plan more integrations with various services: a list of purchases and to-do, a calendar, etc. He came up, looked at one screen - and everything was in full view. Several turn-key projects have shown that this task is relevant.

We also plan to start the production of controllers with preinstalled software for batch solutions of a smart home (currently the batch solution "software + hardware" is available together with our partnersWiren Board .

And support for Google Home and Amazon Alexa. Well, the expansion of the range of supported equipment, of course.

By the way, who cares, you can see the list of supported devices (not complete) on our website , and if something is not found in the list, then ask in the telegram group .

We will be very grateful if you share what you lack in existing applications and what functions you would add in our place.

Thank you all for reading. Let's make our homes smarter together!

All Articles