How I automated my apartment with Node-RED. Part I

Andrew Peyve
IT’s Tinkoff
Published in
12 min readApr 8, 2020

Last year I assembled and configured 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 shut-off in case of emergency.
  2. Switch off ventilation in case of fire.
  3. Notify about emergencies.
  4. Maintain optimal temperature and humidity (supply ventilation, air conditioning, underfloor heating).
  5. Control the lighting (curtains and light).
  6. Save electricity.
  7. Get the local system (local servers only, so that in case of “apocalypse” everything remains in working condition).

Backend and Frontend

There are several basic systems for home automation. There are both paid and free solutions — everything depends on the platform. These can be PLD (programmable logic device), controllers in the router form-factor, or just software.

Originally, I chose the FIBARO Home Center 2 controller as the main hub. Although the interface is nice and there are many settings there, the hardware was poor. The firmware, judging by the reviews, sometimes failed. And it is hard to use the other types of protocols.

From the free options, I considered OpenHUB and Home Assistant. OpenHUB seemed to be too powerful and difficult to extend: for example, it is difficult to add a new Z-Wave module if it is not in the OpenHUB configs. Home Assistant is easy to extend, but you could only use the YAML, which is difficult to debug and maintain. There is also a poor integration with Z-Wave. So, I chose another free analog which I will talk about further.

I chose Node-RED as a backend solution because it provides many ready-made integrations with different protocols, is free and allows us to write automation logic directly in JavaScript in a browser without recompilation. With it, it’s easy to debug and inject scripts.

Node-RED script editing window

Node-RED uses NodJS under the hood, so the rest of the bundling was written on it too. Node-RED is just a script editor and integrator for different protocols. The frontend of the control — like in Home Assistant — is missing. There are several plugins that add the ability to control devices from the browser, but they are not very easy to configure and require the frontend code to write also in the browser (node-red-dashboard).

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

Communication protocols with end devices

My apartment isn’t very large, and there wasn’t much room for a switching unit, so I decided to use wireless modules.

The system uses hidden control relays to leave the physical buttons in the same look with physical buttons. There are also are needed both for direct control and in case the central controller goes down. I chose between Z-Wave and ZigBee wireless systems.

At the time the system was integrated, the Z-Wave technology was the most complete of required devices. In different countries Z-Wave uses different frequencies, in Russia you can officially use 869 MHz. Since I bought most of the sensors in Russia, I decided to use the official frequency for the whole system.

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

To integrate Z-Wave into Node-RED I chose OpenZWave C++ library and node-red-contrib-openzwave.

Z-Wave event handling

For Modbus integration I use node-red-contrib-modbus, for BroadLink control — node-red-contrib-broadlink-control.

Databases

I chose MongoDB as the main database: it saves current data from sensors and end devices, it also stores IR codes for air conditioning and multimedia.

InfluxDB is used as a database for storing time series. From this data, you can view graphs of humidity, temperature, and make any groupings.

Outdoor temperature

Frontend

I decided to write the front part myself in order to achieve maximum flexibility of the system. Two systems are used when working with Dashboard:

  • MQTT-server based on aedes;
  • Authorization server.

The authentication server issues a JWT token by login and password or local network membership, after which the MQTT server checks the token every time a message is sent or received for the front system.

The frontend is written on ReactJS, MQTT over WebSockets (MQTT.JS) is used as the communication protocol with the server. MobX is used for the statistics TypeScript is also used, and Webpack collects all this.

The application consists of two pages:

Dashboard
Z-Wave Device Administration Panel

In the administration panel, you can add and delete devices, configure their parameters and associations.

The FGD212 dimmer setting

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

From a software point of view, each device is a separate module, which is brought into the system through an interface (Typescript). This makes it fairly easy to expand and easily integrate new devices into the Dashboard.

Hardware

I use the Intel NUC NUC7PJYH with Ubuntu Server on it as the controller. To connect to the Z-Wave network, I chose the Z-Wave.Me USB stick.

