The Verge has a helpful article on how to configure your Mac to automatically start up or shut down on a schedule.
Remember that Keyboard Maestro will not be able to operate until you log in, and most UI actions will not work if the screen is sleeping, saving or locked.
Thanks. I've used the "pmset command" once before to fix a problem. My problem was that my Intel Mac was randomly giving me a blank screen and crashing, daily or hourly! I think it was a RAM fault. The crash was so instantaneous that nothing was being written to my system log files during the crash. But by using the pmset command, I was able to get my Mac to reboot one minute after every crash, allowing my regular KM macros to begin working again. You see, I wrote a KM macro that was triggered every minute, and what it did was use the "pmset" command to ask for a reboot "two minutes from now."
I realize that macOS has a feature to reboot after a power failure, but the way my Mac was crashing wasn't equivalent to a power failure. So it wasn't rebooting without the help of my KM macro.
So in effect, my KM macro was directly causing my Mac to reboot every minute if it had crashed, even though KM macros cannot run when a Mac has crashed. I was quite happy with this solution, but soon after I replaced my Mac.
If you have a machine that can't sleep—in my case, because the macro it runs can be called randomly at any time of the day or night—a good alternative is to take advantage of the Sleep Display and Wake Display actions.
I have the macro running on an old laptop, and I set it to Low Power Mode in the Battery Systems Settings panel. I also set the display to minimum brightness, and I have a hot corner to sleep the display, in case I work on the Mac manually. The macro, though, does all the rest.
When triggered, the macro wakes the display, checks the color of a pixel at the location of the Apple menu bar Apple logo to make sure the display is awake (not sure this is necessary, but it felt like a good safety), and then does its stuff, taking advantage of all the UI actions I can use when the display is on. The last step sleeps the display, and the Mac goes blank again.
This works really well—every so often, I can see the display wake up, a bunch of stuff happen onscreen for a few seconds, then it goes dark.