image

Smart furniture, which keeps your house in order, is a must for almost any futuristic set. In fact, an auto-regulating climate, automatic lights and voice control over household devices — all this can be done and configured now. But it will take a little experience, basic knowledge of technology and sometimes programming, as well as a whole sea of ??fantasy. In my case, I did in the way that just fantasy will be enough, but first things first…


I became interested in the idea of ??a “smart home” about five years ago. I made the simplest system at first. It controlled lights in my hallway and bathroom via motion sensor, the air drawing via humidity sensor, and also the weather station — everyone was crazy about them at that time. Every self-respecting DIY enthusiast 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 was simple — I had one sensor in the hallway, and one in the bathroom.

If someone went to the bathroom, then the corridor sensor would detect movement and immediately turn on the lights in the hallway and in the bathroom. At the same time, if no one entered the bathroom, the sensor inside the bathroom would indicate that and 15 seconds after the lights would turn off. If someone entered the bathroom, the hallway lights would turn off in a minute.

I also thought about cases such as if someone was too preoccupied with his own thoughts while sitting on a “white throne” 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, and the other group would do the same 5 minutes later. So if you sit motionless for more than 5 minutes the light would turn off. Very disciplining. However, you could always move your hand and continue your thought journey.

The bathroom also had a humidity sensor, which would automatically start the air drawing if humidity exceeded 50%. As soon as the room was ventilated to 45% humidity, the drawer would turn off.

All this was management (or rather tried to be) through the Arduino platform.


Almost immediately, it became clear to me that this platform was not all about creating a smart home. The main disadvantage of working with Arduino was that the platform worked without using the network, and without it, no truly unified ecosystem could be created. Of course, I could add network support, but why do so? I’ve made an easy choice and changed the 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 support + it is more compact in size. This module is still popular among smart home gadget manufacturers.



In parallel, I tried to make the smart home even smarter. For example, I solved the problem of 24 hours underfloor heating or an always-on air conditioner. I bought a Chinese Beok Wi-Fi thermostats in order to do this. They allowed me to turn off the floor heating remotely, but I had to do it through a dedicated phone app.

I solved the problem of remote controls for the air conditioner using the Broadlink RM Pro infrared signal emulator. Nothing too complicated here: you record a signal from the air conditioning remote controller (or it can be any device with remote controls) to the emulator, and so when you press a button in the application, the emulator plays the previously recorded signal. In this case with my air conditioner, I had the opportunity to turn it on and off, set the operation mode and set other parameters remotely.

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



On the contrary: I had to install a separate application again for control, and it had no feedback, so that I could not see whether the light was on, and if it was manually turned on/off by someone using a conventional switch.

My smart home also grew with various controlled Wi-Fi relays such as Sonoff or Tuya, and even the expensive Danalock for locking the apartment, which also required a separate application. I bought almost all of those little things (except Danalock) on Aliexpress, where they only cost a penny, which allowed me to experiment without serious investments.

One of the first relatively serious purchases was the Tion breezer. It coped with automatic CO2 control more or less, but the temperature had to be constantly adjusted throughout the winter. And again — it required a separate application.



I can’t even remember all the sensors and controllers that I tried back then. My smartphone was clogged with apps to manage them all. It was like a zoo, which you had to look after. I tried to combine these applications through all sorts of aggregators like HomeBridge / MajorDomo, etc. But all of them came with significant shortcomings:

  • Unfriendly, and sometimes just terrible UI
  • Lack of support
  • Complex connection

The search for an ultimate application for centralized management for such a number of sensors, controllers and other systems had no success. Then I tried to tweak one of the «smart» devices — the very Tion breezer. I wrote a script to automatically control the heating depending on the room temperature. The fact is that the ventilation system did not have an automatic heating adjustment. It turned out that the room was either super-hot or super-cold. There was no way to hit the sweet spot. This problem was solved with a script.

Success with my script for the breezer prompted me to create my own application for smart home management. 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 application development both on the front- and back-end.

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

For note: in the process of working on the application, I experienced a technical insight about the use of mixins when writing device drivers. I don’t know, maybe it seems elementary for everybody else, but it was a breath of fresh air for me.

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

Example of source code
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 variety of different devices, they all do the same and provide approximately the same information. Therefore, all the capabilities of the devices were put in separate mixins, which ultimately make up the final driver. For example, the application supports many devices that have the on / off function. It is taken out and put in a separate mixin to be used identically for all devices. Elementary, Watson!

This results in: drivers for new devices can be done fast and easy, 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), mixins also base on existing ones. They receive device information and transmit it further. Such an approach allowed 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 finishing back and the front ends. When the application became fairly tolerable to look at, I thought: why not share this with the public? I found project partners and assistants to bring the application to life.

