There are quite a few reviews and videos on the Internet about building smart houses. There is an opinion that all this is quite expensive and troublesome in the organization, that is, in general, the fate of geeks. But progress is not standing still. Devices are becoming cheaper and more functional, and design and installation are quite simple. However, the reviews mainly focus on 1-2 examples of use, practically not covering nuances and not creating a complete picture. Therefore, in this article I want to make an overview of the finished project, demonstrate the use cases and pitfalls encountered in building a smart home with Xiaomi devices on the example of a sauna. The described ideas with small variations can also be applied to the automation of the apartment.

image

Background or why all of this is necessary


For starters, a little background so that the context can be understood. In the early autumn of 2018, the sauna was finished and put into operation. The sauna is an autonomous capital structure with year-round heating and water supply.

image

For understandable reasons, no one permanently lives in the bathhouse and does not control the condition of the premises. As much as I would like, visiting the bathhouse is also not a very frequent occurrence. Accordingly, thoughts about creating a «smart» bath were present from the very beginning of the project. First of all, for safety reasons (fire, flooding, access control). For example, switching off the heating at -35 degrees outside (I live in Novosibirsk) is a very dangerous situation. However, unlike the main house, I did not think over the project of bath automation from the beginning and did not make additional wiring to the right places. On the other hand, the bath was carried out by the Internet, and the appearance of the other two buildings is video surveillance (you can assess what is happening visually).

Back from a business trip in November 2019, in the evening I went to the bathhouse, opened the front door and was shocked by what I saw. The WiFi-point LEDs were blinking from the darkness and a stream of water was pouring down my feet. So there was flooding, and the power wasn't cut off. The water in the bathhouse is organized with the help of its own well, a submersible pump and an automation system controlling the process. As it turned out later, one of the fittings in the toilet junction was torn down and all the rooms were flooded. I never found out why the automation was compassionate and still shut down, but it managed to pump 15 cm of water per square 30. It was -14 degrees outside that day. The warm floor managed to keep the room temperature at the right level, but there was 100% humidity. You couldn't sneak in on the organization of a smart house — you have to start doing it.

Choice of devices


During the construction of the main house I gained experience working with Eldes devices (the appropriate wiring was created). Part of the automation is done on Raspberry PI. Another part is made on Xiaomi Aqara devices. The variant with Raspberry PI was the one I liked the most and I initially considered it for the bath. But, unfortunately, it requires much more effort to organize. It's not a plug-and-play device after all — from exercises with iron to writing software for your own needs. For certain reasons, MajorDoMo wasn't happy with it. Crossing Raspberry PI, ZigBee Adapter (to use Xiaomi wireless sensors) and Apple HomeKit required learning (and Apple HomeKit interface is not very happy at the moment). There wasn't much time (I didn't want the situation to be repeated) and there was no wiring for each necessary point, so I decided to do everything on Xiaomi devices.

The main device in this situation is the hub. In the case of Xiaomi, there are two versions of the hub: Xiaomi Mi Smart Home Gateway 2 and Xiaomi Aqara Gateway. The latter is about twice as expensive, more suitable for the local market and able to integrate devices into Apple HomeKit. However, if you install the Aqara Home application and select the region «Russia», at the time of writing these lines, only 13 different devices (switches, sockets, sensors) will be available. If you install the application Xiaomi Home, select the region «China Mainland», then there will be hundreds of devices available for connection. However, if you select the «China Mainland» region, you will not be able to connect the European socket and vice versa. Selecting «China Mainland» region within the Aqara Home application does not give the completeness of devices that are present within Xiaomi Home with the same region. Fearing incompatibilities, I decided to stop at the Xiaomi Mi Smart Home Gateway 2 hub. By the way, the hub itself is a lamp — this can be taken into account during installation.

image

