A few weeks ago, I tried to do something similar to what you did. I had made a simple implementation of a power driver for maas which calls some kind of API on an esp32 (but it could be anything else). Then the esp32 can read the state of a pin or switch a relay. It seemed to work but it was just a test implementation.
As for the raspberry, if you use the uefi firmware you cannot install the operating system on the sd card but only on an external disk. I don’t know if it’s possible to avoid using uefi, I have my doubts.