The BATTERY() function can detect whether your Mac is currently charging or not, but it can't be used as a trigger. As far as I can tell, the only way to accomplish something like this (and it is a way I do not recommend) is to have a periodic trigger firing every second and to use an If Then Else condition to check BATTERY() for charging status and proceed accordingly. If you really want to use a macro like this, here's an example for getting started:
Trigger on Charge State.kmmacros (9.1 KB)