A separate interesting question is how long this is going to work out. It's not even about sensors and batteries in them, but about synchronization and storage of data in the cloud. At the moment, the account is free. All information is stored on Xiaomi servers. If tomorrow the guys decide that users from Russia should not store data in the region «China Mainland» or Roskomnadzor for some reason will banish their servers, the whole smart house risks to turn into a pumpkin. I decided for myself that in this case the sensors will remain, and the hub will be replaced by Raspberri PI + ZigBee Adapter.

Monitoring and preventing leaks


The first and most important automation scenario was a natural continuation of the problem — when a leak occurs, the water supply, i.e. the pump, must be turned off and a problem alert must be sent to the phone. There were two potentially dangerous leak locations.

In addition to the hub, this scenario required two leak detectors and a smart wall-mounted socket. Leakage sensors are autonomous, run on batteries. The manufacturer claims that one battery will be enough for 2 years.

image

Installation of a smart socket was a little complicated by the fact that under the Chinese sockets you need square sockets, which are not sold in our regular stores (but you can bring them on order).

Drilling square holes is still a pleasure. Plus, you need an adapter in a good way, although there is also an outlet for the European plug. The Aqara version for the local market does not currently have a wall-mounted socket, which ties us to the «China Mainland» region. Alternatively, you could install a normal wall socket and plug a smart Xiaomi socket in it, but this would require two additional adapters. Another alternative was a relay. But I stopped at a wall-mounted socket.

image

In the Xiaomi Home app, a socket and a sensor were added. Next, a «in case of leakage» scenario is written for two actions: to turn off the socket and send an alert.

image

The first leak sensor was installed next to the pump (and, in fact, next to the hub). For the test, water was poured into a small plate and the sensor was lowered into it. I did all the action directly in the place where the sensor was installed to bring the situation as close to reality as possible. The test was successful: the socket was disconnected, the alarm came on the phone, plus the hub blinked emergency mode.

The second leak detector was planned to be installed in the toilet near the pipe junction. But with its installation there were nuances — the hub did not see the sensor, although the distance was small. The fault was the configuration of the premises.

image

Between the place of installation of the hub (rest room) and the place of installation of the second sensor of leakage (toilet) there was a steam room. In the best traditions, the steam room was sewn in a circle of foil, creating problems with the signal passing.

The manufacturer claims that the devices are able to form a mesh network, that is, one device can transmit data to the hub through another device. I have seen information somewhere that only devices that are connected to the network (and not battery-powered) can act as such transmitters on the mesh network. However, it was enough for me to install a temperature sensor in the corner of the washroom so that the signal from the leak sensor would no longer be lost. Maybe this is a coincidence because a street light control relay has been installed below the ceiling in the washing room (maybe it acts as a transmitter in the mesh-network). However, the problem with the loss of signal from the leak detector in the toilet has been solved. In addition, the connection of the instrument to the hub can be checked by pushing the sensor centrally. If all is well, you will hear the information from the hub in pure Chinese (in case of the Aqara hub the communication is in pleasant English).

A check to see if the power has been disconnected and then switched on by means of the machine shows that the smart socket goes off. There is an appropriate setting so that it goes on when the power comes on:

image

An additional sign of flooding was an increase in humidity to 100%. Please refer to the next section about controlling this sign.

Smoke and temperature control


A sauna is a fire hazardous room, so the next scenario was to determine the fire signs. For this scenario, two temperature (and humidity) and smoke detectors were required.

The smoke sensor was mounted on the corridor ceiling in the washroom (actually close to the stove and the exit from the steam room). Further, a device was added to the Xiaomi Home application and a «in case of smoke detection» script was created, followed by a notification to the phone. The test was conducted with a fireplace match. The sensor successfully coped with the test. The hub was freezing the alarm, plus an audible alert was working. The sensor itself was also very nasty and beeped loudly, warning of a problem.

image

