This seems to be very popular with the release of iOS14, & I’m writing this up as a personal reference so I don’t have to continue to watch the great setup video that u/zeeshan_02 posted on Reddit: Beginner’s Guide on Playing a Custom Sound when Connected to Charger!
Shortcut 01: Encode Audio
This converts a sound file (in my case I was using an MP3) to Base64, for later use by the next shortcut:
Shortcut 02: Charger Connected
Sound that will be played when the charger is connected. The base64-encoded text should already be in the clipboard from the step above. You just have to paste that into the Text field:
Shortcut 03: Charger Disconnected (Optional)
Can use the same sound for connect & disconnect if you want. I just wanted to have different sounds used. It’s the same setup as above, just using a different Base64 string. If you want the same sound for both actions, you can skip this.
Setup a new Personal Automation for when your device is connected or disconnected from power, or both, & run the appropriate shortcut for what you’re trying to do.