You are using a mish-mash of the new template integration and old template sensor platform configuration options.
Please see the examples here: Template - Home Assistant
You also can not turn a power sensor into an energy sensor just by changing the unit (first two sensors).
You need to integrate power with respect to time to get energy. You can use this to do it:
Make sure to use method: left to minimise approximation errors.
Your last sensor requires an availability template or you will see strange spikes in your energy use. See Why an availability template is important for energy template sensors
Finally, be careful with your capitalisation. it is kWh not kwh.