Another sign of fire is an increase in temperature. Two sensors were installed to monitor the temperature: one in the break room and the other in the wash room. Next, a «in case of temperature above the set point» scenario was set up in the application with a corresponding notification on the phone. At the moment I have set the trigger threshold for the rest room to 30 degrees (in summer it will probably need to be reconfigured).

image

Also, it was configured the scenario «in case of temperature below a preset» with a trigger threshold of 18 degrees and a warning on the phone. If for some reason the heating stops working, I would like to know about it as soon as possible. Similarly, the «in case of humidity rise» scenarios have been created for both sensors with a 70% trigger threshold, a warning on the phone and the shutdown of the water pump.

From the nice bonuses on temperature and humidity sensors, historical graphs are available in the application. You can, for example, determine at which moments the bath was used for its intended purpose (temperature peaks in the graph below) or compare whether the current temperature is abnormal.

image

Ventilation control


The steam room has a forced extractor hood. After completing the procedures, it is desirable to air the room. Ventilation is switched on by means of a key switch, and the ventilation itself takes at least 30 minutes. However, often the sauna ends at the first or second hour of the night. To do everything in advance is not always possible, and to sit at the end of another 30 minutes and wait for the steam room to ventilate — pleasure is below average because you want to sleep already.

For this scenario we needed a key switch from Xiaomi with zero line and wall mounting. The price of the question is about 1900 p. Switches are available in the version of Aqara for the local market.

In my case, you can not just replace a normal switch with a smart one — a power line is required. Accordingly, it was necessary to pull a zero line to the installation opening for the switch, this was a good opportunity. In the case of a circuit breaker without a zero line, installation would have been easier.

image

After installation, the smart switch was added to the application as a device and performance tested. The switch settings have a timer and you can set the switch-off time. That is, the switch-off timer is now set for an additional 30 minutes of ventilation before leaving the sauna, and you can go to bed in peace.

image

Another option is possible to automate the process. After bathing procedures are completed, the door to the steam room opens completely in addition to ventilation. This results in an increase in temperature in the washing room, where a temperature sensor is installed. On the basis of this sensor readings, it is possible to create on/off ventilation scenarios. But I haven't run this option around yet. In addition, you could experiment with the sensor for opening the door to the steam room. But I'm afraid it will quickly die or fall off, because the door is made of glass and the steam room can be 120 degrees.

Street light control


Another task that we wanted to automate was to control street light on the veranda. One of the typical scenarios is to turn on the light on the veranda when you are not far from the building and it is dark outside. The sauna is locked, the street light switch is inside the room. You had to follow the key to open the door and turn on the light. Turning off the lights required a similar procedure. Another scenario that occurred regularly was to turn the lights on or off on the veranda when you were in the main house. I often forgot to turn off the lights on the veranda when I left the sauna and found that I was already in the house: either by looking out the window or by looking at the security cameras. At that moment I was usually reluctant to go anywhere, so the lights kept on all night.

image

A two-channel relay was purchased to implement this idea. The price of the question is about 2000 p. There are no relays in the version of Aqara for the local market at the moment. But it can be replaced by a key switch (it is clear that installing it in the distributor box is a more troublesome process).

Initially, I was supposed to mount the relay behind the key switch, but it was very difficult to reach the power line (the relay again needs power). The ideal place is the junction box where the power line, the line from the circuit breaker and the line from the street lights all converged. It was under a false ceiling, so it had to dismantle some of the car rails. It was desirable to think about this point in advance. However, the installation was successful. The wiring diagram is much more complicated than for sockets and switches (in my case four 3-core wires and 8 terminals on the relay itself). In order not to keep it in my head and not to get anything mixed up, I painted the circuit diagram on paper before mounting it. Next, I did a trial mounting to check everything out:

image

