I did something similar for finding which outlet a breaker went to. I connected my MacBook to the outlet, airplay to the TV so it was loud, then had it yell if the power was disconnected:
while ! pmset -g batt | grep 'discharging'; do; echo waiting; sleep 1; done; say disconnected