You don’t need to factory reset the Shelly. Reset of the total energy value (aenergy:total) can be done via API call.
First, get the actual values with:
http://>IP-Shelly</rpc/Shelly.GetStatus
The reset of aenergy is done by (e. g. for Shelly Plus 1pm):
http://>IP-Shelly</rpc/Switch.ResetCounters?id=0&type=[“aenergy”]
Reference: Switch | Shelly Technical Documentation