ESPHOME show switch state

I have the following code for my Sprinkler project and would like to see the states of the switch in HA. Everything works, I can see the sensors and I can switch relay on and off but would like to actually see the state of relay in HA.

sensor:
  - platform: wifi_signal
    name: "Sprinkler Wifi"
    update_interval: 60s
binary_sensor:
  - platform: status
    name: "Sprinkler Status"
  - platform: gpio
    pin:
      number: D3
      mode: INPUT_PULLUP
      inverted: True
    name: "Outdoor Rain Sensor"
    filters:
      - delayed_off: 10ms

switch:
  - platform: gpio
    pin:
      number: D6
      mode: OUTPUT
    id: relay
  - platform: template
    name: "Rainy Weather"
    turn_on_action:
    - switch.turn_on: relay
  - platform: template  
    name: "Dry Weather"
    turn_on_action:
    - switch.turn_off: relay

Give the relay/switch a name not just an id and it should show up.

2 Likes

Thanks. That was what I was missing.

1 Like