[SOLVED]APIs for Noobs

Posted on
Sun Jan 19, 2014 10:31 am
berkinet offline
User avatar
Posts: 3290
Joined: Nov 18, 2008
Location: Berkeley, CA, USA & Mougins, France

Re: APIs for Noobs

:D

Posted on
Tue Jan 28, 2014 1:03 pm
Bollar offline
Posts: 528
Joined: Aug 11, 2013

Re: APIs for Noobs

So, now that I'm getting ready to send data to a site, I have been playing with feeding variables into a url. This script modifies the PVOutput script so that the key and SID are pulled from variables.
Code: Select all
import urllib2
import urllib
data = {}
data['key'] = (indigo.variables[775241456].value) #pvoutputKey
data['sid'] = (indigo.variables[1685522851].value) #pvoutputSID
url_values = urllib.urlencode(data)
url = 'http://pvoutput.org/service/r2/getstatus.jsp'
full_url = url + '?' + url_values
response = urllib2.urlopen(full_url)
f = response.read()
pv = f.split(",")

indigo.variable.updateValue(1920763080, value=str(pv[0])) # Date
indigo.variable.updateValue(1705190321, value=str(pv[1])) # Time
indigo.variable.updateValue(690513764, value=str(pv[2])) # Energy Generation
indigo.variable.updateValue(133349311, value=str(pv[3])) # Power Generation
indigo.variable.updateValue(1101260058, value=str(pv[4])) # Energy Consumption
indigo.variable.updateValue(1991582166, value=str(pv[5])) # Power Consumption
indigo.variable.updateValue(835833028, value=str(pv[6])) # Efficiency
indigo.variable.updateValue(74384762, value=str(pv[7])) # Temperature
indigo.variable.updateValue(114588059, value=str(pv[8])) # Voltage

response.close()

pvPowerGen = (int(indigo.variables[133349311].value))
pvPowerCon = (int(indigo.variables[1991582166].value))
pvNetPower = pvPowerGen - pvPowerCon

indigo.variable.updateValue(1894842094, value=str(pvNetPower))

pvEnergyGen = (int(indigo.variables[690513764].value))
pvEnergyCon = (int(indigo.variables[1101260058].value))
pvNetEnergy = pvEnergyGen - pvEnergyCon

indigo.variable.updateValue(326233494, value=str(pvNetEnergy))

Insteon / Z-Wave / Bryant Evolution Connex /Tesla / Roomba / Elk M1 / SiteSage / Enphase Enlighten / NOAA Alerts

Posted on
Tue Jan 28, 2014 2:33 pm
Bollar offline
Posts: 528
Joined: Aug 11, 2013

Re: APIs for Noobs

This script uploads data to PVOutput
Code: Select all
import urllib2
import urllib
data = {}
data['key'] = (indigo.variables[775241456].value)  # pvoutputKey
data['sid'] = (indigo.variables[328824441].value)  # pvoutputSIDTest
data['d'] = (indigo.variables[1920763080].value)   # Date
data['t'] = (indigo.variables[1705190321].value)   # Time
data['v1'] = (indigo.variables[690513764].value)   # Energy Generation
data['v2'] = (indigo.variables[133349311].value)   # Power Generation
data['v3'] = (indigo.variables[1101260058].value)  # Energy Consumption
data['v4'] = (indigo.variables[1991582166].value)  # Power Consumption
data['v5'] = (indigo.variables[74384762].value)    # Temperature
data['v6'] = (indigo.variables[1815759961].value)  # Voltage
data['v7'] = (indigo.variables[1257323281].value)  # Extended V7


url_values = urllib.urlencode(data)
url = 'http://pvoutput.org/service/r2/addstatus.jsp'
full_url = url + '?' + url_values
response = urllib2.urlopen(full_url)
f = response.read()
pv = f.split(",")

indigo.variable.updateValue(284728925, value=str(f))

response.close()

Insteon / Z-Wave / Bryant Evolution Connex /Tesla / Roomba / Elk M1 / SiteSage / Enphase Enlighten / NOAA Alerts

Posted on
Wed Feb 05, 2014 8:45 pm
Bollar offline
Posts: 528
Joined: Aug 11, 2013

Re: [SOLVED]APIs for Noobs

Unfortunately, I can't share the code, but Indigo allows me to integrate my eMonitor, Weather and Enphase inverter outputs into pvmonitor.org: http://pvoutput.org/intraday.jsp?id=26327&sid=24036

Love it!

Insteon / Z-Wave / Bryant Evolution Connex /Tesla / Roomba / Elk M1 / SiteSage / Enphase Enlighten / NOAA Alerts

Who is online

Users browsing this forum: No registered users and 3 guests