Create entity to measure the consumption

Hello every one.

I want to create one entity to measure the consumption of one switch.

The ideia is once the switch is turned on starts to sum the kWh.

Switch (sonoff with tasmota) is connected to one lamp of 10w.

Once the light is turn on starts sum in one entity 0,003kw by the second until the light is turned off.

After I achieve this the ideia is to track the power consumption in energy dashboard.

Is this possible to do?

Thank you in advance

There is a custom app for doing just what you want. See here

or github

I there.
Thank you very much.
It works great.