ESPhome to ESPhome?

Is it possible for one ESPhome device to send commands to another ESPhome device, rather than using HA as an intermediary?

Only if you use another intermediary like an mqtt broker.

Try ESP-NOW. No intermediary required. Peer to peer

https://www.espressif.com/en/products/software/esp-now/overview

There is also the ability to use the web api.

As nickrout said, you could use the Web Server API

But in my experience, I have found using the web server API to be unreliable. Maybe it’s because I’m using cheap ESP8266/ESP32 development boards, but I have found that some boards are unable to send and/or receive POST requests. You might have better luck if you use high quality boards.

But speaking of ESPHome to ESPHome direct communication, I ended up using the homeassistant platform on ESPHome rather than using ESPHome’s Web API. Maybe due to poor Wi-Fi connection in my house, I found that the latency of using Web APIs to be annoyingly big. So I use the homeassistant platform to get the state of the sensor directly from HA, and then set the automations on ESPHome rather than setting up an automation on HA. Using the homeassistant platform, the trigger latency is way more acceptable. I know it still relies on HA, but I found the reliance on HA to be worth the trade off for better latency.

You could try BLE for that - wifwucite/esphome-ble-controller allows defining commands that can be executed when when a certain value is written to a characteristic. That being said, I’m only aware of BLE Client Binary Output — ESPHome which only supports binary values, I wonder if there are text outputs available (or maybe you can contribute one).

Alternatively, I recently contributed a change to ESPHome (available since last release) that allows you to embed custom data into BLE advertisements, and there is already a built-in way to consume such advertisements in ESPHome. This way, to trigger an automation, you can broadcast a specific value in advertisement, and have the other node to listen for the trigger. It’s tricky to tell though if command was executed though [and only once], as advertisements are connection-less and you don’t know if it was received. Here is an example esphome-docs/esp32_ble.rst at 42fe5663127f9233d157eb300d9d30af030e71e8 · ashald/esphome-docs · GitHub

The good part of BLE is that it’s already available in ESPHome (compared to ESP now), and doesn’t require Wi-Fi as the API-based solutions. The bad part is that BLE has limited range.