Part 19: Automatic temperature control

Control your AC with Zabbix

Can you control your air conditioner 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 and Grafana and do some weird experiments with them. Welcome to my weekly blog about this project.

About two months ago I added our recently bought air conditioner to Zabbix monitoring by utilising MQTT. Reading values is nice and mandatory for monitoring, but can we also send commands to air conditioner using Zabbix? Yes.

Testing, testing

MQTT is a little unknown area for me, so please don't hit me too hard if I'm doing this completely wrong. Anyway, this seems to work! I know that Zabbix supports MQTT for reading data, but I'm not sure if it can do writing, so that's why I am using command line and external scripts for my example.

At first I tested if my whole idea would work just by using command line:

mosquito_pub command

The mosquitto_pub command might sound like a bar where some summer-time insects spend their free time, but no, this one instead publishes an MQTT message with value 22 to that aircon topic. In other words, I tried to change the temperature to 22 degrees Celsius.

And it worked!

From here, the rest was easy. I created three shell one-liners:

 

  • One for setting AC mode (off, cooling ....)
  • One for setting AC fan speed
  • One for setting AC temperature

 

These then receive the some value from Zabbix by taking the command line argument. Yeah, I know, I didn't add any input validation here.

Example shell one-liner

Adding it to Zabbix

Now that I have my scripts, I next went to Zabbix Administration --> Scripts and added some scripts there.

No alt text provided for this image

I gave these scripts a menu tree structure, so from now on I can control my AC from Zabbix and it looks like this.

Setting fan speed:

No alt text provided for this image

Setting AC mode:

No alt text provided for this image

Setting temperature:

No alt text provided for this image

... and whenever I execute any of these, I get mosquitto_pub command output back, here setting temperature to 22 C.

No alt text provided for this image

Of course, the scripts could be hooked with triggers, so if for example our living room would be too hot, Zabbix could power on the AC automatically. For now, I'm not taking the automatic route as we might not be at home all the time.

A Grafana dashboard

And, like for so many other monitored items, I have a separate Grafana dashboard for our air conditioning as well, values being read from Zabbix. From the dashboard I can easily see whenever our AC has been on or off, what's the fan speed and so on.

No alt text provided for this image

Oh, BTW -- those of you using Zabbix 6.2 and Grafana -- please make sure you upgrade your Grafana Zabbix plugin to at least version 4.2.9 (released July 12th 2022), as the previous versions did not work with Zabbix 6.2 at all. I found this out a hard way at home, but I patiently waited for the update.

I have been working at Forcepoint since 2014 and it never has been cooler to work from home.

 

Add new comment

Restricted HTML

  • Allowed HTML tags: <a href hreflang> <em> <strong> <cite> <blockquote cite> <code> <ul type> <ol start type> <li> <dl> <dt> <dd> <h2 id> <h3 id> <h4 id> <h5 id> <h6 id>
  • Lines and paragraphs break automatically.
  • Web page addresses and email addresses turn into links automatically.
Buy me a coffee

Like these posts? Support the project and Buy me a coffee