Allow Zabbix monitoring to switch office lights
Posted on di 29 december 2020 in home_automation
As my wife is not a big fan of the colored Hue light bulbs, I removed a couple of them from the living room. One of the bulbs is now delivering pink, blue or red light in the bedroom of our youngest. The other bulb was moved to my home office. And thus the need for monitoring integration was born. This is nowhere near a new idea, but I have never taken the time to set something like this up. So it seemed a nice X-mas downtime project.
I had already experimented with the python Phue library to control the lights in our home. And I created a custom Zabbix -> signal integration in the past. So it should be fairly easy to combine the two in something nice.
The setup is as follows:
[zabbix host] -> [VPN] -> [raspberri pi at home] -> [Hue controller]
I thought about creating an API on the PI, but thinking about it, just using a password less ssh setup seemed just as good. So that is what I ended op doing.
The script controlling the light just does a number of loops, switching the light briefly to red and white. There is also a testversion of this script that I run from cron to check the system still works. This script changes the light from blue to green and back a couple of times.
Hue script:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 |
|
The zabbix alertscript is like really trivial. Passing the alert text as morse code seemed over the top.
root@monitor:/usr/lib/zabbix/alertscripts# more set_office_alert.sh
#!/bin/bash
ssh 10.20.XX.YY /home/zabbix/bin/office_alert.py
Testing the alertscript from zabbix resulted in this:
Now we wait for a critical alert to actually trigger this :-).