Skip to content

Commit

Permalink
Merge pull request johanmeijer#237 from githubDante/pv_out_limit3
Browse files Browse the repository at this point in the history
PvOut Limit 3
  • Loading branch information
johanmeijer authored Nov 28, 2022
2 parents 3636e50 + 297cb3b commit 72c410b
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 3 deletions.
3 changes: 2 additions & 1 deletion examples/grott.ini
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,8 @@

#pvoutput = True
#apikey = yourapikey

# Data upload limit (in minutes)
#pvuplimit = 5
# Use this if you have one inverter
#systemid = 12345

Expand Down
2 changes: 2 additions & 0 deletions grottconf.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ def __init__(self, vrm):
self.pvinverterid[1] = "inverter1"
self.pvdisv1 = False
self.pvtemp = False
self.pvuplimit = 5

#influxdb default
self.influx = False
Expand Down Expand Up @@ -391,6 +392,7 @@ def procconf(self):
if config.has_option("PVOutput","pvdisv1"): self.pvdisv1 = config.get("PVOutput","pvdisv1")
if config.has_option("PVOutput","pvinverters"): self.pvinverters = config.getint("PVOutput","pvinverters")
if config.has_option("PVOutput","apikey"): self.pvapikey = config.get("PVOutput","apikey")
if config.has_option("PVOutput", "pvuplimit"): self.pvuplimit = config.getint("PVOutput", "pvuplimit")
# if more inverter are installed at the same interface (shinelink) get systemids
#if self.pvinverters > 1 :
for x in range(self.pvinverters+1) :
Expand Down
32 changes: 30 additions & 2 deletions grottdata.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,37 @@
import struct
import textwrap
from itertools import cycle # to support "cycling" the iterator
import json, codecs
import json, codecs
from typing import Dict
# requests

#import mqtt
import paho.mqtt.publish as publish


class GrottPvOutLimit:

def __init__(self):
self.register: Dict[str, int] = {}

def ok_send(self, pvserial: str, conf) -> bool:
now = time.perf_counter()
ok = False
if self.register.get(pvserial):
ok = True if self.register.get(pvserial) + conf.pvuplimit * 60 < now else False
if ok:
self.register[pvserial] = int(now)
else:
if conf.verbose: print(f'\t - PVOut: Update refused for {pvserial} due to time limitation')
else:
self.register.update({pvserial: int(now)})
ok = True
return ok


pvout_limit = GrottPvOutLimit()


# Formats multi-line data
def format_multi_line(prefix, string, size=80):
size -= len(prefix)
Expand Down Expand Up @@ -494,7 +519,10 @@ def procdata(conf,data):

if not pvidfound:
if conf.verbose : print("\t - " + "pvsystemid not found for inverter : ", definedkey["pvserial"])
return
return
if not pvout_limit.ok_send(definedkey["pvserial"], conf):
# Will print a line for the refusal in verbose mode (see GrottPvOutLimit at the top)
return
if conf.verbose : print("\t - " + "Grott send data to PVOutput systemid: ", pvssid, "for inverter: ", definedkey["pvserial"])
pvheader = {
"X-Pvoutput-Apikey" : conf.pvapikey,
Expand Down

0 comments on commit 72c410b

Please sign in to comment.