I should note that when I received the iMac back, I installed High Sierra to an external SSD and made this my boot disk. Apple suggested that if the power issue happens again, I should reinstall OS X.
Well, I just started experiencing the shut down issue again. All seemed fine for a week, but the issue came back yesterday morning when I found my iMac powered off. Only way to power it back on was to unplug, wait 10 seconds then plug back in. When I got home from work yesterday, the iMac was again powered off. Again, I unplugged and replugged. This time, the iMac would boot, then in about 10-15 seconds, would completely shut down. I ran hardware tests (holding down D on boot up) which found nothing. Curiously, the iMac did not power down during these tests, which lasted about 5 minutes.
I tried moving my iMac to different wall outlets in different rooms. My iMac powered off at each location so I can rule out the wall outlet. I tried booting from a different OS and different HDD, so I believe I can rule out the OS as the issue as apple believes this is a sleep problem. If it were I should still be able to power cycle the Mac with the power button. Which does not work.
I have another appointment this Friday to lug my iMac back to the apple store where I hope they can fix it for good this time. I recorded one of the shutdowns so I can at least show the genius that I am not crazy, and this is indeed happening.