The Android tablet that I ordered from Alibaba.com is used as the main smart home remote control. And the tablet came directly from the factory: with Vesa attachment, PoE power supply and power plug (not USB). The tablet is powered by a 12V power supply unit located on a DIN rail in the control cabinet. There is no battery in the tablet.

I ordered the tablet according to my specifications.

Remote control panel

Climatic system

For a comfortable climate maintaining I use:

  • Electric floor heating in three zones.
  • Air-conditioning of living spaces.
  • Central air supply ventilation.
  • Humidifiers.
  • Central heating.

Ventilation

My home is located next to a busy highway and I don’t want to open the windows at all. So I use a ventilation system.

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

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

  • Installation of breezes in every room.
  • Installing the outdoor unit and distributing the ducts to the outside wall.
  • Central ventilation system.

The breeze I rejected because it would have to be placed in every room and in my opinion, it is quite noisy for normal air exchange. One of the most important conditions for me was the low noise level and the ability to quickly ventilate the room. When using a breeze unit with filters and fans, it hangs directly on the wall inside the room, which takes up extra space in the apartment.

Many installers offer to mount an external ventilation unit or to install an air inlet on the balcony. But I don’t have a balcony, and the outdoor unit on the wall would look quite bulky. Taking into account that there are two blocks from conditioners hanging on the wall as it is, such construction wouldn’t pass the coordination. That’s why I chose the central ventilation system.

As the space of the apartment is limited and I don’t want to lower ceilings on the whole apartment, the inflow was established in a corridor, where ceilings were lowered, and the input was made from a children’s room.

Ventilation input

A hole 160 mm in diameter was drilled in the outer wall using a diamond drill and the external grating was installed. The entry pipe was insulated with K-flex insulation. The pipe then runs along the kitchen wall and enters the main ventilation unit.

Ventilation unit Breezart 550 lux and additional filter

I choose the Breezart ventilation unit. I took into account the cost of installation, size, and possibility of connection to the automation system. The unit has a maximum power of 550 m³ per hour.

The system has a quiet fan with 10 speeds and an electric heater. There is an electromechanical valve at the inlet, which closes when the unit is switched off to prevent cold air from walking around the apartment. On the electronics side, the system has three Modbus ports, temperature sensors and pressure sensors to detect the contamination of filters. A G4 coarse filter is included with the installation.

Coarse filter after six months of use

The coarse filter was 70% blocked after a year of use. But, according to the sensor CO₂, the ventilation was no longer in a working at low speed.

Until December 20 — the filter is full, after December 20 — new filter, the speed is the same

The air handling unit is followed by a fine filter F7. I don’t recommend to use HEPA-filter: they will quickly get clogged. Also, the producers do not recommend to exceed the pressure drops on the filter.

After the fine filter, two mechanical airflow regulators are installed, followed by several SONODEC flexible ducts to the rooms. This type of ducting was chosen in order not to install a bulky silencer and at the same time to silence the installation noise. After the ceiling has been closed, the ventilation system can only be heard from 8 speeds (440 m³ per hour) and only from the corridor. At the outlet of the ventilation system there are two-way adjustable lattices.

Ventilation system, covered
Ventilation exit to one of the rooms

One of the Modbus ports is connected to the remote control from the set, the second port to the Modbus TCP server HF2211.

Modbus RTU — Modbus TCP converter HF2211

This server allows you to connect to the internal network via Wi-Fi or Ethernet on one side and to a Modbus RTU device on the other. It can then raise the server with the required settings and already access the air handling unit over the network. The installation is polled every 300 ms: errors and checksums are checked and only then data can be written to the registers. Communication with the installation is done via the node-red-contrib-modbus plugin.

Scheme of receiving and sending parameters from the venturing via Modbus
Scheme of receiving and sending parameters from the venturing via Modbus

The manufacturer’s website has a detailed Modbus register reference and general description for this installation (sorry, in Russian only), but you should check the controller and firmware version. The air handling unit is controlled in automatic mode by time and sensor CO₂ MH-Z19b.

Automation ventilation flow
Automation ventilation flow

Sensor CO₂ is portable. It is based on MH-Z19b sensor, two 18650, ESP32 batteries and IRF520 (to disconnect power from the sensor when the controller sleeps).

