Refrigerator/Freezer Monitor
A few months ago our main refrigerator started to have problems and were detected by the “milk is to warm” children sensor. I ended up cleaning the fins which solved the problem, but it made me nervous about what would happen if it actually had failed. I decided I needed a better sensor (or set of them) to keep an eye on the unit and alert me if there were any issues. A few days ago my garage fridge actually died but Home Assistant helped me avoid the loss of food and a mess to clean up. I thought I’d share my project here as it could help out someone else.
I’ve been making a number of room sensors using ESPHome and Node MCU units and they have been cost effective and easy to set up. For the refrigerator setup, I wanted to monitor the temperatures of the refrigerator, freezer, open doors and have a leak sensor by it as well (if you’ve got extra pins, why not use them?)
Rather than using a DTH inside the box, I decided to try out Dallas sensors:
Reed switches for the doors:
Leak Sensor (basically 2 metal tips with some plastic):
Project Box to hold it all:
Jovitec 8 Pieces Plastic Waterproof Boxes Junction Case for Electronic Project, 100 x 60 x 25 mm, Black
I won’t fully go into how to setup and program a device in ESPHome here but if you don’t already use it, it’s pretty nice and you should give it a try. Here is the code for the sensor to flash to the ESP8226:
esphome:
name: garage
platform: ESP8266
board: nodemcuv2
wifi:
ssid: !secret wifi_ssid
## hidden: true
password: !secret wifi_password
## power_save_mode: none
fast_connect: true
# Optional manual IP
manual_ip:
static_ip: 192.168.1.161
gateway: 192.168.1.1
subnet: 255.255.255.0
# Enable logging
logger:
# Enable Home Assistant API
api:
password: !secret api_password
ota:
password: !secret ota_password
safe_mode: true
# Sync time with Home Assistant
time:
- platform: homeassistant
id: homeassistant_time
# Text sensors with general information
text_sensor:
- platform: version
name: "Garage version"
- platform: wifi_info
ip_address:
name: "Garage ip"
ssid:
name: "Garage ssid"
bssid:
name: "Garage bssid"
dallas:
- pin: D5
sensor:
# Uptime sensor
- platform: uptime
name: "Garage uptime"
# WiFi Signal sensor
- platform: wifi_signal
name: "Garage wifi signal"
update_interval: 60s
- platform: dallas
address: xxxxxxxxxxxxxxxxxxx
name: "Garage Fridge"
- platform: dallas
address: yyyyyyyyyyyyyyyyyyy
name: "Garage Freezer"
binary_sensor:
- platform: gpio
name: "Garage Fridge Leak"
device_class: moisture
pin:
number: D6
mode: INPUT_PULLUP
- platform: gpio
name: "Garage Fridge"
device_class: door
pin:
# GPIO10 = SD3
number: 10
inverted: True
mode: INPUT_PULLUP
- platform: gpio
name: "Garage Freezer"
device_class: door
pin:
# GPIO9 = SD2
number: 9
inverted: True
mode: INPUT_PULLUP
At first, you won’t know the address of your Dallas sensors so exclude them for the first upload. You can change the temp of one of them and then note its address in the logs in ESPHome. You can then put in into the program. It’s important to hard code them because if the order they load somehow changes, they will be wrong to Home Assistant.
In Home Assistant, I created some Automations to alert me of certain conditions. Since I have 2 Refrigerators, I was able to group some things together. This automation will send me an alert if the door has been left open:
####################### Door Alerts #########################
- alias: Fridge Door Left Opened
trigger:
- platform: state
entity_id: binary_sensor.kitchen_fridge_door
to: 'on'
for:
minutes: 3
- platform: state
entity_id: binary_sensor.kitchen_freezer_door
to: 'on'
for:
minutes: 3
- platform: state
entity_id: binary_sensor.garage_fridge
to: 'on'
for:
minutes: 3
- platform: state
entity_id: binary_sensor.garage_freezer
to: 'on'
for:
minutes: 3
action:
service: notify.mobile_app_brads_iphone #notify.ios_brads_iphone
data_template:
message: 'The {{ trigger.to_state.name }} was left opened! - {{now().strftime("%H:%M:%S on %m/%d/%y")}}'
One of the other things I really wanted was to know if the door had been closed after being left open. This will send an alert once the door has been closed after being left open. It requires the creation of an input Boolean for each door to be tracked:
########################### Kitchen #############################
- alias: Kitchen Fridge Door Left Opened
trigger:
- platform: state
entity_id: binary_sensor.kitchen_fridge_door
to: 'on'
for:
minutes: 3
action:
- service: input_boolean.turn_on
entity_id: input_boolean.kitchen_fridge_left_open
- alias: Kitchen Fridge Closed
trigger:
platform: state
entity_id: binary_sensor.kitchen_fridge_door
to: 'off'
action:
- service: input_boolean.turn_off
entity_id: input_boolean.kitchen_fridge_left_open
- alias: Kitchen Fridge Closed Notification
trigger:
- platform: state
entity_id: input_boolean.kitchen_fridge_left_open
to: 'off'
action:
service: notify.mobile_app_brads_iphone #notify.ios_brads_iphone
data_template:
message: 'The Kitchen Fridge Door has been closed after being left open. - {{now().strftime("%H:%M:%S on %m/%d/%y")}}'
- alias: Kitchen Freezer Door Left Opened
trigger:
- platform: state
entity_id: binary_sensor.kitchen_freezer_door
to: 'on'
for:
minutes: 3
action:
- service: input_boolean.turn_on
entity_id: input_boolean.kitchen_freezer_left_open
- alias: Kitchen Freezer Closed
trigger:
platform: state
entity_id: binary_sensor.kitchen_freezer_door
to: 'off'
action:
- service: input_boolean.turn_off
entity_id: input_boolean.kitchen_freezer_left_open
- alias: Kitchen Freezer Closed Notification
trigger:
- platform: state
entity_id: input_boolean.kitchen_freezer_left_open
to: 'off'
action:
service: notify.mobile_app_brads_iphone #notify.ios_brads_iphone
data_template:
message: 'The Kitchen Freezer Door has been closed after being left open. - {{now().strftime("%H:%M:%S on %m/%d/%y")}}'
The next item to track is the actual temps of the fridge/freezer. At first one of the things you’ll notice once you start to monitor your systems is that they will cycle or defrost. This can cause a spike in temp that can cause you false alerts. One way to deal with this is to have tiers and delays on alarms. For here, I don’t want to get an alert unless my fridge is above 40F for more than 30 min but if it goes to 50F for more than 5 min. Another thing to stabilize the readings is to put the probe into a container with a liquid. You can use something like glycerol, oil or something else you wouldn’t care if it spilled.
This is set up so you can add multiple other devices if needed for alerts:
############################ Temp Alerts ##########################
- alias: Fride Temp Alerts
trigger:
- platform: numeric_state
entity_id: sensor.kitchen_fridge
above: 40
for:
minutes: 30
- platform: numeric_state
entity_id: sensor.kitchen_fridge
above: 50
for:
minutes: 5
- platform: numeric_state
entity_id: sensor.kitchen_freezer
above: 10
for:
minutes: 20
- platform: numeric_state
entity_id: sensor.kitchen_freezer
above: 20
for:
minutes: 5
action:
service: notify.mobile_app_brads_iphone #notify.ios_brads_iphone
data_template:
message: '{{ trigger.to_state.name }} {{ trigger.to_state.state }}F temperature alert! - {{now().strftime("%H:%M:%S on %m/%d/%y")}}'
As with the doors, I wanted to know once the temperature has returned to a normal state, say after groceries were loaded. One time “someone” loaded a few cases of beer into the drinks fridge which caused the temp to rise. I was able to get an alert once it had gone back down.
As before, input booleans are needed:
########################### Kitchen #############################
- alias: Kitchen Fridge Temp
trigger:
- platform: numeric_state
entity_id: sensor.kitchen_fridge
above: 40
for:
minutes: 30
- platform: numeric_state
entity_id: sensor.kitchen_fridge
above: 50
for:
minutes: 5
action:
- service: input_boolean.turn_on
entity_id: input_boolean.kitchen_fridge_temp_alert
- alias: Kitchen Fridge Temp Return
trigger:
- platform: numeric_state
entity_id: sensor.kitchen_fridge
below: 40
action:
- service: input_boolean.turn_off
entity_id: input_boolean.kitchen_fridge_temp_alert
- alias: Kitchen Fridge Temp Return Notification
trigger:
- platform: state
entity_id: input_boolean.kitchen_fridge_temp_alert
to: 'off'
action:
service: notify.mobile_app_brads_iphone #notify.ios_brads_iphone
data_template:
message: "Kitchen Fridge temperature alert cleared ({{ states('sensor.kitchen_fridge') }}F) - {{now().strftime('%H:%M:%S on %m/%d/%y')}}"
- alias: Kitchen Freezer Temp
trigger:
- platform: numeric_state
entity_id: sensor.kitchen_freezer
above: 10
for:
minutes: 20
- platform: numeric_state
entity_id: sensor.kitchen_freezer
above: 20
for:
minutes: 5
action:
- service: input_boolean.turn_on
entity_id: input_boolean.kitchen_freezer_temp_alert
- alias: Kitchen Freezer Temp Return
trigger:
- platform: numeric_state
entity_id: sensor.kitchen_freezer
below: 0
action:
- service: input_boolean.turn_off
entity_id: input_boolean.kitchen_freezer_temp_alert
- alias: Kitchen Freezer Temp Return Notification
trigger:
- platform: state
entity_id: input_boolean.kitchen_freezer_temp_alert
to: 'off'
action:
service: notify.mobile_app_brads_iphone #notify.ios_brads_iphone
data_template:
message: "Kitchen Freezer temperature alert cleared ({{ states('sensor.kitchen_freezer') }}F) - {{now().strftime('%H:%M:%S on %m/%d/%y')}}"
The boxes I chose offer just enough height to use a small bread board and some small terminal blocks:
GeeBot DIKAVS 70pcs 5.08mm Screw Connection PCB Terminal KIT
I drilled 3 holes in the end of the box, 2 for the sensors and one in the middle for power.
So far the systems have been working as intended and based on my experience in the last week, it was well worth my effort to set up. Let me know if you have any questions as I’m sure I left something critical out.