Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Enphase Local Green Data #25

Open
wants to merge 889 commits into
base: master
Choose a base branch
from

Conversation

integlikewhoa
Copy link

@integlikewhoa integlikewhoa commented Nov 26, 2020

Enphase API has been down due to server issues and also has limits on pulls. Is there a way to add pulling local data to this version.

Someone has already made a fork off the original version that does this and I'm thinking pulling local data is much better then cloud.

Here is what it looked it.

try:
        url = urllib.request.urlopen("http://192.168.1.138/production.json?details=1&classic-1")
    except HTTPError as error:
        print(time_now() + " ERROR: Data not retrieved because %s", error)
    except URLError as error:
        if isinstance(error.reason, socket.timeout):
            print(time_now() + " ERROR: socket.timeout")
        else:
            print(time_now() + " ERROR: Some other error happened")
    else:
        urlGreenData = url.read().decode('utf-8')
        greenEnergyData = json.loads(urlGreenData)

        consW = greenEnergyData["consumption"][0]["wNow"]
        prodW = greenEnergyData["production"][1]["wNow"]
        VoltN = greenEnergyData["consumption"][0]["rmsVoltage"]
        netW = int(float(prodW))-int(float(consW))

        consA = int(float(consW)) / VoltN 
    #excessA = int(float(netW))/VoltN
    # In case, greenEnergyData will contain something like this:
    #   MTU, Time, Power, Cost, Voltage
    #   Solar,11/11/2017 14:20:43,-2.957,-0.29,124.3
    # The only part we care about is -2.957 which is negative
    # kW currently being generated. When 0kW is generated, the
    # negative disappears so we make it optional in the regex
    # below.
    #m = re.search(b'^Solar,[^,]+,-?([^, ]+),', greenEnergyData, re.MULTILINE)
    #remove total car current to work out actual greenEnergyAmpsOffset
        totalAmps = total_amps_actual_all_twcs()
        greenEnergyAmpsOffset = -1*consA + totalAmps + .1 
        		#.1 is for slight bias to import ( 100 watts or so)
    # print (totalAmps)
    # print (prodW)
        if(prodW>0):
            #solarW = int(float(m.group(1)) * 1000)
            solarW = int(float(prodW))
        # Use backgroundTasksLock to prevent changing maxAmpsToDivideAmongSlaves
        # if the main thread is in the middle of examining and later using
        # that value.
            backgroundTasksLock.acquire()

        # Watts = Volts * Amps
        # Car charges at 240 volts in North America so we figure
        # out how many amps * 240 = solarW and limit the car to
        # that many amps.
            maxAmpsToDivideAmongSlaves = (solarW / VoltN) + \
                                          greenEnergyAmpsOffset
            if(debugLevel >= 1):
                print("%s: Solar generating %dW so limit car charging to:\n" \
                     "          %.2fA + %.2fA = %.2fA.  Charge when above %.0fA (minAmpsPerTWC)." % \
                     (time_now(), solarW, (solarW / VoltN),
                     greenEnergyAmpsOffset, maxAmpsToDivideAmongSlaves,
                     minAmpsPerTWC))

            backgroundTasksLock.release()
        else:
            print(time_now() +
                " ERROR: Can't determine current solar generation from:\n" +
                str(greenEnergyData))

dschuesae and others added 30 commits August 11, 2020 18:04
…ReturningAlwaysSameValuesForConsumptionAndProduction

Returns 0 for consumption and not generation value
adding 'yesterday' definition to TWCMaster.py
Fixed comma-mistake which prevented MQTTStatus.py from working.
when minAmps and maxAmps are the same
Co-authored-by: Mike Bishop <[email protected]>
ngardiner and others added 30 commits February 18, 2021 21:08
bug fixes, minor code tweaks etc. for TesalAPI.py
High-pri log if Powerwall auth needed
New menu Graphs, it allows to represent energy graphs base on the SQL…
…tps installs, handle date not being specified for graphs, add capability queries for Logging modules so we can support graphing across more Logging modules in future
…ing for JSONDecodeError exceptions, added Graphs menu to Modern theme
Limit applications of Max Amps during check_green_energy
To use it, you can create a free account on sentry.io
After that, you get a dashboard with errors, and you can get notified by email
of any errors
Added Raspberry Pi OS dependencies
Starting from pymysql v1.0.2 user, password, host, database are now
keyword-only.
Fixes #251
[WIP] Use Python logging module for logging
Added Raspberry Pi OS dependencies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.