Split energy consumption of one entity in more entities based on the device's operating mode?

Answer can be found in this topic:
https://community.home-assistant.io/t/conditional-split-energy-consumption