Creating new sensor for calculating daily energy

Hi, I need advice how to create sensor for calculating daily energy from sensor which measures current energy draw in Watts and store that data in database. My plug have another sensor for calculating daily energy, but reset every day at midnight, maybe is possible take data at morning 00:00 and last data at midnight 23:59 and difference between these two values will be my daily energy consuption. Thank you.

You already have this?