In the first part of the article I talked about how to equip a two-room Khrushchev with various sensors and use them to collect information about the current state of the apartment. In the second part, we will talk about how to start actively managing all available systems. To do this, I performed:

  • Complete wireless automation of all lighting.
  • Set the "turn off everything" button.
  • Made it possible to completely remotely de-energize the apartment (including the management server itself along with the controller) and reverse remote enable.
  • Applied electrical pads (rotation devices) for water taps.

ITKarma picture
Access panel of a residential building with equipment for remote power off of the apartment

The drive-in electrical panel presented in the photo, in my opinion, reflects the general idea of ​​affordable apartment automation, namely that only those elements of the electrical circuit that are required to ensure the operation of this part of the system will be replaced or reinstalled. And in the apartment in question, located in a house that is almost fifty years old, only cosmetic repairs were occasionally carried out. This means that the in-house electrical wiring has never changed completely since the 70s and has been quite worn out. In my opinion, this is not entirely reasonable and even possibly unsafe, but taking into account the fact that a complete alteration of the electrical wiring is expensive and entails a general and expensive repair of the entire apartment, this approach was rather common for most old Soviet apartments.

Wireless automation of the whole world


Since I already collected information from many sensors in the apartment, but did not have the ability to control anything, I decided to correct the situation and start with lighting control.
For economic reasons, I didn’t want to do the wired lighting control option - it would be too expensive for me, and therefore I began to look closely at the wireless options that would allow me not to redo the wiring completely. One of the options was the installation of wireless modules in the junction boxes of the apartment.

ITKarma picture
An example of a typical “classic” wiring diagram for light bulbs

In 2017, I found two-channel relays Wifi IoT Relay Board Based on ESP8266 and single-channel Sonoff Basic WiFi Wireless Switch , and also got acquainted with the free firmware Tasmota .

There is currently a ready-made knowledge base on various factory relays and sensors based on Chinese ESP8266 microcontrollers with Wi- Fi interface, which greatly simplifies the selection of the necessary elements for automation.

And since, when I received all the readings from the sensors, I was no longer dependent on the manufacturers' cloud services and worked locally only with Home Assistant , then I decided not to start talking to them. For wireless modules, I decided to use the open Tasmota firmware, getting rid of the manufacturer's firmware.

ITKarma picture
Junction box in the apartment, in which the bathroom, kitchen, corridor and toilet are switched

However, the found wireless modules were large enough and did not fit into the existing junction boxes.
The modules themselves were inexpensive, but the costs awaited me were not their price, but the cost of the work of an electrician and builders. The electrician determined the switching points from the switches in the walls, because the connection during the construction of the house was done according to the classical scheme using junction boxes, where the wires were connected from the switch, lamps and from the electrical panel.

The builders then hollowed the wall and installed larger junction boxes, and then oiled the newly installed boxes and carefully glued pieces of wallpaper.

ITKarma picture
Wall space prepared for installation of a larger junction box

It was also found that electricians, almost fifty years ago, messed up something and the connection scheme was incorrect - when the switch was turned off, the phase remained on some light bulbs.

ITKarma picture
First Test Connection of the Wireless Module

After trial automation of one lamp, when I was convinced that everything works, I decided to fully automate all 7 apartment lamps. And since almost all the junction boxes were in the hallway of the apartment, I decided to combine this procedure with the change of wallpaper and with the help of builders and an electrician did some renovation:

  1. Left on the old wiring only electrical outlets in the rooms.
  2. I handed a separate cable line from the electrical panel of the entrance to the sockets in the kitchen.
  3. Made a separate cable line for lighting.
  4. Made separate cable lines to power sensors.
  5. Made a separate cable line for the router.

ITKarma picture
Two Dual Channel Wifi IoT Relay Board Based on ESP8266 installed in the wall distribution box (2017)

I stretched out separate cable lines, including for powering the router, so that when the apartment was completely de-energized, the router could be turned on, providing reverse remote switching on of the apartment.

