DEV Community

Cover image for A smart home with a pet cat: how to automate your daily routine at home
ispmanager.com for Ispmanager

Posted on

A smart home with a pet cat: how to automate your daily routine at home

Can you automate your home so that the kitty litter box sends messages to WhatsApp letting you know it needs to get cleaned, and the TV displays a message when the bathroom is free? Our community manager Igor Gubaidullin, an engineer with 20 years of experience, told us about it.

The smart home concept became a hobby of his five years ago. It started with nascent steps to master Apple HomeKit and ended with a dedicated smart home server running Home Assistant.

My smart home is an ordinary one-bedroom apartment, where the temperature, lights, and household appliances like the robot vacuum cleaner or rolling blinds are automated through the open-source Home Assistant platform. I am completely satisfied with this platform, although from time to time, I still refine or reconfigure certain things when my habits change. Most recently, I switched out the motion sensors for presence sensors, achieving far greater accuracy of automation.

It all started with Apple

I've always been a big fan of Apple and its ecosystem. Apple has its own smart home system called Apple HomeKit, and when I became interested in the smart home concept in early 2019, I already had an Apple TV set-top box and other Apple stuff.

To start building a smart home, you first need a hub – a head device that integrates all the components of your smart home into a single system. For Apple, this role can be performed by an Apple TV set-top box, a HomePod speaker, or, until recently, an iPad. If you have one of these devices, you can get started by buying sensors and setting them up.

Image description
Devices for Apple HomeKit may include an Apple TV set-top box, a temperature control sensor, a door or window opening sensor, a smart lamp, a smart outlet, and a smart LED strip

So my existing Apple TV set-top box served as the starting point for my research.

Right off the bat, I'll note one unpleasant feature of the commercial systems out there: only compatible, pre-approved devices can be used with them. This is true for Apple, Xiaomi, Tuya, Aqara, and so on.
Right from the start, I opted for an unconventional approach – instead of installing light bulbs and smart sockets all over the house, I decided to start with climate control. I found a HomeKit-compatible air purifier online, installed and set it up. It was easy, everything worked right out of the box. It was even a bit boring. 🙂

Right after that, I wrote a review article on Sprut.AI, a popular portal at the time.

Image description
The Apple HomeKit Airwasher

After a while, I came across a thermal head for regulating the radiator temperature which is also compatible with Apple HomeKit. I wrote another detailed review about it when I integrated it.

Naturally, I was lying about the lights. I tried to install a Koogeek smart light switch. But it turned out to be incompatible with the wiring in the apartment. I couldn't integrate it so I had to sell it on Avito.

Expanding HomeKit's capabilities with Homebridge

All the above just served as an appetizer. So I decided to push ahead and soon found a manual for building an ESP8266-based sensor for monitoring the ambient concentration of carbon dioxide. I learned that if the CO2 level in the room is too high, it can cause headaches. “Useful,” I thought, and got on AliExpress to buy the parts. I placed the orders, waited, assembled them, flashed the firmware, and surprisingly, it all worked. However, there was a nuance – my homemade sensor was of course not certified by Apple so it would not work as part of my smart home.

But there is hope thanks to open-source projects like Homebridge. The latter allows you to connect any device to Apple HomeKit, even incompatible ones. Homebridge is a software layer between Apple HomeKit and all your gadgets not certified by Apple. But to run Homebridge, you need at least a very primitive home server. So the next stage of building a smart home was to purchase a Raspberry Pi.

Image description
My Raspberry Pi

It was easy to deploy Homebridge on my new SBC, after which I was finally able to connect my homemade CO2 sensor to the system. Now, if the room gets stuffy, the air purifier automatically starts, and I know it’s time to open a window. I later realized that the air purifier itself has no effect on the CO2 level so I addressed this. I’ll explain what I mean, so that you do not repeat my mistake without realizing it.

The air cleaner cleans the air from dust and odors, but it cannot get rid of CO2. Right now, my system runs on forced air supply. There is a hole drilled in the wall of the house that opens to the street. It has a fan with a filter that blows air in from outside, cleans it, and delivers it to the room. The CO2 sensor works in conjunction with this supply system. If the carbon dioxide level is above 1200 ppm, you could get headaches and fatigue. I have set up the system so that when the concentration is above 1000 ppm, the air supply is automatically turned on, and when it drops to an acceptable level, it is turned off.

