Smart Refrigerator w/ESP8266

While the defrost timer in my garage fridge is starting to fail, I have been giving some serious thought about converting it to running off an esp8266.

This is an older GE side by side (circa 1995 when new). The ESP would need to run a single relay to replace the defrost timer, switching between compressor and defroster about every 16 hours (16 hours compressor run, 15 minutes defroster run). I would also want to add two door sensors, one for each the freezer and fresh food side (beer side) and potentially even an audible alarm if a door is left ajar. Also of course, DHT22 temp/humidity sensors. I would also like it to switch back to compressor mode after a short cool off period, if the freezer side would reach a certain temp before the 15 minute cycle is complete, say 40F.

For now I have just been flashing C++ code to create the defrost timer and test durations. Making sure it’s reliable mostly. I have not yet added door and temp/humidity sensors to the code mix. I will do this once I move it to ESPHome.

Does the ESP8266 have enough usable GPIOs to make this possible? Are there certain GPIOs preferred for different functions? I would prefer to mount the ESP inside the fridge near where the original defrost timer resides to simplify wiring. What about moisture? I would have no issues with covering the entire board with either epoxy or hot glue in order to water proof it.

What are your thoughts on this project? Worthy, or should I just replace the failing timer and be done with it? I think it would be really cool (pun intended) to actually pull something like this off. Perhaps somebody already has, but I was not able to find any such project.

2 Likes

You may as well do it. Create a fully ‘smart’ fridge from an old one. Instead of the 8266, use an ESP32 so you can have a camera inside the fridge. Use an output to turn the light on so you can remotely stock-take

Funny you say that. I was thinking of adding one that could “see” the condenser coils so I could visually check for ice build-up, to allow for better defrost cycle adjustments. There are apparently no ice sensors/detectors available, which would have been much more handy I think.

Thanks for the link. Very useful!

If you can model how a partially iced condenser coil impacts temperature, power consumption, etc, you could measure that way. Maybe a bit of rube goldberg here … but could be fun.

1 Like

Last week I connected it to an Emporia smart plug, flashed it to ESPHome and added to HA. It is amazing how much energy this beast uses. It mostly runs 24/7 at ~200 watts while cooling. It uses ~800 watts when defrosting, when it actually does. I have to manually turn the timer about every other day to make it work again. It is consuming more then usual right now, as it is in dire need of a manual defrost. It is problems like these that I want the esp8266 in an attempt to avoid. The defroster and timer were both replaced with new last October, FYI. The defrost cycles seen in the attachment were both manually induced, as the timer was once again stuck.

This might give you something to compare with, similar age refrigerator, still plugging away…

Very cool! Looks like you only have one defroster element versus two in mine, hence mine using 800 watts (just a guess). Are you using one temp/hum sensor per compartment? I was wondering about using two then taking an average from them. Not sure if it would make much difference.

Your power usage grid looks a lot like mine did before it iced up and now runs continuously. I have been manually forcing it into three defrost cycles per day until I have time to defrost it and hopefully get the timer replaced with the esp. I would love to get this done this weekend. My esp8266 is working well enough for that purpose right now, and I have sent it the code for two reed switches and two dht22s, even though it is throwing sensor errors because they are not yet physically connected. They should all be here Saturday morning.

The code is extremely simple right now, after converting it from Arduino to ESPHome. The way it is now it requires complete control from HA automation. I would rather make it completely independent of HA in case wifi goes down, or any number of reasons for HA to loose control over it.

esphome:
  name: fridge_automation
  platform: ESP8266
  board: nodemcuv2

wifi:
  ssid: ""
  password: ""

  # Enable fallback hotspot (captive portal) in case wifi connection fails
  ap:
    ssid: "Fridge Automation"
    password: "AMi0aezQtTKx"

captive_portal:

# Enable logging
logger:

# Enable Home Assistant API
api:

ota:

switch:
  - platform: gpio
    name: "Defrost Relay"
    pin: D2

binary_sensor:
  - platform: gpio
    pin: D3
    name: "Fridge Door"
    device_class: door

  - platform: gpio
    pin: D4
    name: "Freezer Door"
    device_class: door

sensor:
  - platform: dht
    pin: D5
    temperature:
      name: "Fridge Temperature"
    humidity:
      name: "Fridge Humidity"
    update_interval: 30s

  - platform: dht
    pin: D6
    temperature:
      name: "Freezer Temperature"
    humidity:
      name: "Freezer Humidity"
    update_interval: 30s

Duh! I just realized I am going to need a second relay. With one relay, the modes instantly change from compressor- defrost - compressor. This won’t work as there has to be a waiting period between the defroster kicking off and the compressor kicking back on in order to allow the water to completely drain without freezing. Dang! That will complicate things a bit.

I look forward to following your work, good hunting!!!

I am way below where you are planning on going.

My simple setup on this fridge is :

Power monitor on plug using a tasmota based device
One BLE temperature/humidity sensor in freezer section
One BLE temperature/humidity sensor in refrigerator section

That’s basically where I had planned to go too, until the defrost timer failed twice now within 6 mos. Well, the first time it was the defrost heaters themselves, but I changed out the entire system, timer and all. In hindsight, I should have kept the original timer. If I had, I would not be here right now with this project, most likely. I would also have had a working timer for out of fridge testing. DOH!

