The tale of how I automated the apartment using Node-RED. Part I

Over the past year, I have assembled and set up automation for a small apartment near a busy road. In this article I will talk about the solutions used in the climate system, lighting, multimedia and software.



What i wanted to do


  1. Automate water shutoff in case of emergency.
  2. Turn off ventilation in case of fire.
  3. Report emergency.
  4. ( , , , ).
  5. (, ).
  6. .
  7. ( , , «» ).


There are several basic systems for managing home automation. There are both paid solutions and free ones - it all depends on the platform. It can be FPGA (programmable logic integrated circuit), controllers in the form factor of the router, as well as just software.

Initially, I considered the finished FIBARO Home Center 2 controller as the main hub. Although the interface there is beautiful and there are many settings, but the hardware turned out to be weak. The firmware, judging by the reviews, was sometimes buggy. Other types of protocols are quite difficult to connect.

Of the free options, I reviewed OpenHUB and Home Assistant.. OpenHUB seemed too loaded and difficult to expand: for example, it is difficult to add a new Z-Wave module if it is not in OpenHUB configs. Home Assistant is easily extensible, but at the time of integration, automation could only be written in YAML, which is difficult to debug and maintain. The integration with Z-Wave in the Home Assistant has raised questions. Therefore, I chose another free analogue, which I will discuss later. I chose

Node-RED as the backend solution, as it provides many ready-made integrations with different protocols, is free and allows you to write automation logic directly in JavaScript in the browser without recompilation. With it, just debug scripts using debug and inject.

Node-RED Script Editing Window
Node-RED Script Editing Window

Node-RED uses NodeJS under the hood, so the rest of the binding was written on it too. Node-RED is just a script editor and integrator of various protocols. The front part of the control - as, for example, in the Home Assistant - is missing. There are several plugins that add the ability to control devices from the browser, but they are not very convenient to configure and require writing front-end code also in the browser ( node-red-dashboard ).

Each Flow in my system is autonomous and all communication between different Flows takes place via the MQTT bus . I can also move the loaded Flow to separate servers for distributed processing.

Communication protocols with end devices


My apartment is not very large, and there was especially nowhere to place the switching unit, so I decided to use wireless modules.

The system uses hidden control relays to leave the physical buttons in the same series with outlets. Physical buttons are needed both for direct control and in case of failure of the central controller. I chose between Z-Wave and ZigBee wireless systems.

At the time of system integration, Z-Wave technology had the most complete collection of required devices. In different countries, Z-Wave uses a different operating frequency, in Russia you can officially use the frequency of 869 MHz. Since I bought most of the sensors in Russia, I decided to use the official frequency for the entire system.

In addition to Z-Wave, the system uses the BroadLink IR module and Modbus TCP.

To integrate Z-Wave into Node-RED, I selected the OpenZWave C ++ library and node-red-contrib-openzwave . Event Processing Z-Wave to integrate Modbus use node-red-the contrib-modbus , management BroadLink - node-red-the contrib-broadlink-control .

Z-Wave Event Handling




Database


I chose MongoDB as the main database: current readings from sensors and end devices are written there, it also stores IR codes for air conditioners and multimedia.

InfluxDB is used as a base for storing time series. According to these data, you can see the graphs of humidity, temperature, build any groupings. Outdoor temperature readings for a month




Frontend


I decided to write the front part myself in order to achieve maximum system flexibility. When working with Dashboard, two auxiliary systems are used:

  • MQTT server based on aedes ;
  • authorization server.

The authorization server issues a JWT token by login and password, or by belonging to a local network, after which the MQTT server checks this token every time it sends or receives a message for the front-end system.

The front end is written in ReactJS, and MQTT over WebSockets ( MQTT.JS ) is used as a server communication protocol . As state MobX is used. TypeScript is also used, and it all compiles webpack.

The application consists of two pages:

Dashboard
Dashboard

Z-Wave-
Administration panel of Z-Wave devices

On the administration panel, you can add and remove devices, configure their parameters and associations.

FGD212
FGD212 Dimmer Setting

On the Dashboard page, you can add new pages and combine device widgets as you like.

From a software point of view, each device is a separate module, which is entered into the system through the interface (Typescript). This gives fairly easy extensibility and easy integration of new devices on the Dashboard.

Equipment


As a controller, I use the Intel NUC NUC7PJYH on which Ubuntu Server is deployed. For communication with the Z-Wave network, I chose the USB stick Z-Wave.Me .

As the main remote for a smart home, an Android tablet is used, which I ordered on Alibaba.com . And the tablet came straight from the factory: with a Vesa mount, PoE power and a power plug (not USB). The tablet is powered by a 12V power supply located on a DIN rail in the control cabinet. There is no battery in the tablet, so as not to come up with options with constant charging.

