Assistance with ESP YAML

Hi all,
I am attempting to update my ESP, used for opening/closing my garage door, but am receiving the following error:

INFO Reading configuration /config/esphome/garage-door.yaml…
ERROR Error while reading config: Invalid YAML syntax:

Duplicate key “name”
in “/config/esphome/garage-door.yaml”, line 86, column 5:
name: “Garage door closed”
^
NOTE: Previous declaration here:
in “/config/esphome/garage-door.yaml”, line 82, column 5:
name: “Garage door open”
^

I am assuming it is a formatting error but this code worked without problem previously:

binary_sensor:
  - platform: status
    name: "Garage Door ESP Status"
    
  - platform: template
    name: "Garage door open"
    value_template: >-
      {{ is_state('switch.garage_door_open', 'on') }}
  
    name: "Garage door closed"
    value_template: >-
      {{ is_state('switch.garage_door_close', 'on') }}    

Could anyone point me to what’s going wrong (I have attempted reformatting without success)

Thanks

You have to add another - platform: template line for the second template sensor:

binary_sensor:
  - platform: status
    name: "Garage Door ESP Status"
    
  - platform: template
    name: "Garage door open"
    value_template: >-
      {{ is_state('switch.garage_door_open', 'on') }}

  - platform: template
    name: "Garage door closed"
    value_template: >-
      {{ is_state('switch.garage_door_close', 'on') }}    

Thanks, I am now getting the following error:

INFO Reading configuration /config/esphome/garage-door.yaml…
INFO Detected timezone ‘Europe/London’
Failed config

binary_sensor.template: [source /config/esphome/garage-door.yaml:81]
platform: template
name: Garage door open

[value_template] is an invalid option for [binary_sensor.template]. Please check the indentation.
value_template: {{ is_state(‘switch.garage_door_open’, ‘on’) }}
binary_sensor.template: [source /config/esphome/garage-door.yaml:86]
platform: template
name: Garage door closed

[value_template] is an invalid option for [binary_sensor.template]. Please check the indentation.
value_template: {{ is_state(‘switch.garage_door_close’, ‘on’) }}

That yaml is for HA, you need to use lambda in epshome:

1 Like

Is the Lambda just used to turn analogue value into a binary sensor?
This doesn’t seem to work either.

Sorry, I wasn’t paying attention to the actual sensor configuration, but only the syntax.

Looking back at your original configuration: You appear to have 2 switches defined - are these switches defined on the ESP device? If so, the proper way would be to give each switch an ID, and then use those IDs in the template sensors’ lambdas.

So, for example, if you give one switch the ID garage_door_open, then the lambda would look something like:

  - platform: template
    name: "Garage door open"
    lambda: 'return id(garage_door_open).state;'

Hi,
Yes the switches are defined within the ESP config, I am attempting to update within ESP home but my config is now showing the errors above (although it did previously work).

esphome:
  name: garage-door
  platform: ESP8266
  board: esp01_1m

wifi:
  ssid: "****"
  password: !secret wifi_password
  manual_ip:
    static_ip: '192.168.1.98'
    gateway: '192.168.1.1'
    subnet: '255.255.255.0'
  # Enable fallback hotspot (captive portal) in case wifi connection fails
  ap:
    ssid: "Garage-Door Fallback Hotspot"
    password: "****"

captive_portal:
logger:
  baud_rate: 0
api:
ota:

time:

  - platform: homeassistant

    id: homeassistant_time
    
# Text sensors with general information.

text_sensor:

  # Expose ESPHome version as sensor.

  - platform: version

    name: Relay ESPHome Version

  # Expose WiFi information as sensors.

  - platform: wifi_info

    ip_address:

      name: Relay IP

    bssid:

      name: Relay BSSID
      
# Sensors with general information.

sensor:

  # Uptime sensor.

  - platform: uptime

    name: Relay Uptime

 

  # WiFi Signal sensor.

  - platform: wifi_signal

    name: Relay WiFi Signal

    update_interval: 60s      

uart:
  baud_rate: 115200 # speed to STC15L101EW
  tx_pin: GPIO1
  rx_pin: GPIO3

binary_sensor:
  - platform: status
    name: "Garage Door ESP Status"
    
//  - platform: template
//    name: "Garage door open"
//    value_template: >-
//      {{ is_state('switch.garage_door_open', 'on') }}
  
//  - platform: template
//    name: "Garage door closed"
//   value_template: >-
//      {{ is_state('switch.garage_door_open', 'on') }}
      
      
  lambda: |-
      {{ is_state('switch.garage_door_open', 'on') }} {
        // Garage Door is open.
        return true;
      } else {
        // Garage Door is closed.
        return false;
      }    
      
  lambda: |-
      {{ is_state('switch.garage_door_closed', 'on') }} {
        // Garage Door is closed.
        return true;
      } else {
        // Garage Door is open.
        return false;
      }        

switch:
  - platform: template
    id: relay1
    turn_on_action:
      - uart.write: [0xA0, 0x01, 0x01, 0xA2]
    turn_off_action:
      - uart.write: [0xA0, 0x01, 0x00, 0xA1]
    internal: yes

  - platform: template
    id: relay2
    turn_on_action:
      - uart.write: [0xA0, 0x02, 0x01, 0xA3]
    turn_off_action:
      - uart.write: [0xA0, 0x02, 0x00, 0xA2]
    internal: yes

  - platform: template
    name: "Garage Door Open"
    id: garage_door_open
    turn_on_action:
    - switch.turn_on: relay1
    - delay: 500ms
    - switch.turn_off: relay1
    - delay: 500ms
    - switch.turn_off: garage_door_open
    optimistic: true

  - platform: template
    name: "Garage Door Close"
    id: garage_door_close
    turn_on_action:
    - switch.turn_on: relay2
    - delay: 500ms
    - switch.turn_off: relay2
    - delay: 500ms
    - switch.turn_off: garage_door_close
    optimistic: true

This is my full config

Well, those lambda statements underneath binary_sensor won’t work. But you should now be able to insert my previously suggested template binary sensor and that should work just fine.

And because the switches are actually template switches you could also toggle the template binary sensor from within the switches with the binary_sensor.template.publish action.

Appreciate the help, got it working by using your suggested template.

1 Like