How can two ESP's communicate with eachother

First at all, sorry but i couldn’t find this on ESPHome website, or this forum. Also i know this is a really nobish question. Basicly, i have two esp’s, one is light switch:

switch:
  - platform: gpio
    name: "Relay"
    pin: 0
    id: Light1

And it works, i can controll it from HA, and also i want to controll it from the other esp (i want to make a light switch with a button), and here is the code for it:

binary_sensor:
  - platform: gpio
    name: "LightSwitch"
    pin: 0
    on_click:
      min_length: 50ms
      max_length: 350ms
      then:
        - switch.toggle: Light1

What i struggle with, is the last line of the second script:

- switch.toggle: Light1

When i type this, it tells me that there is no ID like that. How do i reference the switch ID of another esp?

in esphome, you can’t. you can transmit via home assistant though.

And how can i do that?

Write a home assistant automation.

One esp would have a binary sensor on it and the other a switch.
You’d then make an automation for one to trigger the other.

You can also use MQTT, but you still need a broker so in that case it needs the same number of devices to implement as using HA automations.

IMO it’s simple to do it with home automation and binary sensor, like samnewman86 said, TBH I’m ashamend i didn’t think of that. But will explore MQTT soon, thanks!