Control HA entity from ESPHome binary_sensor

What I Have:

  • ESP-32s (Original AI Thinker)
  • Sonoff Basic (Vanilla)
  • Home Assistant on Rpi 3B+
    What I wanted:
    To control the sonoff basic via physical button on ESP-32s

Current state:
WORKING!

Sonoff app is integrated to HA so now I can control all devices linked to sonoff account from HA.
EspHome integrated and setup a binary sensor…

binary_sensor:
  - platform: gpio
    pin:
      number: 27
      mode: INPUT_PULLUP
      inverted: True
    name: 'Sonoff Test'
    filters:
      - delayed_on: 10ms
    on_press:
      - homeassistant.service:
          service: homeassistant.toggle
          data:
            entity_id: switch.sonoff_100045b780

As is, this code takes the button press and translates to (kitchen light in this case) required format to tell HA entity what to do.

Yes, this is not a question but is something that I have been investigating for weeks!
This is just to give an idea to anybody else that wants to do something similar.

3 Likes

You should have asked, we could have helped you with that :slight_smile:

Thank you @tom_l.

One, I did not know what to google to start off with.
Two… I like to discover thing myself and leave the questions as a last resort.

It’s the only way to learn going forward :slight_smile:

The only thing I currently do not know is iof I have done it correctly or is there an even simpler way to do it…

1 Like