-
Notifications
You must be signed in to change notification settings - Fork 42
/
PVoutputOutput.py
51 lines (40 loc) · 1.73 KB
/
PVoutputOutput.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
import PluginLoader
import datetime
import urllib
import urllib2
class PVoutputOutput(PluginLoader.Plugin):
"""Sends the data from the Omnik inverter to PVoutput.org"""
def process_message(self, msg):
"""Send the information from the inverter to PVoutput.org.
Args:
msg (InverterMsg.InverterMsg): Message to process
"""
now = datetime.datetime.now()
if (now.minute % 5) == 0: # Only run at every 5 minute interval
self.logger.info('Uploading to PVoutput')
url = "http://pvoutput.org/service/r2/addstatus.jsp"
if self.config.getboolean('inverter', 'use_temperature'):
get_data = {
'key': self.config.get('pvout', 'apikey'),
'sid': self.config.get('pvout', 'sysid'),
'd': now.strftime('%Y%m%d'),
't': now.strftime('%H:%M'),
'v1': msg.e_today * 1000,
'v2': msg.p_ac(1),
'v5': msg.temperature,
'v6': msg.v_pv(1)
}
else:
get_data = {
'key': self.config.get('pvout', 'apikey'),
'sid': self.config.get('pvout', 'sysid'),
'd': now.strftime('%Y%m%d'),
't': now.strftime('%H:%M'),
'v1': msg.e_today * 1000,
'v2': msg.p_ac(1),
'v6': msg.v_pv(1)
}
get_data_encoded = urllib.urlencode(get_data)
request_object = urllib2.Request(url + '?' + get_data_encoded)
response = urllib2.urlopen(request_object)
self.logger.info(response.read()) # Show the response