A method for controlling heat transfer between a local cooling system and a local heating system, wherein the local heating system comprises a heating circuit (30, 30') having a feed conduit (34, 34') for an incoming flow of heat transfer fluid having a first temperature, and a return conduit (36, 36') for a return flow of heat transfer fluid having a second temperature, wherein the second temperature is lower than the first temperature, wherein the local cooling system comprises a cooling circuit (40, 40') having a feed conduit (34, 34') for an incoming flow of heat transfer fluid having a third temperature, and a return conduit (36, 36') for a return flow of heat transfer fluid having a fourth temperature, wherein the fourth temperature is higher than the third temperature, and wherein the fourth temperature is lower than the second temperature, and wherein a heat pump (50, 50') is connected between the local cooling system and the local heating system, the heat pump (50, 50') being configured to transfer heat from the local cooling system to the local heating system, the method comprising: determining a local energy consumption need (LCC1, LCC2) of the local cooling system (40, 40'); determining a local energy consumption need (LHC1, LHC2) of the local heating system (30, 30'); controlling, based on the local energy consumption need (LCC1, LCC2) of the local cooling system and the local energy consumption need (LHC1, LHC2) of the local heating system, the heat pump (50, 50') characterized in that the method further comprising one or more of: introducing a heating control parameter and determining a value indicating an overall heating consumption need of a plurality of local heating systems in relation to overall available heating capacity of a heating grid to which the local heating systems are connected, wherein the controlling of the heat pump (50, 50') is also based on the value of the heating control parameter; introducing a cooling control parameter and determining a value indicating an overall cooling consumption need of a plurality of local cooling systems in relation to overall available cooling capacity of a cooling grid to which the local cooling systems are connected, wherein the controlling of the heat pump (50, 50') is also based on the value of the cooling control parameter; and introducing an electric power control parameter and determining a value indicating an overall electrical power need in relation to overall available electrical power of an electric grid to which the heat pump (50, 50') is connected, wherein the controlling of the heat pump (50, 50') is also based on the value of the electric power control parameter. determining a local energy consumption need (LCC1, LCC2) of the local cooling system (40, 40'); determining a local energy consumption need (LHC1, LHC2) of the local heating system (30, 30'); controlling, based on the local energy consumption need (LCC1, LCC2) of the local cooling system and the local energy consumption need (LHC1, LHC2) of the local heating system, the heat pump (50, 50') characterized in that the method further comprising one or more of: introducing a heating control parameter and determining a value indicating an overall heating consumption need of a plurality of local heating systems in relation to overall available heating capacity of a heating grid to which the local heating systems are connected, wherein the controlling of the heat pump (50, 50') is also based on the value of the heating control parameter; introducing a cooling control parameter and determining a value indicating an overall cooling consumption need of a plurality of local cooling systems in relation to overall available cooling capacity of a cooling grid to which the local cooling systems are connected, wherein the controlling of the heat pump (50, 50') is also based on the value of the cooling control parameter; and introducing an electric power control parameter and determining a value indicating an overall electrical power need in relation to overall available electrical power of an electric grid to which the heat pump (50, 50') is connected, wherein the controlling of the heat pump (50, 50') is also based on the value of the electric power control parameter. introducing a heating control parameter and determining a value indicating an overall heating consumption need of a plurality of local heating systems in relation to overall available heating capacity of a heating grid to which the local heating systems are connected, wherein the controlling of the heat pump (50, 50') is also based on the value of the heating control parameter; introducing a cooling control parameter and determining a value indicating an overall cooling consumption need of a plurality of local cooling systems in relation to overall available cooling capacity of a cooling grid to which the local cooling systems are connected, wherein the controlling of the heat pump (50, 50') is also based on the value of the cooling control parameter; and introducing an electric power control parameter and determining a value indicating an overall electrical power need in relation to overall available electrical power of an electric grid to which the heat pump (50, 50') is connected, wherein the controlling of the heat pump (50, 50') is also based on the value of the electric power control parameter.