Given the opportunity to connect any third-party device to the smart home, I started buying various sensors from Aqara, Xiaomi, and Tuya and integrated them into Apple HomeKit. Plus, I built a few more ESP-powered homemade devices. However, they have a significant disadvantage for my use case: they only work over wifi with specialized energy-efficient protocols for a smart home. I really like Zigbee: it only takes one battery to power a sensor, and it will last for years without needing to be replaced. Plus, wifi devices need external power (I know, CO2 sensors, even Zigbee ones, are not battery-powered, but I’m talking about other devices). Moreover, the devices cannot be used for signal relaying, unlike Zigbee, where each device can act as a router for any of its neighbors that are not in direct contact with the hub. However, we have to live with the fact that a smart home incorporates gadgets on wifi, Zigbee, and even Bluetooth.

Everything is evolving, and soon, this menagerie of protocols will be replaced by a single convenient protocol – Matter. There are already devices that support it on the market. They say that it will make everything easy and simple. We’ll see.

Taking Home Assistant to the next level

After a while, Apple's system became claustrophobic for me. I wanted to create more complex automation options than the ones provided by the vendor. For example, I wanted the lights to come on in specific places when certain conditions were met, or to start chains of actions when certain complex conditions or threshold values on the sensors were reached. Simply put, a smart home is defined by the automation of routine processes. Everything is configured so that in routine scenarios, certain actions are performed without human involvement. Without a certain level of complexity (by HomeKit standards) scenarios this isn’t possible.

This was the impetus for my decision to expand my smart home system beyond Apple HomeKit to incorporate an advanced sensor system that can serve as an automation engine and a hub for other devices. I chose Home Assistant, although I also tried Node-RED, which is popular in some circles. Home Assistant’s huge community and wealth of publications online helped it win out. So I decided to deploy Home Assistant on my Raspberry Pi, meaning that I wouldn't need Homebridge anymore.

At that time, if you installed Home Assistant, you had to be prepared to spend a lot of time on the command line. This didn't scare me, rather, I turned it into my new hobby, as I had never had any problems with Linux thanks to my professional background. Despite the rigorous demands of Home Assistant (especially its early versions) on the user, it offered expansive possibilities, allowing me to fine-tune all my devices and the interconnections between them. The large Russian-speaking community on Telegram was very helpful, and there is quite a lot of information on YouTube. My capabilities grew, and along with them, my smart home began to develop in new, dynamic ways.
Apple TV went from being my main controlling device to being a humble multimedia component of the system. Since one of Home Assistant's functions is to serve as a bridge with Apple HomeKit, anything connected to Home Assistant can be added to HomeKit as well. So I can still control my smart home and all connected devices through the Home app on my iPhone, or, say, ask Siri to raise the curtains in my hall.

At first, I deployed a system based on Raspberry Pi, but the Raspberry Pi has certain drawbacks – an unreliable disk subsystem based on an SD-card and a noisy cooling fan which kept my wife awake from the next room. 🙂 So I found a ready-made Gigabyte mini-PC with a silent passive cooling system and an SSD drive.

Image description
My Gigabyte mini-PC with a Zigbee USB stick as a UD server

It's also much more powerful; the possibilities for my smart home have increased significantly. However, after a while, even this server became cramped, so I ordered another, even more tricked-out one on AliExpress. As a rule, most people have enough Raspberry Pis and get a computer if they need to connect surveillance cameras. I had cameras already, but the overall speed and responsiveness of the system increased dramatically with the transition to the new hardware. Besides, the mini-PC started to serve as a file and media server on top of its role as a smart home server.

How it all works now

That's not to say that getting a smart home to work right is easy. Everyone in my family had their own vision, even the cat. We had to make compromises and bend over backward to make it amenable for everyone. For example, the sensors to control the lights had to be configured so that they could see people but not the cat, and the automation schedule had to be fine-tuned to fit my wife's schedule.
It took months to customize the interface; we wanted it to be clear and easy to use.

Here is everything I managed to automate.

Light in the kitchen. The kitchen is equipped with decorative lighting (above the table, kitchen unit, and on the ceiling), as well as light for my wife's work table. I did not automate the main upper light, it is controlled either manually or by voice.

