Lovelace Switch turns off

Hey guys I am working on a relay that will turn on a relay when the garage door is closed. I think I have it working 100% the only odd thing is that the switch for the output on the ESP32-Wroom turns off automatically.

In my ESPHome code I don’t have an auto-reset template. Its very strange. I am wondering if I need to restart my system after removing settings for RESTORE_DEFAULT_ON

Without any configuration code we would only be guessing.

The lovelace buttons are defined as such:

type: entities
entities:
  - entity: sensor.garage_esp32_wifi_signal_sensor
  - entity: switch.esp_left_garage_door
  - entity: switch.esp_middle_garage_door
  - entity: switch.esp_right_garage_door
  - entity: switch.led_left_garage
  - entity: switch.led_middle_garage
  - entity: switch.led_right_garage
  - entity: binary_sensor.esp_left_garage_sensor
  - entity: binary_sensor.esp_middle_garage_sensor
  - entity: binary_sensor.esp_right_garage_sensor
  - entity: binary_sensor.esp_back_garage_sensor
title: Garage ESP32

The issues are within these:

  - entity: switch.led_left_garage
  - entity: switch.led_middle_garage
  - entity: switch.led_right_garage

ESPhome settings:

- platform: gpio
    id: "pin25"
    pin: GPIO25
  - platform: gpio
    id: "pin26"
    pin: GPIO26
  - platform: gpio
    id: "pin27"
    pin: GPIO27

 - platform: template
    name: "LED Left Garage"
    turn_on_action:
      - switch.turn_on: pin25
    turn_off_action:
      - switch.turn_off: pin25
  - platform: template
    icon: "mdi:arrow-up-down-bold-outline"
    name: "LED Middle Garage"
    turn_on_action:
      - switch.turn_on: pin26
    turn_off_action:
      - switch.turn_off: pin26
  - platform: template
    icon: "mdi:arrow-up-down-bold-outline"
    name: "LED Right Garage"
    turn_on_action:
      - switch.turn_on: pin27
    turn_off_action:
      - switch.turn_off: pin27

That is not sufficient. I can’t even see if those platforms are for switches or binary sensors.

Forgive my ignorance I am new to this.

switch:

and on an ESP32 WROVER

Ok, for the template switches you need to define a lambda function to determine the state of the switch. See https://esphome.io/components/switch/template.html#configuration-variables
Otherwise ESPHome does not know what state your switch is in.

Can you explain why you are not using the GIPO switches directly in home assistant, and are using templates to control them?

Or even better, why not use this?

Again I am all new to this and without some examples I am not sure what is proper. I didn’t mean to go on this tangent but I am trying to turn a relay on and off thats basically it. For this particular case I was testing my outputs really but there are other GPIO’s I will use to operate the relay to open and close the garage door. Let me know if that makes sense? If there was an example ESP Home example and or the lovelace front end I could see it might make better sense?

Thanks a bunch!

If you give these names:

switch:
  - platform: gpio
    pin: GPIO25
    name: "LED Left Garage"
    icon: "mdi:arrow-up-down-bold-outline"
  - platform: gpio
    pin: GPIO26
    name: "LED Middle Garage"
    icon: "mdi:arrow-up-down-bold-outline"
  - platform: gpio
    pin: GPIO27
    name: "LED Right Garage"
    icon: "mdi:arrow-up-down-bold-outline"

They will appear as switches in Home Assistant (add them to an entities card) and you don’t need the template switches.

I wish I understood that, but forgive me, I don’t know what you are saying above?

This is how I am testing. The full card is here:

entities:
  - entity: sensor.garage_esp32_wifi_signal_sensor
  - entity: switch.esp_left_garage_door
  - entity: switch.esp_middle_garage_door
  - entity: switch.esp_right_garage_door
  - entity: switch.led_left_garage
  - entity: switch.led_middle_garage
  - entity: switch.led_right_garage
  - entity: binary_sensor.esp_left_garage_sensor
  - entity: binary_sensor.esp_middle_garage_sensor
  - entity: binary_sensor.esp_right_garage_sensor
  - entity: binary_sensor.esp_back_garage_sensor
title: Garage ESP32

I’m saying you don’t need the template switches in ESPHome. Just use the GPIO switches.

Where did the binary sensors come from?

You have not shown an esp config for them.

This is (almost) everything:

binary_sensor:
  - platform: gpio
    name: "ESP Left Garage Sensor"
    pin:
      number: GPIO16
      mode: INPUT_PULLDOWN
  - platform: gpio
    name: "ESP Middle Garage Sensor"
    pin: 
      number: GPIO17
      mode: INPUT_PULLDOWN
  - platform: gpio
    name: "ESP Right Garage Sensor"
    pin: 
      number: GPIO18
      mode: INPUT_PULLDOWN
  - platform: gpio
    name: "ESP Back Garage Sensor"
    pin: 
      number: GPIO32
      mode: INPUT_PULLDOWN
switch:
  - platform: gpio
    id: "pin19"
    pin: GPIO19
  - platform: gpio
    id: "pin21"
    pin: GPIO21
  - platform: gpio
    id: "pin22"
    pin: GPIO22
  - platform: gpio
    id: "pin23"
    pin: GPIO23
  - platform: gpio
    id: "pin25"
    pin: GPIO25
  - platform: gpio
    id: "pin26"
    pin: GPIO26
  - platform: gpio
    id: "pin27"
    pin: GPIO27
  - platform: template
    name: "LED Left Garage"
    turn_on_action:
      - switch.turn_on: pin25
    turn_off_action:
      - switch.turn_off: pin25
  - platform: template
    icon: "mdi:arrow-up-down-bold-outline"
    name: "LED Middle Garage"
    turn_on_action:
      - switch.turn_on: pin26
    turn_off_action:
      - switch.turn_off: pin26
  - platform: template
    icon: "mdi:arrow-up-down-bold-outline"
    name: "LED Right Garage"
    turn_on_action:
      - switch.turn_on: pin27
    turn_off_action:
      - switch.turn_off: pin27
  - platform: template
    icon: "mdi:arrow-up-down-bold-outline"
    name: "esp Left Garage Door"
    restore_state: yes
    turn_on_action:
      - switch.turn_on: pin19
      - delay: 500ms
      - switch.turn_off: pin19 
  - platform: template
    icon: "mdi:arrow-up-down-bold-outline"
    name: "esp Middle Garage Door"
    restore_state: yes
    turn_on_action:
      - switch.turn_on: pin21
      - delay: 500ms
      - switch.turn_off: pin21  
  - platform: template
    icon: "mdi:arrow-up-down-bold-outline"
    name: "esp Right Garage Door"
    restore_state: yes
    turn_on_action:
      - switch.turn_on: pin22
      - delay: 500ms
      - switch.turn_off: pin22  
  - platform: template
    icon: "mdi:arrow-up-down-bold-outline"
    name: "esp Back Garage Door"
    restore_state: yes
    turn_on_action:
      - switch.turn_on: pin23
      - delay: 500ms
      - switch.turn_off: pin23  
sensor:
  - platform: wifi_signal
    name: "Garage ESP32 WiFi Signal Sensor"
    update_interval: 60s

That is not what you posted originally when I asked for your esphome configuration. I can’t help you if you keep wasting my time like this.

You want to define three template covers in home assistant that pull your binary sensors and switches together into three garage door components.

I didn’t change it. I don’t know why you’re so adversarial. Im just looking for help and didn’t want to dump the entire thing.

I appreciate your time and help. Just looking to make this work. I will figure it out.