Electricity balanced model and agent for community energy optimisation