Readings of CO₂ for the month, peak to 1800 PPM reached when guests arrived (they were followed by turning on the ventilation at higher speeds).

Depending on the installation speed, the comfort temperature of the incoming air is set and the heater is heated.

At higher speeds, a higher temperature is required — otherwise, the cold airflow will be felt. In order not to consume much electricity in winter, when it is colder outside at -7 °C, the installation is limited to a speed 3. At night, the installation is limited to the speed 4. If no one is home, the system automatically switches to the speed 1. On command “Vacation” there is a complete shutdown.

There is a preheating mode after vacation, airing at full speed and switching to the first speed by the timer. If the system has sensors CO₂, it is possible to additionally adjust the speed according to the global limits.

Air Conditioning

Several air conditioners with cooling and heating modes are built into the system. The idea was to install central air conditioning, but all systems are too large and do not allow to regulate the temperature in each room. Unfortunately, my air conditioners are only controlled by IR. So I bought the Broadlink RM Mini3 control panel.

Broadlink RM Mini3

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

Since I haven’t found any pure IR codes for air conditioners and the remote control transmits the whole state (speed, mode, temperature) — all possible heating and cooling states have been copied from the remote control to the database using Broadlink. There were no clear commands for switching on and off, either.

But I found out how to use the timers to turn on and off the air conditioner. I put them on for 10 seconds and copied them into the database. Now, when you turn on, first the command to turn on the timer and then the command to set the mode together with the temperature.

Air conditioning scenario

The script checks the weather outside and, if the values are allowed (more than -7 °C), turns on the air conditioner for heating or cooling — depending on the time of day and the temperature in the room. The temperature sensor readings are taken once per hour.

If everyone has left the house, the air conditioners are switched off. If no one is home and the temperature is too high or too low, but the heating radiators are not yet on, a 15-minute cooling or heating occurs every hour to maintain the climate in the room.

Air conditioner control scenario

Underfloor heating

There are three circuits of electric floor heating in the system. They are controlled by three HeatIt Z-Wave thermostats.

HeatIt thermostat

The thermostat allows us to adjust different resistance parameters to different types of heating elements, has child protection, two stored heating modes, and other settings.

In the cold season, the floor temperature is set to 1°C more than in summer. When there is nobody at home and at night the floors are switched off to save energy and switched on either in the morning or as soon as someone comes home. In the bathroom, the floor raises the temperature when the light is on, the door is closed, there was movement until the door closed and the humidity rose sharply. After an hour, the floor goes back to its previous state or turns off (if it’s nighttime).

Underfloor heating control scenario
Underfloor heating control scenario

Central heating

Since heating in Moscow is not always switched off or on in time depending on the temperature outside the window, it was decided to install a Danfoss Living Connect thermoregulator on each radiator.

Danfoss Living Connect

This temperature controller is powered by 2 AA-batteries via the Z-Wave protocol. A year has passed since it was installed, but the batteries have not yet run out. The maximum settable temperature is 28°C. Because the sensor is close to the battery and cannot be connected remotely, it sometimes fails.

During the summer, the thermostat is always in the “open” position and closes fully every two weeks so that the rod does not sour. The first two weeks sensor is calibrated (which didn’t make my wife very happy as the batteries were switched off from time to time), but after that, it worked properly. Before the heating season starts, the average outdoor temperature is checked for two weeks and if it is below 10 °C, the thermostats go into heating mode. If the room temperature is higher than the set comfort temperature, the thermoregulators reduce the temperature or switch off the battery completely.

Air Humidifiers

Central humidifiers were considered for humidifying the air in the apartment. There are two main types: steam humidifiers and traditional humidifiers. A steam humidifier requires a lot of electricity to constantly heat water. Both types of humidifiers drain a lot of water into the drain system so that it does not bloom. You should also consider that central humidifiers are expensive and take up a lot of space.

I have decided to use ultrasonic humidifiers in every room. They quickly lift humidity, but they require purified water, preferably after reverse osmosis. Humidity can be installed on the humidifiers themselves, or controlled by IR.

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

--

--