Development of automation in a smart home
Today I discovered that the light in the corridor does not turn on when entering the apartment, this is due to the fact that I recently redid saving parameters to the database and starting automation.
I have automation written in bash scripts. I used to use python, but now I don't use it because many times I encountered a situation when the python versions changed, the system settings changed, and after that the scripts stopped working, I had to reinstall and reconfigure everything again, which is not very convenient.
I use bash, in principle, they get around all these problems because it is quite stable, no additional utilities and modules are used, I try to minimize the use of any non-standard commands or libraries, for example, even devices that send information in json format, I simply parsed using bash scripts, made several universal ones In principle, it is quite easy to analyze even large descriptions of the state of devices.
I have made it so that at the entrance to the apartment there is a door opening sensor, there is a motion sensor, if there has been no movement for a long time and the door opens, and the time there is appropriate, from 7 to 12 at night, then the light turns on. I use a sensor at a frequency of 433MHz, the signal is sent through my gateway, and then transmits via MQTT to the smart home system, and when the parameter is saved, I run an automation script that checks all possible automation, including triggering to open the door.
In order to properly process all possible combinations, I load data from the server in this script, this is quite a lot of parameters about one and a half thousand parameters, but this is basically quite simple and does not take long to process, it takes no more than 1 second, I experimented a lot and tried to do it faster, but in fact it is enough already acceptable.
If you suddenly don't need to use any faster ways to respond, for example, if again this is the entrance to the apartment or this is the entrance, for example, to the bathroom or toilet, and so that there is no delay when turning on the light, then I use alternative options specially tailored to specific situations.
I use several types of automation. This is automation that is triggered when sending a value to the smart home server. In this case, the current value is checked, the old value is checked, all possible combinations of sensors are checked, for example, so that they are turned on or off, the time between trips, including the trips of the sensor itself that sent the signal, and the second type of automation is triggered by a timer, it starts by time, I have now done that this script runs every 10 seconds, it checks all kinds of combinations and situations according to the data, it can also be turning off the light if it is lit for a long time, it can be triggered by a timer, by time, or it can be earning by temperature, humidity, and any others.
I have a general triggering of all scripts and processing occurs somewhere in the order of two or three seconds. For example, if you left the bathroom and opened the door, the fan will work for 5 seconds or 10, check the humidity status, check the door opening status, and if the conditions are appropriate, the fan will turn off. The same thing happens in the corridor, it checks whether the motion sensor stopped detecting people, whether the light was turned on, whether it was on for more than 30 seconds, if all the conditions were met, then the light turns off accordingly.
I also send information to the Yandex smart home system. Recently, they made an additional update that you can send the status of sensors to the smart home system, and based on this information, you can make different triggers and scenarios. The Yandex smart home system interacts with other systems in several ways. This can be a periodic survey of the status of sensors and the smart home system, or when the smart home system itself poisons the request to Yandex and transmits information about device changes. This allows you to get information about device changes much faster and make different scenarios for triggering triggers.
The value of the parameters of my sensors is also transmitted to the Yandex system. For example, from sensors running on batteries, I also transmit the state of charge of the battery in addition to the necessary parameters. The system itself does not provide this attribute - it's just a voltage. Usually it is intended to save the voltage in the electrical network, i.e. 220-230 volts, and the parameter itself is an integer and does not allow you to save a fractional value, and the battery voltage level is of course quite low, and it is important to track the hundredth values of volts.
And there is a feature of the Yandex smart home system that if, for example, you request a temperature, it really likes to combine the value of all the temperatures in the room. Sometimes this gives an erroneous value, for example, if one temperature sensor measures the temperature in the room, another measures the battery temperature, the third measures the temperature outside or something else, then the average temperature is completely incorrect. If the script does not match the parameters, then of course I will not transmit it, for example, if I now request the temperature in the room, it will show around 20 degrees, because I have a sensor that does not work and transmits zero temperature, other sensors transmit air temperature.
Automation in a smart home should be useful and create additional comfort, but sometimes everything goes wrong… The reasons for this, and how to configure everything, see on my channel.