Optimisation of energy managament