Skip to header Skip to main navigation Skip to main content Skip to footer

Search form

Site branding

Home
What's up, home?

Main navigation

  • Home
  • Story mode
  • About
  • Features
  • Hardware list
  • Videos
  • GitHub (opens in new tab)
  • Daily AI generated stories (opens in new tab)

Part 19: Automatic temperature control

Breadcrumbs

Breadcrumb

  • Home
  • Part 19: Automatic temperature control

Main page content

By whatsuphome | 12:01 PM EEST, Thu July 14, 2022

TL;DR

I extended my Zabbix air conditioner monitoring to also control it using MQTT commands via mosquitto_pub for setting temperature, fan speed, and AC mode. Shell one-liners receive values from Zabbix scripts, and a Grafana dashboard provides an interface
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.

 

whatsuphome
zabbix
grafana
mqtt
airconditioner
remotecontrol
part18
  • 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.
I extended my Zabbix air conditioner monitoring to also control it using MQTT commands via mosquitto_pub for setting temperature, fan speed, and AC mode. Shell one-liners receive values from Zabbix scripts, and a Grafana dashboard provides an interface

Search

Who am I?

  • Janne Pikkarainen from Finland 🇫🇮
  • Began with computers in 1986 with C64
  • Doing IT for living since 1999
  • Principal Site Reliability Engineer at Forcepoint
  • A Zabbix Summit speaker every year since 2022
  • Walking, talking Zabbix commercial

Support my project

Buy me a coffee 

Footer menu

  • Contact

What's up, home? | Janne Pikkarainen | contact(at)whatsuphome.fi | 2022 - 2026

Developed and Designed by Janne Pikkarainen