The device was plugged into the application and the testing phase began. The street lights had to be turned on/off with both the previous key switch and the application. There are two street lights, one on the left and one on the right. The relay has two channels, but it made no sense to switch them on separately. On the other hand, you didn't want to turn them on alternately with two clicks in the application either. So the control was done on one channel of the relay. By a strange coincidence, this option didn't work normally — there was a sticking in one or the other position. There was no time for experiments, because the light day was over and we wanted to assemble the car on the ceiling back. So I simply hooked the lanterns parallel to both channels and everything worked as desired. In order to make the physical and software switch work as a gateway switch, the Interlock option was enabled in the relay settings.

It would also be possible to organize switching lights on/off by timer. But this scenario was not interesting yet.

Room access control


Another curious moment was the control of the opening of the street door. First of all, to determine and notify that someone had forgotten this very door normally slammed or left it open at all.

For this scenario, a window/door open sensor was required. The price of the question is about 1000 p. There are sensors in Aqara version for the local market (they have less rounded edges).

image

Installation is very simple — sensors are mounted on double-sided tape. Before mounting, it is better to connect the sensor in the application to see at what distance the sensor is triggered. The instructions say up to 20mm clearance, but that's not true to say the least — the sensor and the response magnet have to be mounted almost closely. In the main house, the garage door has a similar sensor. There is a 1 cm wide seal between the guide rail and the door. At this distance, the sensor showed an «open» position and the response magnet had to be increased.

Once a new device has been added to the app, you can move on to automation. Configure the scenario «if the door is open for more than 1 minute» with an alarm on the phone. In the English localization you can not see the part of the phrase about 1 minute, but the threshold for triggering is this. In the variant of the Aqara sensor and the Aqara Home application you can configure other triggering intervals. In the Xiaomi Home application, unfortunately, it is not possible to do so yet. But practice has shown that the interval of 1 minute is more than sufficient — there are no false alarms, all the alarms were on the case. You can also look at the logs by sensors. This sensor is not an exception either. You can, for example, from the log to determine when the bath came (first opening the door on a given day) and when it left (last closing the door), thereby estimating the total time spent in the room.

image

Impressions of use


The overall experience of exploitation is purely positive. Of course, there are some minor nuances, but the main goal of automation is achieved. First of all, it is psychological peace of mind, confirmed by test results. Also important and comfort — was received remote control of street lighting, extractor hood, there is an additional night light. Having gone on holiday, it is possible to remember and remotely to switch off water.

Costs of all the above devices in approximate form (without reference to a particular store) are shown below. When ordering with AliExpress the prices will differ in a smaller direction.

image

When choosing a set of equipment, you must consider compatibility (for which region the equipment was manufactured and which family it belongs). It will not be possible to create a scenario within the application which, for example, will control a socket for a European region according to a smoke alarm event (for the China Mainland region). If you don't need the exotic smoke sensor type, it's better to look at the Aqara devices for the local market. After all, the relay can be replaced, for example, with a two-key switch. A number of stores selling Xiaomi devices seem to be importing them in gray (these devices are for the Chinese region). But, for example, Svyaznoy, there are devices designed for our market. Besides compatibility of the same sockets, they will also have instructions in English and Russian. Below are photos of two identical sensors, but for different regions:

image

The responsiveness of control through an application is not always good. For example, sometimes you may encounter a situation where you get a «request failed» error instead of turning on the light one after another. Experimentally detected treatment — unloading the application from memory and restarting it — solves this problem faster than waiting for a response at the next attempt. There are also sometimes noticeable delays (up to 20-30 seconds) with the update of the status of a particular sensor. At these moments it is better not to press the on/off buttons again, but simply to wait for the status update. When starting the application, in some situations you may see a blank list instead of the device list. There is no need to panic — it usually appears within the next few seconds. Alerts to the phone are not localized and save the correct naming of the events themselves. In addition, the authors of the application periodically use the push-alert channel for advertising (again in Chinese). Of course, I don't like it, but I don't have much choice.

I hope this article has helped to get a good idea of the capabilities of a number of Xiaomi devices to build a smart home and scenarios for their practical application. If you still have any questions, corrections and additions, I will be glad to discuss them in comments.