Template Sensor for Fridge Doors on device with esphomeyaml

I have placed sensors on each of of fridge doors. Its has split doors for the refrigerator and a pull out freezer drawer. There is a WS2812 attached to as well. The way I have it setup right now will turn the light on if any door is open and will turn it off when a door is closed. The problem I’m having is that if both fridge doors get opened but only one is shut the light still goes off.

I’d like to create an internal sensor that is “open” if any number of doors is open so that the light will be on if a door is open. I can’t wrap my head around a template sensor, but I think that is what I need.

Post your door sensor names and I’ll give it a go.

EDIT: Actually the easiest way to approach this would be to add your door sensors to a group. If either door is open (on) the group will be on. Trigger your light from the group state.

I’d like to do this on device with esphomeyaml. Sorry, I completely left that out.

I should have guessed that from the post category.

Post the config you have now and I’ll have a go.

Here it is:

esphomeyaml:
  name: fridge
  platform: ESP8266
  board: d1_mini

wifi:

api:

# Enable logging
logger:

web_server:

ota:

binary_sensor:
  - platform: gpio
    pin:
      number: D1
      mode: input_pullup
    name: "Fridge Door | Left"
    id: "fridge_door_left"
    device_class: door
    on_press:
      then:
        - light.turn_on:
          - id: fridge_light
          - red: 100%
    on_release:
      then:
        - light.turn_off: fridge_light
  - platform: gpio
    pin:
      number: D2
      mode: input_pullup
    name: "Fridge Door | Right"
    id: "fridge_door_right"
    device_class: door
  - platform: gpio
    pin:
      number: D6
      mode: input_pullup
    name: "Freezer Door"
    id: "freezer_door"
    device_class: door
  - platform: status
    name: "Fridge Sensor Status"

switch:
  - platform: restart
    name: "Fridge Sensor Restart"

sensor:
  - platform: uptime
    name: "Fridge Uptime Sensor"

light:
  - platform: fastled_clockless
    chipset: ws2812
    pin: D8
    num_leds: 7
    rgb_order: grb
    name: "Fridge Notification Light"
    id: "fridge_light"

Does this look right?

- platform: template
    name: "Fridge Door Status"
    lamda: |-
      if (id(fridge_door_left).state == 'ON' || id(fridge_door_right).state == 'ON' || id(freezer_door).state == 'ON') {
        return true;
      } else {
        return false;
      }

I had some time to work on it tonight. This is working for me:

- platform: template
    name: "Fridge Door Status"
    lamda: |-
      if (id(fridge_door_left).state == true || id(fridge_door_right).state == true || id(freezer_door).state == true) {
        return true;
      } else {
        return false;
      }

This looks right to me although you probably don’t even need the == true. The documentation about template binary sensors has one more check in case of unknown state of the conditions. You may want to consider how to handle that case.

I’d love to know however this is set up on the hardware side, are these magnetic reed switches?

I have cat6 wire with the ends stripped and taped down in the fridge side with copper tape on the seal to make the connection between the two wires.

This is the youtube video that inspired me:

https://www.google.com/url?sa=t&rct=j&q=&esrc=s&source=web&cd=2&cad=rja&uact=8&ved=2ahUKEwjw3YPgms3gAhWZIDQIHdMjCAwQwqsBMAF6BAgFEAQ&url=https%3A%2F%2Fwww.youtube.com%2Fwatch%3Fv%3D2vAYAbtQfjs&usg=AOvVaw2riEUEsyN6A-6VNUAiKxVY

I need to order more Dallas temperature sensors, but they’ll be added soon as well.

2 Likes

Great solution. Thanks for sharing.