The automation works like this – when someone enters the kitchen, depending on what the light sensor picks up (a number of threshold values are set), when the presence sensor is triggered, a group of lights is turned on, but not the upper light. At night, only the ceiling light is switched on, resulting in a dimmed glow. To automatically switch off the light, there are a few conditions – it only goes off when the presence sensor data shows that there is no one in the room, and the motion sensor shows that my wife is not at her desk.

Scheduled curtains. It’s simple, but it’s our family's favorite automation, the automatic opening and closing of the curtains. We have blackout roller blinds installed on our windows. They are controlled by Aqara chain motors. The curtains have their own triggering conditions: the system determines whether today is a working day or a day off (Home Assistant can be set up according to the holiday calendar), whether one or another family member is at home, and so it raises the curtains earlier in the morning on weekdays or later on weekends and holidays. They close by themselves, at sunset. Of course, they can also be controlled by voice, Siri is always at your service.

Watering the flowers. We also have automated notifications that it's time to water our flowers thanks to our soil moisture sensors. The system sends messages to us all in Telegram, and if anyone is home, Alexa, in a loud and stern voice, demands that we take care of the plants. Of course, there are more sophisticated Zigbee sensors and even entire drip irrigation systems, but I don't see the point in bothering with them, since our family only has a couple of ficuses.

Image description
Smart curtain, air inlet and Zigbee sensor for ficus

Sensor for the kitty litter box. There is a vibration sensor on the kitty litter box so when the cat visits it, the extractor fan in the bathroom automatically turns on. Then we all receive an urgent notification on Telegram to perform a hygienic procedure on the litter.

Image description
Vibration sensor on the cat litter box

Indoor humidity. Another sensor detects the level of ambient humidity. If the room gets too dry, the humidifier automatically turns on. It switches off if the humidity rises above the set level. You just have to keep an eye on the water level in the humidifier.
Bathroom occupancy. Sometimes, our daughter occupies the bathroom for long periods of time while my wife and I watch TV. To avoid knocking every half hour, I have set up a notification display right on our TV screen. As soon as my daughter gets out of the bathroom, we see a message, “Yay, the bathroom is free.” When anyone occupies the bathroom, the TV notifies us of that too.

Christmas tree lights. Our Christmas tree is decorated with an addressable LED strip with an ESP32-based control and WLED firmware. You can activate any of its many beautiful effects. It’s a popular item and very easy to integrate. I set up automation in Home Assistant so that every 10 seconds, a new random effect is randomly selected from the huge effects database.

My smart home can be accessed from anywhere in the world as long as I have internet. This uses Cloudflare Tunnel with a secure, encrypted connection. So when we go on vacation, vacation mode is automatically triggered and everything that should not be on is turned off, the radiators are switched to light heating mode in winter, and so on. If necessary, we can use a phone app to turn something specific on or off.

Autonomy. My smart home system is not connected to any cloud, is completely autonomous, and depends only on power mains. Even this can be circumvented with a UPS. I have set up an uninterruptible power supply system that will keep my entire smart home running for 6–7 hours.

Security. As for the security of the devices themselves, well, buyer beware. Clearly, in the abbreviation IoT, the letter S stands for Security :)

Saving money on a smart home and my future plans

People often think that a smart home will save them money. No.

On the one hand, of course, it is possible to optimize the consumption of some resources through automation: I pay for heating based on how much I consume. My smart home system controls the consumption of electricity and filtered drinking water. It can be set up so that everything is converted into rubles at the current rate.
On the other hand, a smart home is an expensive thing to set up. Think of all the hubs, sensors, various devices, cameras, the server, and your time... So I consider it an expensive hobby, not a silver bullet for solving every problem. There is no real benefit to a smart home, unless of course, you count the comfort and convenience it creates for you and your family members. Plus it's a heck of a lot of fun, provided you like to mess around with hardware and program scenarios and automations as per a plethora of parameters.

I've now reached a state where everything is set up, debugged, and running almost as intended. I don't have any clear plans for the further development of my smart home, I’ll add new things as the need arises.

But I will be happy to get your opinion and constructive suggestions in the comments.

More interesting articles and guides - on the ispmanager blog

Top comments (0)