Monitor the Refrigerator

Monitor the Refrigerator

My wife helps run a cat rescue called purrnation. They have had some problems with stable power which presents a problem with keeping the vaccines in the refrigerator below a certin temp. After telling me this, I decided I could help her monitor that pretty cheaply. After some googling I found that of course this problem has been solved in the Raspberry Pi comminuty.

All I needed was a

I accuired a pretty common DS18B20 tempature sensor. I like this kit because it came with a small IC to connect the probe to the PI. I also used some large heat shink to keep it all together and not accidently get pulled apart.

I went with the ‎Vilros Raspberry Pi Zero W Complete Starter Kit-Premium because it came with everything I needed which is the PI, header pins, heat sink, SD Card, USB Hub and Power supply all for $40. I needed the USB Hub to hook up the UPS so I could monitor that also.

For the display I used this i2c OLED diplay from Adafruit. I like that its made ready to sit on the PI and not use all the freaking pins. In retrospect I sould of looked for something a bit bigger as the 128x32 pixel size is a bit hard to read.

There are MANY options out there for monitor and alerting. My goto is monit for most simple things. It really easy to configure, quite reliable and you can do many things with it.

Here is the code I wrote to tie it all together.

So the script just polls the temp of the refrigerator every 2 seconds and stores all the results in memory for the last 5 minutes. This includes the current temp, min, max, avg, time, and previous poll tempature. All displayed on the OLED after each poll. I also create a rolling average that I use for monitoring and alerting. The script also writes the current result set as json to a file. The script which monit runs just reads in the json and sets the exit code to floor average on the current run. Monit has a conditional that if the exit code is above a threshold (38deg) for 5 cycles (5 minutes in my case) then it alerts.

The PI is connected to a APC UPS that has a USB interface so the PI also runs apcupsd. This means an alert will go out when the site looses power and other alert will go out if that power outage means the tempature in the fridge is nearing critical.