First of all, it was necessary to make the design of the application. In order 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 did not change much from the original idea, literally everything had to be redone.

In parallel, not without the help from my project partners, I bought the most popular smart home devices and coded my application so that it could support these gadgets. Soon, however, it became clear that there would not be enough money for all smart devices, so we decided to ask the existing manufacturers for free test samples of their equipment. We were heard, and Wirenboard and MiMiSmart became the first serious suppliers.

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

* The name did not come from Bari Alibasov, but from Barrymore the butler, from Arthur C. Doyle’s “The Hound of the Baskerville”, — your personal “smart butler”.

What we have in result: a description with pretty pictures and cats



The main screen is a convenient dashboard that can view and manage the automated parameters in your rooms. Convenient is the key here, because in those applications that I tried myself the dashboards had to be configured manually. Not the most pleasant pastime activity.



You can divide your house into zones and rooms. Each room has different parameters: temperature, humidity, current electric power consumption, etc. (as well as selected actions). If we click on a room, we see a list of devices connected to it.



Here you can turn the device on/off, as well as check the main parameters. Switching to the device will give you a more detailed control with a full list of available functions.

All devices are connected using the same type of settings. For many devices there is a connection wizard. No configs for those who like it hot! Basically, it all comes down to specifying the IP address of your device (there is an auto search available for many devices). If the IP address suddenly changes — 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 via Siri. All devices supported by BARY easily integrate with Apple HomeKit with just one click (hello HomeBridge lovers). Yandex Alice is also supported. And it turned out to be more friendly in terms of interface commands. For example, Siri does not want to close the curtains on the command «close the curtains», cannot set a certain volume value on TV, and so on. Yandex Alice is free of such quirks.

For the convenience of managing your territories, more automations have been implemented: perform actions when certain conditions are met. Logical, multilevel automation, i.e. you can do something like “Condition 1 and (Condition 2 or Condition 3)”. Everything in a reasonable and beautiful automation editor.



Personally, I myself have accumulated nearly a hundred of automations, and they are easy to find, everything is grouped by rooms and devices.



The app also supports scripting. Script is a set of actions performed after certain conditions are met. For my smart home, I only use the standard set:



My leaving/coming back home is implemented through Apple TV — it turns on/off automatically when everyone leaves/returns home. You come home and a sad TV host from the 1TV channel is already there to greet you. Isn’t that great?

Well, what is a smart home without the ability to look at your cat?



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

I would also like to mention the statistics section. It turned out to be quite informative:



In the reference list, the red bar is the deviation from the average values for the last six months, the gray bar is the expense level within the average values.

The picture shows my statistics for September. It was cold, no heating was provided yet, so the heater was constantly on.

Also, statistics can be viewed for any connected device.



By the way, automation and statistics helped to cut electricity costs by more than 2 times.

All events that occur are stored and can be viewed.



Also on the main page there is a special tab that collects all of the selected main indicators.



By the way, water metering is implemented through the Xiaomi door/window sensor. To do this, solder the output from the pulse counter a special contact, and BARY will create a virtual counter, in which this sensor can be specified as source.

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 protects the system as much as possible from unwanted interventions.

If there is no white IP address, then you can use cloud. It will act as an intermediary, without the possibility of decoding commands, since the keys are on the server.

Where to get



The back end can run on almost any platform out there — thanks to 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?setup" | sudo bash

If someone would like to install on another platform, let us know and we will update the script. If you have any difficulties — you’re also welcome. We really need feedback.

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

Conclusion



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

Currently, the project is developing rapidly, and our entire team is working to support more equipment from the available on the market. Since I am not the only one working on the project, the tasks remain the same — to create the most convenient application that takes users demands seriously and solves the problems with self-installation of smart solutions for home.

We are open to dialogue on possible integrations and we are ready to implement equipment support from companies interested in partnership as soon as possible. You get a finished application so you do not waste time on software development. And we’d love to wided our range of supported devices for every taste and color. It’s a win-win for everybody.

Future plans and wishes



Currently, my team and I are actively developing a video storage unit. It will be possible to place videos in home storage or cloud. I think at the beginning of next year we can talk about our new release. Should there be an opportunity to playback the best cat moments, while you’re not at home?

Next year we are planning more integrations with various services: shopping and to-do list, calendar, etc. Everything you need is on one screen, — and everything in full view. Several turnkey projects have shown that this is very much in demand.

We are also planning to start production of controllers with preinstalled software for package solutions for smart home (currently the package solution «software + hardware» is available together with our partners Wiren Board).

It also supports Google Home and Amazon Alexa, with more to come!

By the way, if you are interested, you can see the list of supported devices (not complete) on our website, and if you did not find what you were looking for, feel free to ask in our telegram group, you’re welcome!

We will be very grateful if you share what you are missing in existing applications and what functions you would like to add.

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