I use ESPHome on many of my switches (Sonoff mostly), they are driven by Home Assistant.
OTOH I have one NodeMCU that provides a simple service:
it exposes a HTTP endpoint
upon receiving a call it
sets a GPIO pin
waits two seconds
unsets the pin
This is coded in “arduino C” and the NodeMCU is flashed with the code. It works fine.
I would like to move this service to ESPHome for a variety of reasons:
simpler integration with HA
homogeneity in my IoT mess
what not
First question: is it possible in the first place?
If so: what would be the typical approach to configure this?
via HA where an automation would send an MQTT (or native API) message which will be understood by ESPHome to “set the pin”, wait in the automation 2s and then send another message to ESPHome that would be understood as “unset the pin”
or would the whole service be contained in the ESPHome code (set, wait, unset) - a code that would be launched upon receiving a MQTT/API trigger? (← I would prefer this, I think)
What confuses me a bit with ESPHome is the actions on the pins, I think that it will be much easier to let HA do the heavy lifting (via the example we both pointed to).
ESPHome will activate the GPIO pin 25 with ID ‘relay’ defined as a switch,
ESPHome will de-actovite the internal switch with id ‘relay’ after 500 ms (and thus switch the pin 25)
ESPHome will update the status of the switch.gate_remote on HA