ketra / nl.ketra.enphase.local

Enphase envoy local API V7 firmware
GNU General Public License v3.0
1 stars 2 forks source link

Data is not updating #1

Open Slofware opened 1 year ago

Slofware commented 1 year ago

It looks like the data is not updating, it is shows that the last update was a day ago. Also today when the sun was shining the values didn't change.

Slofware commented 1 year ago

import requests import datetime import json import time from requests.auth import HTTPBasicAuth, HTTPDigestAuth

gInlog = '**' gPassword = '*****' gIP = '---------' authToken = ""

while True:

print('Get serialnumber and version firmware and test LAN connection to Envoy') try: systemXML = requests.get('http://' + gIP + '/info.xml', verify=False) if "" in systemXML.text: envoyserial= systemXML.text.split("")[1].split("")[0] else: print('Serial not found') if "" in systemXML.text: envoyfirmware= systemXML.text.split("")[1].split("")[0][:2] #note [:2] first 2 chars else: print('Firmware not found')
except Exception as err: print('Error connection...') break

if authToken == "": print('Go login with Enphase Enlighten Account') data = { 'user[email]': gInlog, 'user[password]': gPassword } try: response = requests.post('https://enlighten.enphaseenergy.com/login/login.json?', data=data) except Exception as err: print('Error login...') break

   response_data = json.loads(response.text)
   print("Got sessionId '" + response_data['session_id'] + "' from Enphase Enlighten.")

   print('Get authToken')
   data = {
    'session_id': response_data['session_id'],
    'serial_num': envoyserial,
    'username': gInlog
   }

   try:
       response = requests.post('https://entrez.enphaseenergy.com/tokens', json=data)
   except Exception as err:
       print('Error token...')
       break

   authToken = response.text
   print("Got authToken '" + authToken + "' from Enphase Energy.")

if authToken != "":

   print('Validate token on IQ Gateway')
   headers = {
           "Authorization": "Bearer " + authToken
   }
   try:
       response = requests.get('https://' + gIP + '/auth/check_jwt', headers=headers, verify=False)
   except Exception as err:
       print('Error auth...')
       break

   print('Check response, a valid response will look like: <!DOCTYPE html><h2>Valid token.</h2>')
   if "Valid token." in response.text:

       print('Extract the sessionId from the cookies.')
       sessionId = response.cookies['sessionId']

       if sessionId != '':
           print("Got sessionId '" + sessionId + "' from {}".format(gIP) )
       else:
           print("Error getting sessionId and/or authToken using Enphase Enlighten username and password.")
           break

       try:
           jsoninverters = requests.get('http://' + gIP + '/api/v1/production/inverters/' ,cookies=dict(sessionid=sessionId), verify=False)
       except Exception as err:
           print("Error connecting to Enphase Envoy on {} error: {}".format(gIP , err) )

       if (jsoninverters.status_code == 200):
           inverters=jsoninverters.json()
           for inverter in inverters:
               print( 'Inverter: ' + inverter['serialNumber'] + ' Lastreport: ' + str(inverter['lastReportDate'])  + ' Reports: ' + str(inverter['lastReportWatts']) )

       try:
           jsonproduction = requests.get('https://' + gIP + '/production.json', cookies=dict(sessionid=sessionId), verify=False)
       except Exception as err:
           print("Error connecting to Enphase Envoy on {} error: {}".format(gIP, err) )
           break 

       if (jsonproduction.status_code == 200):
           production=jsonproduction.json()['production'][0]
           print('Total production read {} Watts, counter is {}'.format(production['wNow'], production['whLifetime']))

   else:
       authToken = ""

else: authToken = ""

print('Wait....') time.sleep(10)

print('Exited...')

Slofware commented 1 year ago

Made this in Python and this is getting the data:

jsonproduction = requests.get('https://' + gIP + '/production.json', cookies=dict(sessionid=sessionId), verify=False)

RoadXY commented 1 year ago

Je wachtwoord staat er in...

Slofware commented 1 year ago

Je wachtwoord staat er in...

Thanks!!!!!!!

Slofware commented 1 year ago

Got it running now, took me a few lessons but I think it is oke. Now in a test mode, I will update when it is oke

ketra commented 1 year ago

The API seems to work weid, when the local (installer) webinterface is openened, the data refreshes every 10 seconds, but when the webinterface is closed the api only updates once every 5 minutes. now busy with investigating why this is happening, and how to trigger the update.