For me I just use the command line tools in HA to do that. The problem with restarting a Mac is that you need super user permissions (sudo) which can be problematic if trying to do it on a headless command. You can, however, have Applescript do the job for you using System Events by issuing the following command via a remote SSH:
osascript -e 'tell app "System Events" to restart'
Perhaps that will give you some better results. You will want to set up a stored SSH key on HA (ssh-keygen) so you don’t have to log into the SSH request, but otherwise it should be straight forward.