Time controlled write value of a sensor into variable

I would like to write the value of sensor total_current to variable x at sunset and the value at sunrise to variable y.

The difference gives me the power consumption over night.

Does somebody has an idea?

This is an English only forum - please re-post in English