Skip to content

Commit

Permalink
Reset input datastore when published and all datastores each night.
Browse files Browse the repository at this point in the history
  • Loading branch information
aaronjbrown committed Jan 22, 2022
1 parent 2c5ccf7 commit 61bb2c0
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions scripts/growatt_mqtt.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,14 @@ def publish_data(datastore, interval):
client.publish("home/solar/AC/energy/today", datastore.getValues(4, inputRegisters["Eac_today"], 1)[0] / 10, retain=True)
client.publish("home/solar/AC/energy/total", datastore.getValues(4, inputRegisters["Eac_total"], 1)[0] / 10, retain=True)

# We've consumed the energy data, so reset the store to prevent uploading duplicate data
if time.strftime("%H") == "00":
# If it's midnight, reset the whole datastore
datastore.reset()
else:
# It's daytime, so only reset the Input Registers
datastore.store['i'].reset()

# Keep repeating
timer = threading.Timer(interval, publish_data, args=(datastore, interval))
timer.start()
Expand Down

0 comments on commit 61bb2c0

Please sign in to comment.