Refrigerator/Freezer Monitor

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")}}'

image

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")}}'

image

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.

image

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.

14 Likes

Do you have any pics of the unit installed in the fridge?

I assume the controller box is outside and the temp sensors run thru the seal on the door? any issues with that?

1 Like

The box is outside of the fridge, the door sensors are at the gap in the doors not on the outside/face of them. (I used a small magnet vs the one that comes with the sensors.)

image

For the temperature monitors, I put a small hole in the seal and ran the wires though the seal on my garage fridge since it’s older and I didn’t care as much about it. For the one in the kitchen, I removed some of the outside jacket so the 3 internal wires would lay flat against the door seal. I then used white duct tape to tape it down. I put them at the corners where there was already some small molding. It’s against the wall side of the unit so it really doesn’t stand out but it’s also not the most elegant way to do it.

2 Likes

Well done! I have done the same monitoring for all my fridges and freezers…for a few years now. Love the Dallas sensors. There was some great little tips in your article that I want to implement.

I glad I could help, I appreciate you letting me know. I’ve gotten so much great info from the community, it’s nice to be able to give some back.

This was a great tutorial that got me started with ESPHome and some ESP8266 devices. I missed your tip on stripping back the wire for the sensor, but came to the same conclusion. I enter the freezer near the handle. I happened to have some reed switches lying around from my alarm install days and just used automotive moulding tape to adhere it to the side of the freezer. Could of bought a reed switch like yours, but this was free.

I was using a Thermalworks temperature monitor, and it is still in place since you can walk out and see the temp at a glance. But it’s alerting features are garbage, which sent me looking for your writeup.

I built a second one and placed that near my network rack to monitor ambient temperature. Help me find a better cooling solution in that location. Very helpful little device to deploy around the house.

Great, thx for sharing!
I landed on this page as I had some idea for related use case:

With such freezer temp reading available on a freezer, do you believe it would be possible power off the freezer at certain intervals?

Context:
Combining the temp sensors with a smart power switch, would it be possible to power off the freezer eg at night and power it back on when temp is rising? With some luck I would expect this will make it possible to make optimal use of solar power while limiting the overnight power usage when the sun isn’t shining.
But before I would try such setup I’d like to know if this woud be a realistic use case? Or will the temp rise quickly once the freezer is powered off while the doors remain closed at night?

I have used a zigbee switch from Aqara to turn off the exhaust fan in the laundry room when the temp falls low enough. The temperature is read using a similar ESPHome device as in this tutorial. However, the zigbee switch has a current limitation, so that would be the thing I would check. Also you need to wire an outlet up to a wall switch. But theoretically what you suggest would work.

I used to do something similar with a chest freezer to make it a kegerator. IF you already have a smart switch that can handle the freezer, you could use Home Assistant to control the switching. You could have it drop the temp a little lower when the power is cheaper (free) and then coast up over night. During power failures, the freezer will hold temp pretty well if not opened.

So pardon my ignorance with the “dallas sensors”, I made an air temp/humidity sensor using i2c bus with a sht3xd daughter board, are the data pins for the temperature probes both wired into pin 5 and you figure out the addresses later based on their readings, it assigns an address automatically or something?

Can I also assume DS18B20 is what to look for in the temp probes since the ones you used are out of stock?

Thanks for any response, pardon my ignorance, I’ve been having problems with defrost heaters and would like to maybe get ahead of the next frost build up.

The Dallas sensor have their own addresses built into the probe. Until you connect to them, you won’t know what they are.

image

Read the Getting Sensor IDs section here:
https://esphome.io/components/sensor/dallas.html

For the sensor probes, yes DS18B20
On the Bezos Family Store:
https://www.amazon.com/gp/product/B0BJK8BKYG/ref=ppx_yo_dt_b_search_asin_title?ie=UTF8&psc=1

1 Like

Thank you. Yea this will be a project soon.

@bigscience Does this not need a resistor for the temperature sensor?

Thanks so much for the write-up, going to get started on this.

Wanted to share that I have a 2nd freezer/fridge in our garage that I wanted to monitor the freezer temp. Mine (like most new models I assume) has a small opening in the rear of the freezer to install a water line for an automatic ice maker, which I am not using since it’s in the garage. It was perfect size for putting a Dallas temp sensor without any exposed wiring.

1 Like

So in the original writeup, I did not use a resistor but then at some point after updating the ESP, one of my probes “Died”. I replaced the probe and it was still not working. I ended up adding a 4.7KΩ between 3.3V and the data pin as recommended which fixed the problem. I’ll try to update the writeup above with some better schematics, including the resistor.