pi@domoticzpi ~/domoticz/scripts/Omnik-Data-Logger $ cat OmnikExport.py
#!/usr/bin/python
import InverterMsg # Import the Msg handler
import socket # Needed for talking to inverter
import datetime # Used for timestamp
import sys
import logging
import ConfigParser, os
# For PVoutput
import urllib, urllib2
# Load the setting
mydir = os.path.dirname(os.path.abspath(__file__))
config = ConfigParser.RawConfigParser()
config.read([mydir + '/config-default.cfg', mydir + '/config.cfg'])
# Receive data with a socket
ip = config.get('inverter','ip')
port = config.get('inverter','port')
use_temp = config.getboolean('inverter','use_temperature')
wifi_serial = config.getint('inverter', 'wifi_sn')
mysql_enabled = config.getboolean('mysql', 'mysql_enabled')
mysql_host = config.get('mysql','mysql_host')
mysql_user = config.get('mysql','mysql_user')
mysql_pass = config.get('mysql','mysql_pass')
mysql_db = config.get('mysql','mysql_db')
domoticz_enabled = 'true'
domoticz_host = '192.168.1.10'
domoticz_port = '8080'
domoticz_url = 'json.htm'
#domoticz_enabled = config.getboolean('domoticz','domoticz_enabled')
#domoticz_host = config.get('domoticz','domoticz_host')
#domoticz_port = config.get('domoticz','domoticz_port')
#domoticz_url = config.get('domoticz','domoticz_url')
domoticz_temp = config.get('domoticz','domoticz_temp')
domoticz_Input_PV1 = config.get('domoticz','domoticz_Input_PV1')
domoticz_Input_PV2 = config.get('domoticz','domoticz_Input_PV2')
domoticz_AC_Output = config.get('domoticz','domoticz_AC_Output')
domoticz_Cur_Total = config.get('domoticz','domoticz_Cur_Total')
domoticz_AMP_1_2_3 = config.get('domoticz','domoticz_AMP_1_2_3')
pvout_enabled = config.getboolean('pvout','pvout_enabled')
pvout_apikey = config.get('pvout','pvout_apikey')
pvout_sysid = config.get('pvout','pvout_sysid')
log_enabled = config.getboolean('log','log_enabled')
log_filename = mydir + '/' + config.get('log','log_filename')
server_address = ((ip, port))
logger = logging.getLogger('OmnikLogger')
hdlr = logging.FileHandler(log_filename)
formatter = logging.Formatter('%(asctime)s %(levelname)s %(message)s')
hdlr.setFormatter(formatter)
logger.addHandler(hdlr)
logger.setLevel(logging.DEBUG)
for res in socket.getaddrinfo(ip, port, socket.AF_INET , socket.SOCK_STREAM):
af, socktype, proto, canonname, sa = res
try:
if log_enabled:
logger.info('connecting to %s port %s' % server_address)
s = socket.socket(af, socktype, proto)
s.settimeout(10)
except socket.error as msg:
s = None
continue
try:
s.connect(sa)
except socket.error as msg:
s.close()
s = None
continue
break
if s is None:
if log_enabled:
logger.error('could not open socket')
sys.exit(1)
s.sendall(InverterMsg.generate_string(wifi_serial))
data = s.recv(1024)
s.close()
msg = InverterMsg.InverterMsg(data) # This is where the magic happens
now = datetime.datetime.now()
if log_enabled:
logger.info("ID: {0}".format(msg.getID()))
# --------------------------------------------------
# Uploaden Temperature of Omnik Omvormer to Domoticz
# --------------------------------------------------
if domoticz_enabled:
url = ("http://" + domoticz_host + ":" + domoticz_port + "/" + domoticz_url)
if use_temp:
get_data = {
'svalue': msg.getTemp(),
'type': 'command',
'param': 'udevice',
'idx' : domoticz_temp,
'nvalue': '0'
}
else:
get_data = {
'svalue': msg.getTemp(),
'type': 'command',
'param': 'udevice',
'idx' : domoticz_temp,
'nvalue': '0'
}
get_data_encoded = urllib.urlencode(get_data)
request_object = urllib2.Request(url + '?' + get_data_encoded)
response = urllib2.urlopen(request_object)
# --------------------------------------------------
# Uploaden Input String (1) PV1 to Domoticz
# --------------------------------------------------
if use_temp:
get_data = {
'svalue': msg.getVPV(1),
'type': 'command',
'param': 'udevice',
'idx' : domoticz_Input_PV1,
'nvalue': '0'
}
else:
get_data = {
'svalue': msg.getVPV(1),
'type': 'command',
'param': 'udevice',
'idx' : domoticz_Input_PV1,
'nvalue': '0'
}
get_data_encoded = urllib.urlencode(get_data)
request_object = urllib2.Request(url + '?' + get_data_encoded)
response = urllib2.urlopen(request_object)
# --------------------------------------------------
# Uploaden Input String (2) PV2 to Domoticz
# --------------------------------------------------
if use_temp:
get_data = {
'svalue': msg.getVPV(2),
'type': 'command',
'param': 'udevice',
'idx' : domoticz_Input_PV2,
'nvalue': '0'
}
else:
get_data = {
'svalue': msg.getVPV(2),
'type': 'command',
'param': 'udevice',
'idx' : domoticz_Input_PV2,
'nvalue': '0'
}
get_data_encoded = urllib.urlencode(get_data)
request_object = urllib2.Request(url + '?' + get_data_encoded)
response = urllib2.urlopen(request_object)
# --------------------------------------------------
# Uploaden AC Power output to Domoticz
# --------------------------------------------------
if use_temp:
get_data = {
'svalue': msg.getVAC(1),
'type': 'command',
'param': 'udevice',
'idx' : domoticz_AC_Output,
'nvalue': '0'
}
else:
get_data = {
'svalue': msg.getVAC(1),
'type': 'command',
'param': 'udevice',
'idx' : domoticz_AC_Output,
'nvalue': '0'
}
get_data_encoded = urllib.urlencode(get_data)
request_object = urllib2.Request(url + '?' + get_data_encoded)
response = urllib2.urlopen(request_object)
# --------------------------------------------------
# Uploaden Current Power and Day Total to Domoticz
# --------------------------------------------------
if use_temp:
get_data = {
'svalue': str(msg.getPAC(1)) + ';' + str(msg.getEToday() * 1000),
'type': 'command',
'param': 'udevice',
'idx' : domoticz_Cur_Total,
'nvalue': '0'
}
else:
get_data = {
'svalue': str(msg.getPAC(1)) + ';' + str(msg.getEToday() * 1000),
'type': 'command',
'param': 'udevice',
'idx' : domoticz_Cur_Total,
'nvalue': '0'
}
get_data_encoded = urllib.urlencode(get_data)
request_object = urllib2.Request(url + '?' + get_data_encoded)
response = urllib2.urlopen(request_object)
# --------------------------------------------------
# Uploaden Ampere to Domoticz
# --------------------------------------------------
if use_temp:
get_data = {
'svalue': str(msg.getIPV(1)) + ';' + str(msg.getIPV(2)) + ';' + str(msg.getIAC(1)),
'type': 'command',
'param': 'udevice',
'idx' : domoticz_AMP_1_2_3,
'nvalue': '0'
}
else:
get_data = {
'svalue': str(msg.getIPV(1)) + ';' + str(msg.getIPV(2)) + ';' + str(msg.getIAC(1)),
'type': 'command',
'param': 'udevice',
'idx' : domoticz_AMP_1_2_3,
'nvalue': '0'
}
get_data_encoded = urllib.urlencode(get_data)
request_object = urllib2.Request(url + '?' + get_data_encoded)
response = urllib2.urlopen(request_object)
#-------------------------------------------------
#END OF DOMOTICZ ADJUSTMENT
#-------------------------------------------------
if mysql_enabled:
# For database output
import MySQLdb as mdb
if log_enabled:
logger.info('Uploading to database')
con = mdb.connect(mysql_host, mysql_user, mysql_pass, mysql_db);
with con:
cur = con.cursor()
cur.execute("""INSERT INTO minutes
(InvID, timestamp, ETotal, EToday, Temp, HTotal, VPV1, VPV2, VPV3,
IPV1, IPV2, IPV3, VAC1, VAC2, VAC3, IAC1, IAC2, IAC3, FAC1, FAC2,
FAC3, PAC1, PAC2, PAC3)
VALUES
(%s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s,
%s, %s, %s, %s, %s, %s, %s);""",
(msg.getID(), now, msg.getETotal(),
msg.getEToday(), msg.getTemp(), msg.getHTotal(), msg.getVPV(1),
msg.getVPV(2), msg.getVPV(3), msg.getIPV(1), msg.getIPV(2),
msg.getIPV(3), msg.getVAC(1), msg.getVAC(2), msg.getVAC(3),
msg.getIAC(1), msg.getIAC(2), msg.getIAC(3), msg.getFAC(1),
msg.getFAC(2), msg.getFAC(3), msg.getPAC(1), msg.getPAC(2),
msg.getPAC(3)) );
if pvout_enabled and (now.minute % 5) == 0:
if log_enabled:
logger.info('Uploading to PVoutput')
url = "http://pvoutput.org/service/r2/addstatus.jsp"
if use_temp:
get_data = {
'key': pvout_apikey,
'sid': pvout_sysid,
'd': now.strftime('%Y%m%d'),
't': now.strftime('%H:%M'),
'v1': msg.getEToday() * 1000,
'v2': msg.getPAC(1),
'v5': msg.getTemp(),
'v6': msg.getVPV(1)
}
else:
get_data = {
'key': pvout_apikey,
'sid': pvout_sysid,
'd': now.strftime('%Y%m%d'),
't': now.strftime('%H:%M'),
'v1': msg.getEToday() * 1000,
'v2': msg.getPAC(1),
'v6': msg.getVPV(1)
}
get_data_encoded = urllib.urlencode(get_data) # UrlEncode the parameters
request_object = urllib2.Request(url + '?' + get_data_encoded) # Create request object
response = urllib2.urlopen(request_object) # Make the request and store the response
if log_enabled:
logger.info(response.read()) # Show the response
capture and import smartmeter data from Web Solar Log
Moderator: leecollings
-
- Posts: 6
- Joined: Friday 20 February 2015 20:32
- Target OS: Raspberry Pi / ODroid
- Domoticz version:
- Contact:
Re: capture and import smartmeter data from Web Solar Log
and config
pi@domoticzpi ~/domoticz/scripts/Omnik-Data-Logger $ cat config.cfg
################
### Settings ###
################
[inverter]
# IP address of your Omnik inverter
ip = 192.168.1.30
# Default for a Omnik with Wifi module
port = 8899
# S/N of the wifi kit
wifi_sn = 602xxxxx
#use temperature of inverter for pvoutput
use_temperature = true
[mysql]
# Enable for exporting to a mysql database
mysql_enabled = false
# Host where the mysql server is active
mysql_host = 127.0.0.1
mysql_user =
mysql_pass =
mysql_db =
[pvout]
# Enable or disable uploading to PVoutput
pvout_enabled = true
# These two can be found at http://pvoutput.org/account.jsp
pvout_apikey = a6203somekey3506c1cc489d
pvout_sysid = 187483
[log]
log_enabled = true
log_filename = omnik-export.log
[domoticz]
domoticz_enabled = true
domoticz_host = 192.168.1.10
domoticz_port = 8080
domoticz_url = json.htm
# Provide IDX here of the specific devices
domoticz_temp = 15
domoticz_Input_PV1 = 11
domoticz_Input_PV2 = 10
domoticz_AC_Output = 12
domoticz_Cur_Total = 14
domoticz_AMP_1_2_3 = 16
pi@domoticzpi ~/domoticz/scripts/Omnik-Data-Logger $ cat config.cfg
################
### Settings ###
################
[inverter]
# IP address of your Omnik inverter
ip = 192.168.1.30
# Default for a Omnik with Wifi module
port = 8899
# S/N of the wifi kit
wifi_sn = 602xxxxx
#use temperature of inverter for pvoutput
use_temperature = true
[mysql]
# Enable for exporting to a mysql database
mysql_enabled = false
# Host where the mysql server is active
mysql_host = 127.0.0.1
mysql_user =
mysql_pass =
mysql_db =
[pvout]
# Enable or disable uploading to PVoutput
pvout_enabled = true
# These two can be found at http://pvoutput.org/account.jsp
pvout_apikey = a6203somekey3506c1cc489d
pvout_sysid = 187483
[log]
log_enabled = true
log_filename = omnik-export.log
[domoticz]
domoticz_enabled = true
domoticz_host = 192.168.1.10
domoticz_port = 8080
domoticz_url = json.htm
# Provide IDX here of the specific devices
domoticz_temp = 15
domoticz_Input_PV1 = 11
domoticz_Input_PV2 = 10
domoticz_AC_Output = 12
domoticz_Cur_Total = 14
domoticz_AMP_1_2_3 = 16
capture and import smartmeter data from Web Solar Log
Is there anyone who can help me with the script if you have 2 inverters. The script for one works perfect.
- sincze
- Posts: 1299
- Joined: Monday 02 June 2014 22:46
- Target OS: Raspberry Pi / ODroid
- Domoticz version: 2024.4
- Location: Netherlands / Breda Area
- Contact:
Re: capture and import smartmeter data from Web Solar Log
Maybe we need to create 2 scripts one for each inverter, as each inverter can be triggered via a unique package.Solar wrote:Is there anyone who can help me with the script if you have 2 inverters. The script for one works perfect.
Or did you already solve this in a different way?
Pass2php
LAN: RFLink, P1, OTGW, MySensors
USB: RFXCom, ZWave, Sonoff 3
MQTT: ZIgbee2MQTT,
ZWAVE: Zwave-JS-UI
WIFI: Mi-light, Tasmota, Xiaomi Shelly
Solar: Omnik, PVOutput
Video: Kodi, Harmony HUB, Chromecast
Sensors: You name it I got 1.
LAN: RFLink, P1, OTGW, MySensors
USB: RFXCom, ZWave, Sonoff 3
MQTT: ZIgbee2MQTT,
ZWAVE: Zwave-JS-UI
WIFI: Mi-light, Tasmota, Xiaomi Shelly
Solar: Omnik, PVOutput
Video: Kodi, Harmony HUB, Chromecast
Sensors: You name it I got 1.
-
- Posts: 6
- Joined: Sunday 14 December 2014 23:38
- Target OS: Raspberry Pi / ODroid
- Domoticz version: Latest B
- Contact:
Re: capture and import smartmeter data from Web Solar Log
I tried this script too, but this is what i get:
Someone an idea?
It's a copy from the code of the user kaatje
Code: Select all
pi@domoticzpi ~ $ sudo python /home/pi/Omnik-Data-Logger/OmnikExport.py
File "/home/pi/Omnik-Data-Logger/OmnikExport.py", line 67
af, socktype, proto, canonname, sa = res
^
IndentationError: expected an indented block
It's a copy from the code of the user kaatje
-
- Posts: 21
- Joined: Wednesday 06 July 2016 22:31
- Target OS: Raspberry Pi / ODroid
- Domoticz version:
- Contact:
Re: capture and import smartmeter data from Web Solar Log
Hello
I copied Omnik-Data-Logger en followd the post from kaatje.
But i can't get it to work.
Anyone can help?
I copied Omnik-Data-Logger en followd the post from kaatje.
But i can't get it to work.
Anyone can help?
Who is online
Users browsing this forum: No registered users and 0 guests