Control HA switch from ESPHome

Is it possible to directly toggle (or turn on or off) a switch in HA front end from ESPHome without using an intermediate step?

If so, how do I do this?

I’m stumped and probably missing the obvious.

You can call HA services using the API see: Native API Component — ESPHome
I think this is what you are asking for, you will need a trigger for it.

1 Like

Thank you.

So, it would be something like:

  - homeassistant.service:
      service: switch.turn_on
      entity_id: switch.myswitch

Is that how it should work?

This works!

Apart from an error in my config. Here’s the correct version:

 - homeassistant.service:
      service: switch.turn_on
      data:
        entity_id: switch.myswitch

Yes, the service calls are looking for data, or data_template, glad it worked.