It’s late now and I am not even going to attempt to get my head around the logic of two very dependent relays. Probably won’t happen this weekend now, but the major defrosting still probably will. It needs to be done because of $$ and a 40F fridge is too warm for beer. The freezer is also not right either. Not at a normal 0F, but instead checking in at a whopping -16F!

1 Like

Make some progress. I added the second relay and the code to support it. Still very much a work-in-progress. The defroster relay is normally closed but not connected to anything until switched to normally open, at which point it feeds the compressor relay normally open side. So the code delays are presently set for seconds for testing, but will be changed to minutes for actual operation.

So the test mode logic goes something like this.

  • Compressor relay switches to normally open mode for 1 second (which is where the defrost circuit is connected, but presently off)
  • Then the defrost relay switches to the normally opened side, feeding the compressor relay.
  • 15 seconds later, the defroster relay switches back to normally closed so no voltage is getting to the compressor relay.
  • 10 seconds later, the compressor relay switches back to normally closed thereby turning the compressor back on.

Now I just need to figure out how to wrap the entire thing into a 12 minute loop (12 hours for actual operation). Any ideas how to do that? Here is the revised code:

esphome:
  name: fridge_automation
  platform: ESP8266
  board: nodemcuv2

wifi:
  ssid: ""
  password: ""

  # Enable fallback hotspot (captive portal) in case wifi connection fails
  ap:
    ssid: "Fridge Automation"
    password: "AMi0aezQtTKx"

captive_portal:

# Enable logging
logger:

# Enable Home Assistant API
api:

ota:

switch:
  - platform: gpio
    name: "Compressor Relay"
    id: comp2def
    pin: D2       #GPIO4
  - platform: template
    name: "defrostmode"
    turn_on_action:
    - switch.turn_on: comp2def
    - delay: 1s   #Change to 60s (1 min) for actual operation
    - switch.turn_on: defroston
    - delay: 15s  #Change to 900s (15 min) for actual operation
    - switch.turn_off: defroston
    - delay: 10s  #Change to 600s (10 min) for actual operation
    - switch.turn_off: comp2def

  - platform: gpio
    name: "Defrost Relay"
    id: defroston
    pin: D1       # GPIO5
  - platform: template
    name: "autooff"

binary_sensor:
  - platform: gpio
    pin: D3
    name: "Fridge Door"
    device_class: door

  - platform: gpio
    pin: D4
    name: "Freezer Door"
    device_class: door

sensor:
  - platform: dht
    pin: D5
    temperature:
      name: "Fridge Temperature"
    humidity:
      name: "Fridge Humidity"
    update_interval: 30s

  - platform: dht
    pin: D6
    temperature:
      name: "Freezer Temperature"
    humidity:
      name: "Freezer Humidity"
    update_interval: 30s

Block Entity
Turning on the bottom switch (defrostmode) kicks in the cycle. I want this to be totally automatic and independent eventually.

I am always open for suggestion too, please.

I am far from a refrigeration expert, however I have often heard that frequent cycling the power to the compressor on a refrigerator will shorten it’s life. FYI, perhaps something to be careful of in your testing.

1 Like

No testing is being done on the refrigerator itself. Just all standalone as you see in the photo. Using a meter to monitor continuity is all…at this point.

So far I am reading that continuous loops in ESPHome may not be possible. Ugh!

Would the time component be of help (Specifically time triggers)?

Perhaps so. Investigating this now. Thanks for the tip!

1 Like

I have been pretty lucky so far, but getting good rf signals in and around my refrigerator has been something I have had a few hiccups at times. Looking at your picture, that esp’s wifi antenna is pretty ‘caged’ by this relays. You might want to consider a unit with an external antenna option for production.

Yes, I had notice this myself. I have a few spare wifi antennas in my toolbox. If I have any issues with it I have already thought I would cut the antenna traces and add an external antenna. Another possibility is to just tear this one down and rebuild it on a larger circuit board and try to mount the relays flat, rather than upright. It was originally a single relay garage door opener. :smiley:

1 Like

Update: Got my timer loop working finally, which makes it fully self contained. No external automation needed to run it. Thanks gonzotek for your suggestion.

Also got my reed switches and dht22s delivered today and have them tested and working as well.

Right now, it is running in the fridge on a battery monitoring temp and the performing relay cycles. I have not yet tied it into the timer. I just want to make sure the cold doesn’t cause oddities. One never knows until tried. :wink:

If I were to add a tiny camera to monitor the condenser coils, what are the odds that it would just fog/freeze up the lens? Given the high humidity in a fridge, I think it would need a lens defroster in order to work. What do you guys think?

EDIT: Forgot to mention the wifi is surprisingly working well.

1 Like

In reading your post, it does seem that a camera based solution might be rather fragile. So I googled ‘ice build up sensor’ and it seems that is an area that there is some amount of research going on. This paper by Texas Instruments using their capacitive sensors might give you some ideas on maybe a way to use inexpensive and fairly robust capacitive touch sensors to detect ice build up…