Optimisation of battery usage in Smart Grids