I ordered a tablet according to my specifications.


Remote Control

Climate system


To maintain a comfortable climate, the system uses:

  • Electric floor heating in three zones.
  • Air conditioning of living quarters.
  • Central ventilation.
  • Humidifiers.
  • Central heating.

Ventilation


Since the house is located next to a busy highway and I don’t want to open the windows at all, I use the ventilation system.

,
Black dust on the window, accumulated in about three months.

Studying different solutions to the problem of ventilation without opening the window, I made a short list of three options:

  • Installation of breathers in each room.
  • Installation of the outdoor unit and wiring of the ducts on the external wall.
  • Central ventilation system.

The breathers were rejected immediately, as they would have to be put in every room and, in my opinion, they are quite noisy for normal air exchange. One of the important conditions for me was the low noise level and the ability to quickly ventilate the room. When using a breather, a block with filters and a fan is hung directly on the wall inside the room, which takes up additional space in the apartment.

Many installers offer to mount an external ventilation unit or install a supply to the balcony. But I do not have a balcony, and the external unit on the wall would look rather bulky. Given that two units from air conditioners are hanging on the wall already, such a design would not have passed approval. Therefore, I chose a central ventilation system.

Since the apartment’s space is limited and there was no wish to lower the ceilings throughout the apartment, the inflow was installed in the corridor, where the ceilings were lowered, and the input was made from the children's room.


Ventilation input

A hole with a diameter of 160 mm was drilled in the outer wall using a diamond drill and galvanized with an external grill. The inlet pipe was insulated with K-flex insulation. Then the pipe goes along the wall of the kitchen and enters the main ventilation unit.

Breezart 550 lux
Breezart 550 lux ventilation unit and unit for optional filter The

ventilation unit was selected by Breezart . When choosing, I took into account the installation cost, dimensions and the ability to connect to the automation system. The unit has a maximum capacity of 550 m³ per hour:
The system has a quiet fan with 10 speeds and an electric air heater. An electromechanical valve is installed at the entrance, which closes when the unit is turned off so that cold air does not walk around the apartment. On the electronics side, the installation provided three Modbus ports, temperature sensors and pressure sensors to determine if filters are dirty. Included with the installation is a coarse filter G4.


The coarse filter after six months of use

The coarse filter clogged by 70% after a year of use, but judging by the CO₂ sensor, the ventilation no longer pulled at low speeds. Until December 20 - the filter is clogged, after December 20 - a new filter, the speed is the same

20  —  ,  20  —  ,


After the ventilation installation, there is a fine filter F7. Using finer filters, such as HEPA, for my situation, I considered it inappropriate: they will clog quickly and the installation will not be able to push them. Also, manufacturers do not recommend exceeding the pressure drop across the filter, as this will increase the load on the fan and dirt from the filters may begin to blow into the rooms.


After the fine filter, two mechanical air flow regulators are installed, followed by several SONODEC flexible air ducts to the rooms. This type of duct was chosen so as not to put a bulky muffler and at the same time drown out the noise of the installation. After closing the ceiling, the ventilation system is audible only starting at speed 8 (440 m³ per hour) and only from the corridor. At the ventilation outlet there are grilles adjustable in two directions.


Ceiling- mounted ventilation system Ventilation


output to one of the rooms

A remote control from the kit is connected to one of the Modbus ports, and a Modbus TCP HF2211 server to the second.

Modbus RTU — Modbus TCP converter HF2211
Modbus RTU - Modbus TCP converter HF2211

This server allows you to connect to the internal network via Wi-Fi or Ethernet, on the one hand, and to the Modbus RTU device on the other. Then on it you can raise the server with the necessary settings and already access the ventilation unit via the network. The installation is polled every 300 ms: errors and checksums are checked and only after that it is allowed to write some data to the registers. Communication with the installation occurs through the node-red-contrib-modbus plugin . Scheme of receiving and sending parameters from a ventilation unit via modbus Scheme of receiving and sending parameters from a ventilation unit through modbus The manufacturer's website has a detailed reference of modbus registers and a general description

modbus


modbus


for this installation, but you need to check the version of the controller and firmware. The ventilation unit is controlled automatically by time and by the CO₂ MH-Z19b sensor. Flow ventilation automation Flow automation ventilation The CO₂ sensor is portable, assembled on the basis of the MH-Z19b sensor, two 18650 batteries, ESP32 and IRF520 mosfet (to disconnect power from the sensor during the controller’s sleep). CO₂ readings for a month, peak to 1800 PPM - guests came with the subsequent inclusion of ventilation at higher revolutions . Depending on the installation speed, a comfortable temperature of the incoming air is set, which heats the air heater.

