Control LED lights from HomeAssistant with ESPHome

I have connected a button to a NodeMCU ESP8266 and would like to use it to always switch a light (light.canvas_48e9) on/off.

I have already found codes online in the documentation, but they somehow only refer to the lights that are directly connected to the ESP.

How can I also control lights from HomeAssistant?

Many thanks in advance for your answer!

I knew I could work it out. I have put this together for you, should work. Also you’ll need to allow your ESPhome device to call home assistant services, this link will help.

Also, have a link to the homeassistant.service info

binary_sensor:
  - platform: gpio
    pin:
      number: GPIO05 # change to your GPIO
      mode: INPUT_PULLUP # change if needed
      inverted: True # or false
    name: "Button1" # change to your prefered name
    internal: false # change to true if you don't want it showing in HA
    filters:
      - delayed_on: 10ms
    on_press:
      then:
        - homeassistant.service: 
            service: homeassistant.toggle
            data:
              entity_id: light.uplight # change to your light
1 Like

Thank you very much!
It has finally worked!
:partying_face: