From where 1 million in a smart home

I have been writing a lot of values to a database about various parameters in a smart home for a very long time. I have this database made on an external hosting, because it is internal resources. Of course, if I use a microcomputer with an sd card there, then first of all it will not fit there and will greatly affect performance, and then it will also be quite difficult to analyze this database on this microcomputer, and of course this card may turn off and stop working at all at some point, and of course I would not like to lose this database.

On the hosting I already have a lot of data, I have about 1 million records per month, of course this happens very much and the reasons for this are very different, sometimes there are errors when I just happened to make some script there and it starts, for example, to change the parameter your constantly and these all the values they will be recorded in this database, for example, the device turned on then it turned off after a while or there was a change in the light in the room and each time it started to be recorded, that is, of course, in this way it is very easy to make a million records there with only one parameter if, for example, every 10 seconds to record information for a month, this will be a lot and of course the growth of the database, it will be so unpredictable, so I periodically start optimizing looking for such a parameter and with what frequency it is advisable to record the database, that is, from each it can be a sensor, and from each device it can be very different many parameters to be, that is, it is for example a temperature sensor where the temperature itself is recorded, humidity is recorded, the state of the battery, the quality of communication are recorded, and so of course it all needs to be stored somewhere.

Some values change very often, for example, the same illumination, or let's say I have an electricity meter, it also constantly changes the value and they also have to be recorded, but here I have how it is done that first I keep the base value last in order to access it in principle, and if I need it for what-that is, for example, the value will be, then I save it the previous one, if it changes, for example, I can run some script, but when saving the actual value, it also gets into the database and stays there, that is, of course, I don't aggregate them, I don't delete the old ones, and they are just stored there and if any situations arise, I can open this database and see how the value actually changed by seconds and understand what was happening and of course this is useful information.

But if you do not limit it at all, then it can be recorded every second and then the size will be very large, and so I make it so that where possible I have restrictions, for example, that recording is not more often than once every 10 seconds or once a minute, but only if some large changes occur significantly, more than someone's range, then in this case they are recorded forcibly, but if these are minor changes, for example, there are sockets that measure the mains voltage and it increases there by one volt and drops by one volt periodically, of course, this information is of no value, and in this case, of course, you can record much less often.

But you can generally allow some information to be recorded, for example, once an hour, but I record no more than one hour, so that I then have statistics, there are graphs built exactly for at least an hour, but by and large, once an hour it is quite rare and there are very few records for a month, that is, it is certainly convenient and such parameters that do not change at all they can simply be recorded in order for them to be, or for example 5 sockets in the apartment is worth it, then you can record only one because the voltage is most likely to be the same everywhere, and this change is either an error just measuring a specific outlet, well, or if some powerful consumer is connected to it, then the mains voltage will sink specifically on this outlet and it will show a little less than others, but this is absolutely not necessary information, because this outlet also measures current consumption and in amperes and kilowatts, so in principle it is already visible and of course it makes no sense to track this information through voltage.

I record almost all the parameters of all devices in the database, for example, there are door opening sensors that also transmit a lot of parameters, this is not only opening and closing, but also a plus, for example, the battery and signal strength, and I also save this, firstly in order to see that the battery is there in some status, it will also need to be changed sometime, after a certain time and not miss this moment so that it does not turn off, but the signal also needs to be monitored periodically, because if for some reason the network is incorrectly configured, for example zigbee, then, of course, you will need to see it and fix it, otherwise just this sensor will start to spend a lot of battery and will not last long in this mode of operation and communication quality.

On many devices, of course, there are not so many parameters, for example, they have switches in principle, this is only the state, well, if this is a three-button switch, then the state of each button, well, more precisely, the relay that is tied to this button, and I also write down the total value from this switch in order to generally understand the switch in it is in the on mode, or it is completely off, it is convenient when, for example, I say turn off the light, it is really there, or I press some button that just switches this switch, then in this way I see that something is turned on and it is necessary to turn it off, for example, and not so that part of the relay will be switched to the on state, and part will be switched to the off state, so that there is no such light representation of course.

Different modern devices, such as LED strips or different lamps, they certainly contain a lot of parameters in themselves and of course you need to think every time whether it is necessary to record it or not, for example, if the LED strip has different colors, then there for red, green, blue you also need to have a value, if for example I want to somehow remember them, these colors, and then restore them, or let's say they change to a certain range, shift the value, then of course it needs to be saved somewhere, otherwise it turns out that if I don't know the value, then I can't correctly determine what mode the tape is currently in and somehow process it correctly in scenarios, so in addition to these three colors, the temperature option is still saved, if it's white light, then what temperature it has, if the brightness still needs to be saved, because now it's basically so that there is a separate temperature value if the light is white or a color value, a certain color, then the brightness is also added to this, and there may also be different operating modes, for example, a lamp, this also needs to be saved separately somewhere and there may be quite a lot of different modes and you also need to think about it, but it's certainly easier here if for example it's just a change, then you can save it once and not change it in principle, but for example if there is some dimming, then there are a lot of such values and there, save only at the end when the dimming is over or save each value, but if for example I have for example processing, not all dimmers support the smooth dimming mode, that is, in fact, you need to do it manually, that is, to save the value, then read the last value, change it to some increment, and then change the value and save the base again, and repeat it there several times, as long as you need to turn on a certain brightness or mode there.

A lot of values have to be saved, for example, if I track different devices on the network, that is, if I have about a hundred devices, then for example wi-fi, then of course there is a need to constantly record its value when pinging a device or changing its status, read its value, that is, I used to ping all these devices and a certain time I recorded all the values at all, all this if there are 200 devices there, then I actually had 200 values once a minute, of course once a minute is sometimes long, but by and large for ping on the network this is normal, because not all devices, they don't often respond to ping correctly there, and therefore you can just accidentally calculate that the device is turned off, even though it is turned on, but then I made sure that the changed values are saved, and not each one.

This is not always convenient, but it allows you to save the same number of records in the database, and the database grows in this case already less.

Well, from interesting values, I also record the geolocation of different devices, I have a program installed on my phone that sends my coordinates and of course these coordinates can be sent often there every minute, or if I move, it can be there more often, of course this is a lot of parameters, but if I don't move, there is a setting like this that it sends very infrequently coordinates and it doesn't create a large data stream.

For example, I also record weather data, and in several places, I get information from weather servers on the Internet, but recently I started recording a lot of parameters.

This is not only the temperature, humidity, wind outside or pressure, but also record the air quality outside there, which is also interesting information.

I want to accumulate statistics there in order to understand in general how it changes, what are the spikes, it's very interesting to observe it, and now I also began to record several different locations, which I also sometimes come to and want to know too, what happens there and in what periods of time there is an increased content of what gases and it is probably better not to go there at this time.

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.

You may also watch

Article By Alex

If you have any ideas on how to improve automation, make it more reliable, fast and useful, then you can leave a comment below. I will try to implement the proposals and tell you in the following videos.