Flow


Flow




CO₂  ,   1800 PPM —




At higher speeds, a higher temperature is required - otherwise a stream of cold air will be felt. In order not to consume much electricity in winter, when it is colder outside −7 ° C, the installation is limited to a third speed. At night, installation is limited to a fourth speed. If nobody is at home, the system automatically switches to the first speed. At the "Vacation" command, a complete shutdown occurs.

There is a pre-heating mode after vacation, airing at full speed and a transition to the first speed on a timer. If the system has CO₂ sensors, then additional speed control is possible in accordance with global restrictions.

Conditioning


The system has several air conditioners with cooling and heating modes. There was an idea to put central air conditioning, but all the systems are too large and do not give the opportunity to regulate the temperature in each room. Unfortunately, my air conditioners are controlled only by IR. So I bought the Broadlink RM Mini3 control panel.

Broadlink RM Mini3
Broadlink RM Mini3

If you use a native application, then this remote will connect to Chinese servers, so all configuration and management commands are transmitted directly from Node-RED using the node-red-contrib-broadlink-control module .

Since I did not find any clean IR codes for the air conditioners, and the remote control transmits the entire state (revs, mode, temperature) - all possible states for heating and cooling were copied from the air conditioning remote using Broadlink to the database. There were no clean commands to enable or disable either.

But I found how to use the air conditioner on and off timers. I set them for 10 seconds and copied them to the database. Now, when turned on, the command to turn on by timer is transmitted first, and then the command to set the mode along with the temperature. Air conditioning control




The script checks the weather outside and, if the values ​​are acceptable (more than −7 ° C), it turns on the air conditioner for heating or cooling, depending on the time of day and the room temperature. The temperature sensor reads once an hour.

If everyone leaves the house, the air conditioners turn off. If nobody is there and the temperature is too high or low, but the heating batteries are not yet turned on, then a 15-minute cooling or heating takes place every hour to maintain the indoor climate. Air Conditioner Management Scenario

Air Conditioner Management Scenario


Floor heating


The system has three circuits for electric floor heating. They are controlled by three HeatIt Z-Wave thermostats .

Thermostat HeatIt
Thermostat HeatIt The

thermostat allows you to configure different resistance parameters for different types of heating elements, has child protection, two saved heating modes and other minor settings.

In the cold season, the floor temperature is set at 1 ° C more than summer. When there is no one at home, and also at night, the floors are turned off to save energy and turned on either in the morning or as soon as someone comes home. In the bathroom, the floor raises the temperature, if the light is on, the door is closed, there was movement until the door was closed and humidity increased sharply. After an hour, the floor goes into the previous state or turns off (if night falls).

Underfloor control scenario
Heated floor management script Heated floor management script

Underfloor control scenario


Central heating


Since Moscow does not always turn off or regulate heating on time depending on the temperature outside the window, it was decided to put a Danfoss Living Connect thermostat on each battery .

Thermostat Danfoss Living Connect
Thermostat Danfoss Living Connect

This thermostat is powered by two finger batteries using the Z-Wave protocol. A year has passed since the installation, but the batteries have not run out yet. The maximum set temperature is 28 ° C. Since the sensor is next to the battery and the remote is not connected, it sometimes lies.

In the summer, the temperature regulator is always in the “open” position and makes a complete closure once every two weeks, so that the stock does not sour. When you connect for the first time during the week, the sensor is calibrated (which didn’t really please my wife, as the batteries turned off periodically), but after that everything worked as it should. Before the start of the heating season, the average outdoor temperature for two weeks is checked, and if it is below 10 ° C, thermostats go into heating mode. If the temperature in the room is higher than the comfortable one, thermostats reduce the temperature or completely turn off the battery.

Humidifiers


To humidify the air in the apartment, central humidifiers were considered. There are two main types: steam and traditional. A steam humidifier requires a lot of electricity to constantly heat water. Both types of humidifier drain a lot of water into the drain so that it does not bloom. It is necessary to carry out calculations so that the ducts do not bloom and flow. It is also worth considering that central humidifiers are expensive and take up a lot of space.

I decided to use ultrasonic humidifiers in each room. They quickly raise humidity, but they require purified water, preferably after reverse osmosis. Humidity can be set on the humidifiers themselves, or can be controlled using IR.


An example of the operation of the interface

In the second part of the article I will talk about lighting, a multimedia system and security sensors, and also summarize the long-term use of the system.

All Articles