Send ssh commands with or without HA instance running?

Hi to all!!

I have a question about if is possible to use a esphome node to send ssh commands by itself.

I want to automate a shutdown of my non-essential servers in case of power leakage, while send a wol to power on a rpi-like device (a beaglebone black i have unused in a drawer, i will refer to it as rpi in short terms for now) with a basic instance of HA running on Debian to keep some critical services online (home security and sensors).

My “critical” esphome nodes have installed a backup battery and the main UPS supports all network stuff -aps, firewall, gpon, switch… and 3 HP Desktop mini pcs used as Ubuntu servers. One is the “main” (HA, Frigate, AI…) other runs media server, ebook library, file storage…and last one as sandbox homelab and testing enviroment… all instances in each server runs in docker, all managed and unified with portainer.

In case of leakage, rpi with comms online and a basic HA instance with some sensors must be the contingency plan, but this only makes sense if UPS range can be increased to maximum time…

The wanted scenerio must be like this:

  • Power leakage → the modbus power meter connected to a esphome node with backup battery becomes “unavaliable” up to 2 min.
  • this is assumed like a possible “long time leakage” and the esp node sends, first wol magic packet to power on the rpi, and, after a little delay, send ssh commands to shutdown the servers.
  • ideal, if is possible too, do the some thing, but “inverted” on power comes back again…as like, wake up the servers, and power downs the rpi…

I know already about this:

  • pairing ssh keys for each device is mandatory to run shutdown remote ssh commands, and needs to be “stored” in a esp node. I thing this can be done easy due to minimal size of key files, or maybe integrated directly on yaml. For home use devices into a isolated vlan, i can assume this risk.
  • yes, i can use mqtt to send action to HA instance on rpi device (with ssh keys pairing done) and rpi reflects bash commands to servers after, but i want to know if espnode can run this automation by itself, without broker or any HA instance running (really is only a basic if-else action with simple sensor trigger and a pair of conditions), to keep It working even if main HA suddenly becomes unavaliable, still able to shutdown the servers and wake up the rpi although.

Can be this done with a “decent” esp32 device (psram or with sd reader attached to store keys) running esphome? Tasmota/espeasy can be a pretty option to evaluate too…

Someone has been integrated some like this yet?

Thanks in advance and merry xmas!!