The calculation, in principle, is simple. Watts times hours divided by 1000
equals kilowatt-hours, kWh.
How easy this is to do in practice depends mainly on when you get updates from
the sensor.
If you get regular Watt readings every second, or every minute, or every hour,
then you can very easily convert this into kWh - if it’s every second,
multiply by 3.6; if it’s every minute, divide by 16.67; if it’s every hour,
divide by 1000.
The challenge comes if you do not get Watt readings on a regular basis,
because then you need to know the time interval since the last reading, as
well as whether it is safe to assume that the power consumption has been level
during that period of time, in order to calculate the energy consumption.
If your sensor tells you when the power consumption level changes, you should
probably multiply the time since the previous reading by the value of the
previous reading, in order to get the energy consumption during that time,
because the new power level has only just taken effect, so until then, it was
whatever the previous reading was.
Either way, in order to get the total energy consumption over an hour / day /
month / year you then need to sum these calculated values over the appropriate
time interval, which is pretty simple to do in Grafana.
All I can say beyond that is that the ease of finding out what the previous
power level was, and the time interval between that previous measurement and
the new measurement, depends on what your back-end data store is.
With any luck, your power sensor will give you regular measurements every N
seconds and you can do the simpler calculations.
Regards,
Antony.