Can you automatically control the temperature of your home in a time- and room-based manner using Zabbix? Of course, you can!
By day, I am a monitoring technical lead in a global cyber security company. By night, I monitor my home with Zabbix & Grafana and make some weird experiments with them. Welcome to my weekly blog about this project.
Earlier in this blog series, I made Zabbix read the status of our air conditioner, and made it possible to use Zabbix as manual remote control for the device. But we need to take a step further and make Zabbix control the AC based on the time of day and if I am at home or not.
Table of Contents
Forget the sweaty nights
Usually in Finland during the summer, the nights are not so hot that an AC would be needed. However, that can happen during any rare heat wave we get. It’s annoying to wake up in the middle of the night all sweaty and turn on the AC when it’s already too late.
Of course, I could just leave the AC on when I go to bed, but let’s make Zabbix do some good for our electricity bill and for the environment by not using the AC when it’s not needed.
Detecting if I am at home
Like so many times before in this blog series, Cozify smart home hub is the true star of this story. It detects if anyone is at home based on if a specific phone or, for example, a smart key fob is present and reachable in Cozify’s range. For this case, I will be using my smart key fob in Zabbix, too. This is how it looks in Cozify.
… and here’s the key fob reachability status in Zabbix.
Surprisingly enough, it shows 1 (or “True”) as my status now that I type this blog entry at home and my keys are at home.
A deeper dive into my key fob Zabbix item
To make this all work, I have a set of Python scripts gathering data from Cozify via an unofficial Cozify API Python library. One of the scripts gets the reachability status for all the items, and here’s the configuration for my key fob Zabbix item.
… and some preprocessing …
Let’s add some triggers
Now that we have the key fob data, let’s create some triggers to combine the data about my presence with the temperature information.
I created the triggers by using Zabbix expression constructor:
.. and when I was done, this is how it looked.
I made a similar trigger for our living room, too.
Next, some scripts
Next I added some scripts under Zabbix Administration → Scripts and made them as Action operations.
This one turns on the AC:
… and this one turns it off.
Lights, camera, action!
We have our triggers and scripts, great! Next, it’s time to add some actions.
- During the daytime, Zabbix will be interested in the living room temperature and will turn on AC if the temperature goes over 23C for ten consecutive times
- During the nighttime, Zabbix will be reading the temperature of our bedroom and turn on AC if the temperature goes over 23C for ten consecutive times
We will see how well my attempt at this will work. Here’s what the operations look like — if it’s too hot, turn on the AC, and when the temperature comes down enough, turn off the AC.
As I built this thing while I was writing this blog entry, it’s possible I would need to fine-tune the thresholds somewhat to not make my automatic AC control too aggressive. Anyway, this now works in theory.
Oh, BTW, Cozify could also make similar rules, but as it does not directly support our air conditioner (but would require a separate Air Patrol device for that), this is again a great example of how I can utilize Cozify, but with Zabbix extend my home’s IoT functionality even more for free.
I have been working at Forcepoint since 2014 and always try to find out new ways to automate things. — Janne Pikkarainen
This post was originally published on the author’s LinkedIn account.