Making Your Refrigerator SMART

I have an old refrigerator in my garage which I suspected was a power hog.  I bought a Sonoff S31 Power Monitoring outlet and flashed it with custom firmware (Tasmota) and blogged about that here.

I’ve since figured out you can do a WHOLE LOT MORE with a Tasmota flashed Sonoff S31. I figure there are two important things you’d want to know about an old refrigerator.

  1. Is it running?
  2. Has the door been left open?

Both answers can be tackled with home automation.  I use the EXCELLENT program HomeAssistant.  So let’s get to it, shall we?

Here’s what my set up looks like.  Note that on the first picture the running amps are about 1.4 and the watts are around 177.  That will factor in later.  The second screen shot shows my refrigerator at an Idle state.

Refrigerator States – Click To Enlarge

Now let’s talk about how we got there.  First of course I added the Sonoff S31 Outlet as a switch.

    name: 'Sonoff S31 Garage'
    state_topic: 'stat/sonoffs31/POWER'
    command_topic: 'cmnd/sonoffs31/POWER'
    availability_topic: 'tele/sonoffs31/LWT'
    payload_on: 'ON'
    payload_off: 'OFF'
    payload_available: 'Online'
    payload_not_available: 'Offline'
    qos: 0

I should state for the record that I changed the MQTT topic name to “sonoffs31”.  You can name it anything you want but I forget what the default Tasmota name is.

Now we can create some input select devices.  Those are the drop down boxes where the state of the refrigerator is displayed such as “Running” or “Idle” and “Open” or “Closed”.

input_select:
  refrigerator_status:
    name: Garage Refrigerator Status
    options:
      - Idle
      - Running
  refrigerator_door_open:
    name: Refrigerator Door Open
    options:
      - Open
      - Closed

This creates TWO different boxes and as you can see the conditions are that the refrigerator is Running and the door is Closed.  Once again take note of the running amps and watts (1.46 and 177, respectively).

Now lets set up some sensors in HomeAssistant, shall we?

  - platform: mqtt
    name: "Garage Refrigerator Outlet Sensor"
    state_topic: "tele/sonoffs31/SENSOR"
    value_template: "{{ value_json['ENERGY'].Voltage }}"
    unit_of_measurement: "V"
  - platform: mqtt
    name: "Garage Refrigerator kWh"
    state_topic: "tele/sonoffs31/SENSOR"
    value_template: "{{ value_json['ENERGY'].Today }}"
    unit_of_measurement: "kWh"
  - platform: mqtt
    name: "Garage kWh Yesterday"
    state_topic: "tele/sonoffs31/SENSOR"
    value_template: "{{ value_json['ENERGY'].Yesterday }}"
    unit_of_measurement: "kWh"
  - platform: mqtt
    name: "Garage Refrigerator Amps"
    state_topic: "tele/sonoffs31/SENSOR"
    value_template: "{{ value_json['ENERGY'].Current | round(2) }}"
    unit_of_measurement: "A"
  - platform: mqtt
    name: "Garage Refrigerator Total kWh"
    state_topic: "tele/sonoffs31/SENSOR"
    value_template: "{{ value_json['ENERGY'].Total }}"
    unit_of_measurement: "kWh"
  - platform: mqtt
    name: "Garage Refrigerator Watts"
    state_topic: "tele/sonoffs31/SENSOR"
    value_template: "{{ value_json['ENERGY'].Power }}"
    unit_of_measurement: "W"

Now let’s set up the automations. This one is for “Running” and “Idle”.  Note that I have set the condition that anything above 1 amp is running and anything below 1 amp is idle.  Just opening the door and turning the light on is about 0.4 amps so I had to make sure there were no false triggers.  So basically to trip this function I have to have it above 0.4 amps but not higher than 1.4 amps.  I just selected 1 as it fits comfortably between those two conditions.

automation 28:
  alias: Set refrigerator running
  trigger:
    - platform: numeric_state
      entity_id: sensor.garage_refrigerator_amps
      above: 1
  condition:
    condition: or
    conditions:
      - condition: state
        entity_id: input_select.refrigerator_status
        state: Idle
      - condition: state
        entity_id: input_select.refrigerator_status
        state: Running
  action:
    - service: input_select.select_option
      data:
        entity_id: input_select.refrigerator_status
        option: Running
automation 29:
  alias: Set refrigerator idle
  trigger:
    - platform: numeric_state
      entity_id: sensor.garage_refrigerator_amps
      below: 1
  condition:
    condition: and
    conditions:
      - condition: state
        entity_id: input_select.refrigerator_status
        state: Running
  action:
    - service: input_select.select_option
      data:
        entity_id: input_select.refrigerator_status
        option: Idle

And this automation is for “Open” and “Closed”. The running watts of my refrigerator are almost always between 160 and 180.  So when the refrigerator is running AND the light bulb is on that means I’m generally in the 220 watt range or so.  I may find myself having to fiddle with these numbers some as time goes on.   So far it is working great and I left the fridge door open through several cycles yesterday and it worked perfectly.

automation 30:
  alias: Refrigerator Door Open
  trigger:
    - platform: numeric_state
      entity_id: sensor.garage_refrigerator_watts
      above: 210
      below: 250
      for: 
        seconds: 45
  condition:
    condition: or
    conditions:
      - condition: state
        entity_id: input_select.refrigerator_door_open
        state: Open
      - condition: state
        entity_id: input_select.refrigerator_door_open
        state: Closed
  action:
    - service: input_select.select_option
      data:
        entity_id: input_select.refrigerator_door_open
        option: Open
    - service: notify.clicksend
      data_template:
        title: "Garage Refrigerator Door Open"
        message: >-
          The Garage Refrigerator Door Is Open
automation 31:
  alias: Set refrigerator door closed
  trigger:
    - platform: numeric_state
      entity_id: sensor.garage_refrigerator_watts
      below: 190
  condition:
    condition: and
    conditions:
      - condition: state
        entity_id: input_select.refrigerator_door_open
        state: Open
  action:
    - service: input_select.select_option
      data:
        entity_id: input_select.refrigerator_door_open
        option: Closed

Phew!  You may notice the 2nd action above is to send me a text if the refrigerator door is open for more than 45 seconds.  In reality that time is longer as if you open the door and the refrigerator is NOT running it will take some time for the cool to escape and the fridge kick on and then of course the 45 second count.  Here’s the text Clicksend sent.  (You of course need a Clicksend or PushBullet or whatever notification service you use account).

It could take 5 minutes or more to get a text but let me say this.  THAT IS BETTER THAN LEAVING IT OPEN ALL NIGHT!

I’ll probably now study the compressor cycle and have it send me a text if it doesn’t see that 1 amp spike for say 6 hours or so.  Even in a power outage leaving your door closed for 6 hours shouldn’t have a detrimental effect on the food.

Geeky Friderators. Heck yeah

Leave a Reply

Your email address will not be published.