Just noticed that with the latest unifi update, they must have changed the case of the x-csrf-token which busted this script 
This commit fixes that though: fix(unifi): csrf case sensitivity · JonGilmore/ha-personal@76c17a1 · GitHub
Just noticed that with the latest unifi update, they must have changed the case of the x-csrf-token which busted this script 
This commit fixes that though: fix(unifi): csrf case sensitivity · JonGilmore/ha-personal@76c17a1 · GitHub