i use ubiquiti mpower . It does not only allow scripting and on of but calculates also the costs of the electricity used till the moment and of course read used power FROM THE WALL. it is also good for other purposes... and it is bloody cheap
3 ports version cost 57 USD (has only wifi unfortunately )
https://www.eurodk.com/en/products/mfi/mpower/pro version (6 port + eth & wifi connection) cost a lil more 90 USD
https://www.eurodk.com/en/products/mfi/mpower-pro