ITKarma picture
View of a junction box with inside mounted wireless relays and cable channel with twisted pairs from sensors after plywood wallpaper in the hallway of an apartment

In 2017, I still used OpenHAB and set up the Home Assistant & lt; - > factory relay based on ESP8266 via via MQTT .

ITKarma picture
The process of downloading firmware to factory relays based on ESP8266

Initially, I chose from several firmwares, but the main advantage of Tasmota firmware for me was its complete autonomy from Wi-Fi - even when the module lost contact with the server, it doesn’t matter for what reason - there may be problems with Wi-Fi or the server just freezes - always it was possible to turn the light on or off, as usual, by pressing the physical switch - that is, the user, if desired, could even ignore it.

ITKarma picture
Connected lights in the control panel

OpenHAB vs Home Assistant


At the very beginning, I used only one executive controller - Mega, but it was the controller - there was no "human" interface in it, and for a beautiful control panel I needed a separate server, which usually uses a fanless Raspberry Pi, which can work for years, the only one occasionally experiencing problems with microSD (no backup anywhere).

ITKarma picture
My latest configuration on openHAB

My complete OpenHAB 1.8.3 and 2.2.0 configurations, including items, persistence, rules, sitemaps, transform, are uploaded to GitHub .

In the early years, working with a smart home, I used openHAB on the Raspberry Pi - I already wrote about this in an article on Habr: as I have 1000 days used OpenHAB and then switched to Home Assistant .
I want to note that, for me personally, writing complex rules in the Home Assistant is easier compared to OpenHAB.

ITKarma picture
My current configuration on Home Assistant

The full configurations of Home Assistant, including automations.yaml, configuration.yaml, customize.yaml, lovelace, are laid out at GitHub .

Automatic reports by mail for submission to the management company


Still using OpenHAB as the automation server, I decided to make automatic report generation five days before the end of the month.
As a result, I got such an automatically generated report:

ФИО кв. ХХХ за 12.2016 Холодная вода: ХВС расход в тек.мес.: 2,57 м. куб. Текущие показания: 22,06 м. куб. Показания хол. на 1е число: 19,49 м. куб. Горячая вода: ГВС расход в тек.мес.: 1,63 м. куб. Текущие показания: 13,44 м. куб. Показания гор. на 1е число: 11,81 м. куб. Электроэнергия: Э/э расход в тек.мес.: 31,19 кВт*ч Текущие показания: 253,79 кВт*ч Показания э/э на 1е число: 222,60 кВт*ч Температура воды в трубах: Мин. значение хол. трубы в месяце: 11,31°С Макс. значение гор. трубы в месяце: 66,33°С Средняя темп. батарей в месяце: 42,29°С Отчет сформирован в пятница, 16.12.2016, 08:48 через openHAB. 

The report generation code is presented on GitHub .

Button to turn off all


The physical button located at the front door and which turns off all the light in the apartment is really convenient. In my case, the twisted pair is forwarded to the controller on its input port. Mega controller sends the received signal about the closure of the button to the server, and the server, depending on the rules, turns off all the lights in the apartment, except the passerby, immediately, and the light in the hallway after 15 seconds.

Specific examples of the rules are presented below for the systems that I used in the apartment:

  1. openHAB
  2. Home Assistant

Complete remote blackout of the apartment


HOA at home made a complete replacement of the access electric switchboards, including including grounding, and since the neighboring apartments on the site moved their electric meters and “automatic machines” inside their own apartments, the floor electric panel turned out to be almost empty.

ITKarma picture
View of the floor switchboard before my "intervention" (the meter and the upper machines are mine)

Ideally, I would like to receive the following: remotely connecting via VPN I would be able to completely de-energize the entire apartment, while maintaining the possibility of its remote reverse connection. To do this, I needed to break the electrical network of the apartment into separate cable lines, which I mentioned above.
I also needed a 40A contactor (powerful relay) and another Sonoff wireless module.I also developed a connection scheme for all the electrical consumers of the apartment, according to which I later collected the entire scheme in the driveway.

ITKarma picture
Electrical circuit of the access electrical panel, realizing a complete remote blackout of the apartment

