Learning esphome.yaml

I am learning by doing. Unless there is good reading material or youtube video that explains all compoments that controls device, think learning by doing is the way to go.

I am playing with Sonoff device with ESPHome flashed and integrated to HA. By taking parts of code from various internet sources I put together source, but still not sure about some parts of it. Not sure why and how it works…

Hope someone can shed some light over yaml file comands to understant what controls what…

This example adds switch for ESP1. Adds 2 switches: separate switch for Device “ESP1 relay” as well as for the whole Area where ESP1 is located

switch:
  - platform: gpio
    pin: GPIO12
    id: relay
  - platform: template
    name: "ESP1 relay"
    optimistic: true
    id: relayandled
    turn_on_action:
    - switch.turn_on: relay
    - light.turn_on: led
    turn_off_action:
    - switch.turn_off: relay
    - light.turn_off: led

I would be ok to have jus tone switch linked to device, not Area switch

Next question is about another set of code to add switch to HA Overview window:

output:
  - platform: esp8266_pwm
    id: sonoff_green_led
    pin:
      number: GPIO13
      inverted: True

light:
  - platform: monochromatic
    name: "ESP1 Green LED"
    output: sonoff_green_led
    id: led

Adding this to yaml file creates switch, but I am not sure why do I use two 'definitions" in yaml file: output and light

OK, I am not 100% sure if I understand you correct. But let me explain. The first switch is the actual gpio itself. As it doesn’t have a name it will not show up in Home Assistant. If you are seeing two switches in HA that may be a feature of the UI element you are using.

The scond switch is a template switch that combindes the other switch and the LED. So that the LED is on when the relay is on.

output is the physical device that does the switching (in this case a GPIO pin) and light is the logical object based on the ouput. The light is represented in Home Assistant. You could use the same ouput for another type of device. For example a fan. Then it will show/work as a fan in HA.

This is a picture of what I see in HA Overview. Too many labels with useless labels. Basically I would only want to see one line: ESP1 relay with a switch, so that I could turn it on or off. I suspect those are coming from another Sonoff device with ESPHome, but I thought I should see what is defined in yaml file. Every Sonoff device has separate yaml file…

And then that Area switch to the right of Area name “Greenhouse” is also not needed.

Funny, i just changed my green status led to act reverse to relay (that was how it was with Tasmota, which i dropped a couple of days ago)
I was eager to have the led act as ‘glow in the dark’ again, so the button is easy to find in the dark; the status function i find very useless🤔

Anyway, not sure if it’s of any use, but here is my yaml.
What i did was:

  • drop status_led and control gpio13 with output (so it doesn’t show up in HA)
  • use output.turn_on/off from within the light to copy the relay. N.B. It seems the led is inverted, so on is off and off is on. I could have used invert, but i didn’t :wink:

Still added sensors for wifi strength and uptime :yum:

esphome:
  name: sonoff_switch_ip51
  platform: ESP8266
  board: esp01_1m

wifi:
  ssid: !secret wifi_ssid1
  password: !secret wifi_password

  # Enable fallback hotspot (captive portal) in case wifi connection fails
  ap:
    ssid: "sonoff_switch_ip51 Fallback"
    password: "fallback"

captive_portal:

# Enable Home Assistant API
api:
  password: !secret api_password

ota:

# Enable logging
logger:
  baud_rate: 0

binary_sensor:
  - platform: gpio
    pin:
      number: GPIO00
      mode: INPUT_PULLUP
      inverted: True
    id: button_1
    on_press:
      then:
        - light.toggle: light_1

sensor:
  - platform: wifi_signal
    name: "WiFi Signal Sensor"
    update_interval: 60s
  - platform: uptime
    name: "Uptime"

light:
  - platform: binary
    name: "My Light"
    id: light_1
    output: relay_1
    on_turn_on:
      then:
      - output.turn_on: led_1
    on_turn_off:
      then:
      - output.turn_off: led_1

output:
  - platform: gpio
    pin: GPIO12
    id: relay_1
  - platform: gpio
    pin: GPIO13
    id: led_1


Cheers!!

The screenshot you are showing has nearly nothing to do with your ESPHome yaml.

It is just your UI configuration. There should be a menu button in the top right corner that will allow you to configure your HA UI. The “area switch” is generated from HA and when you edit the entity card using the edit UI there is a option to disable it.

And also to remove all other entities you do not want to see in HA.