commit c10c71279fac7afc57251e27e9f76ff817fff304 Author: Christophe SCAYA <> Date: Fri Feb 16 21:53:42 2024 +0100 Premier commit diff --git a/docs/IQ Gateway Local API or UI Access using Token-TEB-00060.1.0-EN-2023-08-14.pdf b/docs/IQ Gateway Local API or UI Access using Token-TEB-00060.1.0-EN-2023-08-14.pdf new file mode 100644 index 0000000..eb8f896 Binary files /dev/null and b/docs/IQ Gateway Local API or UI Access using Token-TEB-00060.1.0-EN-2023-08-14.pdf differ diff --git a/enphase.py b/enphase.py new file mode 100644 index 0000000..6190d21 --- /dev/null +++ b/enphase.py @@ -0,0 +1,43 @@ +import json +import requests +import base64 +import time +import urllib3 +import logging +import os + +urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning) +logging.basicConfig(level=logging.INFO, filename=os.path.join(os.path.dirname(__file__),'enphase.log'), filemode="a+",format="%(asctime)-15s %(levelname)-8s %(message)s") + +user='christophe.scaya@gmail.com' +password='92@!Z&KYxt8shT' +envoy_serial='482330092358' +ip='192.168.0.201' +ip_esp='192.168.0.115' + +"""data = {'user[email]': user, 'user[password]': password} +response = requests.post('http://enlighten.enphaseenergy.com/login/login.json?',data=data) +response_data = json.loads(response.text) +data = {'session_id': response_data['session_id'], 'serial_num': envoy_serial, 'username': user} +response = requests.post('http://entrez.enphaseenergy.com/tokens', json=data) +token=response.text""" + +token='eyJraWQiOiI3ZDEwMDA1ZC03ODk5LTRkMGQtYmNiNC0yNDRmOThlZTE1NmIiLCJ0eXAiOiJKV1QiLCJhbGciOiJFUzI1NiJ9.eyJhdWQiOiI0ODIzMzAwOTIzNTgiLCJpc3MiOiJFbnRyZXoiLCJlbnBoYXNlVXNlciI6Im93bmVyIiwiZXhwIjoxNzM5MTA4NTIzLCJpYXQiOjE3MDc1NzI1MjMsImp0aSI6IjE5MmI0YjJhLTNjMTktNDc3YS1hZTc5LTdlM2FkZTY4ZWI3MSIsInVzZXJuYW1lIjoiY2hyaXN0b3BoZS5zY2F5YUBnbWFpbC5jb20ifQ.crL1eSrSfZ76AtrQT_vPCukcjA0I9Yyj7HO1bMJSbl6KiAznrETfr85HluwAJrd2KI7mTwNzHZZrVnwPiN4rAA' + +headers = {'Accept': 'application/json', + 'Authorization': 'Bearer '+token,} + +while True: + try: + response = requests.get('http://'+ip+'/ivp/meters/reports/consumption', verify=False, headers=headers) + json=response.json() + total = round(json[0]['cumulative']['currW']) + net = round(json[1]['cumulative']['currW']) + panneaux = total-net + #esp_cmd = requests.get('http://'+ip_esp+'/control?cmd=event,setPwr='+str(net)) + logging.info("Total: "+str(total)+" Panneaux: "+str(panneaux)+" Enedis: "+str(net)) + print("Total: "+str(total)+" Panneaux: "+str(panneaux)+" Enedis: "+str(net)) + time.sleep(2) + except requests.exceptions.RequestException as e: + logging.error(e) + time.sleep(30) diff --git a/enphase.service b/enphase.service new file mode 100644 index 0000000..2267e96 --- /dev/null +++ b/enphase.service @@ -0,0 +1,11 @@ +[Unit] +Description=Enphase service +After=multi-user.target + +[Service] +Type=simple +Restart=always +ExecStart=/usr/bin/python3 /home/chistophe/Bureau/enphase/enphase.py + +[Install] +WantedBy=multi-user.target