After completing the installation of the electrical circuit of the shield, it turned out exactly as it was intended.

ITKarma picture
Appearance of the electrical panel at the entrance of a residential building, together with my equipment for remote power off the apartment

Access to the contactor (at 40A) is not carried out from the HA control interface (which also de-energizes), but simply by the ip address of the device that is connected to the contactor.

Electrocontacts for water taps


I previously had experience installing electric ball valves on electric water, but now their price is almost 7 thousand rubles. apiece and 15 thousand rubles. for the kit, which in this case was not economically feasible.

ITKarma picture
Example - electric ball valves Neptun Bugatti Pro 12V ½, " installed elsewhere"

There are similar electric water taps on the well-known Chinese site and the price is several times lower, but since it is connected with water, I was just afraid to fill in several floors below and began to look towards the overlays for existing taps.

ITKarma picture
Electroplate for controlling cold water ball valve

The controller can control these electrical tabs through motor drivers on the L298N. It can also be configured in SW LINK mode on the controller in order to prevent simultaneous switching on both sides.

For the correct operation of the linings, the pipes had to be moved apart, otherwise the linings interfered with each other's work. They are also quite voluminous and if the pipes were closed by a box, they would hardly have been able to fit correctly.

ITKarma picture
Voltage measurement on the L298N

The cranes rotate, by themselves, quite tightly and the lining pulls seem to be at the limit of their capabilities, but almost a year and a half has passed since the installation and they still work properly. Closing-opening time of about 15 seconds.

Photos of the apartment


I bring a few photos so that you can evaluate the size and appearance of the apartment and the scope of the work done:

ITKarma picture
Entrance Hall

On the left wall of the hallway, next to the front door, there is OLED display SSD1306 in the factory building, which displays the current time and ambient temperature, on the street.

ITKarma picture
Bedroom of the apartment

What I would do differently if I knew this beforehand


Designing everything in the first phase


If you immediately determine all the expected functions of a smart apartment, develop a complete apartment automation scheme in advance, select all the necessary components of the scheme, it will be easier to combine the current apartment repair and the choice of a convenient and economically more appropriate upgrade option, rather than adjust to the individual needs of the automation scheme or specific examples solutions to a similar problem.

Counters with RS485 interface


First of all, I would install all the meters with the RS485 interface - with a pulse output, a lot of fuss due to the fact that from time to time it is necessary to check the reality of the readings on the counter and in the interface, and especially if there were any malfunctions on the server. When reading using the RS485 protocol, the meter gives not only current current readings, but also has a memory of past readings that can be read. It may be more expensive, but it seems to me more technological and accurate. The only thing that worries about RS485 is that although the protocols of some manufacturers have been decrypted by enthusiasts, and the protocols of other manufacturers have been freely available, there are practically no ready-made integration modules in openHAB or Home Assistant. This is especially noticeable in the case of water meters.

Maybe ZigBee instead of Wi-Fi


Perhaps I would use ZigBee instead of Wi-Fi for wireless relays. But I would still install junction boxes in an enlarged size - a fairly practical solution and you can always roll back to the usual wiring diagram. Moreover, now there is a knowledge base of compatible ZigBee devices .

Maybe Wiren Board instead of Mega


I did not consider the economy and I am only very superficially familiar with the Wiren Board itself, but they have quite a few ready-made modules. It would be interesting to see how it looks in work.

Summary Summary


A very important factor that played a role in the choice of components for the automation of the apartment is the price. And although here I had a microscopic budget and quite a lot of desires - I believe that almost all the necessary functions of smart homes for an apartment were fully realized:

  1. Complete lighting control of the apartment.
  2. Energy metering from a single control panel.
  3. Monitoring of all indicators of the apartment: temperature of risers, batteries, living rooms.
  4. The ability to track and show other people objective noise levels.
  5. Possibility of prompt remote intervention: to completely disconnect the apartment and shut off the water. And perform the reverse operation.


Posted by: Mikhail Shardin

June 15, 2020

Source