Used energy per hour

I need help finding, or creating a sensor (or two) for the kwh used per hour.
In “Homey” we have this app called “Power by the hour”.
The first thing it does is to calculate how much power you have used this hour (in Norway we have a tariff that costs more if you have used more than ex. 5kwh in a hour the past month. next step is 10kwh and so on)
The next thing, and the thing I think is more difficult to make. Is that during the hour, it calculates how much power you are expected to have used . Using this “expected usage” you can turn of devices and use less power to keep the usage below the threshold you have set.

How do I do this in Home Assistant? And is there something for this already?