You can do it easily through plasma desktop scripts, like this:
auto-hide on:
var panel = panelById(panelIds[0]) panel.hiding = 'autohide';
auto-hide off:
var panel = panelById(panelIds[0]) panel.hiding = 'none';
The bad news is there is no way to programatically run the script when you want it except perhaps for some kind of keyboard+mouse automation.
The closest you can get (per this discussion on KDE forum) is open the script in desktop console via
qdbus org.kde.plasma-desktop /MainApplication \ loadScriptInInteractiveConsole /path/to/js/file
There is bug #238817 in KDE Bugzilla filed on this.