Browse Source

Premier commit

master
Christophe SCAYA 2 years ago
commit
c10c71279f
  1. BIN
      docs/IQ Gateway Local API or UI Access using Token-TEB-00060.1.0-EN-2023-08-14.pdf
  2. 43
      enphase.py
  3. 11
      enphase.service

BIN
docs/IQ Gateway Local API or UI Access using Token-TEB-00060.1.0-EN-2023-08-14.pdf

Binary file not shown.

43
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)

11
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
Loading…
Cancel
Save