How to program a cycle for counting solar power

I like to program a count method starting with a value which already has been imported by our solar panels. Then adding the daily or weekly import kwh and at every 1.000kwh HA has to send a message to me.