Advertisement
Guest User

Untitled

a guest
Aug 23rd, 2018
686
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.09 KB | None | 0 0
  1. #!/usr/bin/python3
  2.  
  3. import requests
  4. import json
  5. import datetime
  6. from datetime import datetime
  7.  
  8. # this is the default URL for the admin interface of SunPower PVS5
  9. pvs5_url = "http://172.27.153.1/cgi-bin/dl_cgi?Command=DeviceList"
  10.  
  11. # pvoutput.org
  12. pvoutput_url = "https://pvoutput.org/service/r2/addstatus.jsp"
  13. pvoutput_key = "api_key"
  14. pvoutput_systemid = "systemdid"
  15.  
  16. r = requests.get(pvs5_url)
  17.  
  18. sum = 0
  19. usage = 0
  20. for device in r.json()["devices"]:
  21.     if device["MODEL"] == "AC_Module_Type_D" and device["STATE"] != "error":
  22.         sum += float(device["p_3phsum_kw"])*1000
  23.     if device["MODEL"] == "PVS5M0400c":
  24.         usage = float(device["p_3phsum_kw"])*1000*-1
  25.  
  26. date = datetime.now()
  27. requests.post(pvoutput_url, data={"d":date.strftime('%Y%m%d'), "t":date.strftime('%H:%M'), "v2":sum}, headers = {'X-Pvoutput-Apikey': pvoutput_key, 'X-Pvoutput-SystemId': pvoutput_systemid})
  28. requests.post(pvoutput_url, data={"d":date.strftime('%Y%m%d'), "t":date.strftime('%H:%M'), "n":1, "v4": usage}, headers = {'X-Pvoutput-Apikey': pvoutput_key, 'X-Pvoutput-SystemId': pvoutput_systemid})
  29.  
  30. exit;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement