Omnik Solar Inverter

From Domoticz
Jump to navigation Jump to search

Start of Omnik Solar Inverter Wiki Page

Foreword

This wiki exists out of two parts;

  1. a cronjob python script that will be posting values into Domoticz.
  2. a domoticz configuration part where you will be creating the appropriate virtual sensors.

By default the Omnik Solar Inverter can upload all performance values of the inverter to its own portal. (http://www.omnikportal.com/Terminal/TerminalDefault.aspx?come=Public)

The main reason I made this script was because I want to register data myself. The Omnik Inverter can be triggered by sending a 'magic-packet' to it (based upon the great work of Woutrrr: https://github.com/Woutrrr/Omnik-Data-Logger) or grab the data while it is sending it on its own.


Supported protocol

This script will only work with the V4 protocol as used in the older embedded ethernet loggers. It is not compatible with the newer V5 protocol. Currently there is a github project working on this, however its still under development. (XtheOne Datalogger https://github.com/XtheOne/Inverter-Data-Logger).


My current setup

To give a short description of my current system, below a short description of the situation at my home.

Solar Inverter

I have an Omnik 4k Solar Inverter with 2 DC input strings attached to it and '1 AC Output string'. Omnik creates from these 2 DC input strings 1 AC output string.

Software

I'm using a script from Woutrrr, this pulls out the data from my Omnik Solar inverter and stores it in Domoticz using JSON.

Prepare Domoticz

If you don't know how to create a virtual sensor chances are you have never done this before.

  1. Go to "Hardware"
  2. Fill in the name field with a desired name (like "Virtual")
  3. Choose for type the "Dummy, does nothing, use for virtual switches only"
  4. Click on "Add"
  5. The added hardware is now added to the hardware list. In the same row there is a "Create virtual sensor" button shown. Click on it.

Now you are ready to create virtual devices.

  1. Go to "Hardware"
  2. Press "Create virtual sensor".
  3. Fill in the name field with a desired name
  4. choose type "custom sensor"

We need at least 8 virtual sensors:

# Omnik Temperature (Current Omnik System Temperature)
# DC Input Omnik PV1 (V)
# DC Input Omnik PV2 (V)
# DC Current Omnik PV1 (A)
# DC Current Omnik PV2 (A)
# Omnik AC Output (A)
# Omnik Total / Return (Watt / kWh)
# Omnik Current / Return (Watt / kWh)


Now that you have repeated the above steps 8 times:

  1. Go to "Devices"
  2. Search for 8 virtual devices (use the word "Omnik"in the search field).
  3. Make a note of the idx values for each of the virtual devices

Creating the Shell script used in cron

Now, using an editor such as "nano") create a shell script omnik.sh and put it in the "home/pi/domoticz/scripts/" folder. Enter the following lines and save the file:

#!/bin/bash
sudo python /home/pi/Omnik-Data-Logger/OmnikExport.py


Make the script executable: "sudo chmod +x /home/pi/domoticz/scripts/omnik.sh"

Installing Data-Logger

Instructions thanks to Woutrrr

  1. Install Python
  2. Git clone the source with git clone https://github.com/Woutrrr/Omnik-Data-Logger.git
  3. Copy the config-org.cfg to config.cfg
  4. Change the settings in config.cfg (add your serial# and IP of inverter). Behind 'enabled_plugins =' type: 'DomoticzOutput'. Also add the code shown below (don't forget to enter the IP address of the Domoticz server, and the port number which is usually 8080).
  5. Test your settings with python LiveStats.py, when succesfull you should see data from your inverter
[domoticz]
domoticz_host      = <IP OF DOMOTICZ MACHINE>
domoticz_port      = <Port of DOMOTICZ MACHINE>
domoticz_url       = json.htm

# Provide IDX here of the specific devices
idx_Temp      = idx
idx_PV1_U     = idx
idx_PV2_U     = idx
idx_PV1_A     = idx
idx_PV2_A     = idx
idx_AC_Output = idx
idx_E_Total   = idx
idx_E_Current = idx

DomoticzOutput.py

Create a file called DomoticzOutput.py in your /home/pi/Omnik-Data-Logger/outputs folder and insert the following code.

#!/usr/bin/python

import PluginLoader
import urllib
import urllib2
import ConfigParser

config = ConfigParser.RawConfigParser()

#change to correct folder.
config.read(['/home/pi/Omnik-Data-Logger/config-default.cfg', '/home/pi/Omnik-Data-Logger/config.cfg'])

domoticz_host    = config.get('domoticz','domoticz_host')
domoticz_port    = config.get('domoticz','domoticz_port')
domoticz_url     = config.get('domoticz','domoticz_url')

idx_Temp = config.get('domoticz','idx_Temp')
idx_PV1_U = config.get('domoticz','idx_PV1_U')
idx_PV2_U = config.get('domoticz','idx_PV2_U')
idx_PV1_A = config.get('domoticz','idx_PV1_A')
idx_PV2_A = config.get('domoticz','idx_PV2_A')
idx_AC_Output = config.get('domoticz','idx_AC_Output')
idx_E_Total = config.get('domoticz','idx_E_Total')
idx_E_Current = config.get('domoticz','idx_E_Current')
url = ("http://" + domoticz_host + ":" + domoticz_port + "/" + domoticz_url)

class DomoticzOutput(PluginLoader.Plugin):
    """Outputs the data from the Omnik inverter to Domoticz"""

    def process_message(self, msg):
        """Output the information from the inverter to Domoticz.

        Args:
            msg (InverterMsg.InverterMsg): Message to process
        """

        #Total AC energy generated by inverter in kWatt
        get_data = {
                'svalue': msg.e_total,
                'type': 'command',
                'param': 'udevice',
                'idx' : idx_E_Total
                }
        get_data_encoded = urllib.urlencode(get_data)
        full_url = url + '?' + get_data_encoded
        urllib.urlopen(full_url)

        #Current AC power and today's total power
        get_data = {
                'svalue': str(msg.p_ac(1)) + ';' + str(msg.e_total * 1000),
                'type': 'command',
                'param': 'udevice',
                'idx' : idx_E_Current,
                'nvalue': '0'
                }
        get_data_encoded = urllib.urlencode(get_data)
        full_url = url + '?' + get_data_encoded
        urllib.urlopen(full_url)

        #Current inverter temperature
        if msg.temperature < 300: #inverter displays temperature of +/- 6352 degrees Celcius when not generating power
                get_data = {
                        'svalue': msg.temperature,
                        'type': 'command',
                        'param': 'udevice',
                        'idx' : idx_Temp,
                        'nvalue': '0'
                        }
                get_data_encoded = urllib.urlencode(get_data)
                full_url = url + '?' + get_data_encoded
                urllib.urlopen(full_url)

        #String 1 voltage
        get_data = {
                'svalue': msg.v_pv(1),
                'type': 'command',
                'param': 'udevice',
                'idx' : idx_PV1_U,
                'nvalue': '0'
                }
        get_data_encoded = urllib.urlencode(get_data)
        full_url = url + '?' + get_data_encoded
        urllib.urlopen(full_url)

        #String 2 voltage
        get_data = {
                'svalue': msg.v_pv(2),
                'type': 'command',
                'param': 'udevice',
                'idx' : idx_PV2_U,
                'nvalue': '0'
                }
        get_data_encoded = urllib.urlencode(get_data)
        full_url = url + '?' + get_data_encoded
        urllib.urlopen(full_url)

        #String 1 ampere
        get_data = {
                'svalue': msg.i_pv(1),
                'type': 'command',
                'param': 'udevice',
                'idx' : idx_PV1_A,
                'nvalue': '0'
                }
        get_data_encoded = urllib.urlencode(get_data)
        full_url = url + '?' + get_data_encoded
        urllib.urlopen(full_url)

        #String 2 ampere
        get_data = {
                'svalue': msg.i_pv(2),
                'type': 'command',
                'param': 'udevice',
                'idx' : idx_PV2_A,
                'nvalue': '0'
                }
        get_data_encoded = urllib.urlencode(get_data)
        full_url = url + '?' + get_data_encoded
        urllib.urlopen(full_url)

        #Current AC current
        get_data = {
                'svalue': msg.i_ac(1),
                'type': 'command',
                'param': 'udevice',
                'idx' : idx_AC_Output,
                'nvalue': '0'
                }
        get_data_encoded = urllib.urlencode(get_data)
        full_url = url + '?' + get_data_encoded
        urllib.urlopen(full_url)

Create the Cronjob

Now all ingredients are available to read the data from the inverter and insert them into Domoticz.

  1. execute python OmnikExport.py
  2. Domoticz Inverter devices should now be filed with data.
  3. execute "crontab -e"
  4. add the following line "*/5 * * * * /home/pi/domoticz/scripts/omnik.sh 2>&1 >> /dev/null"
  5. exit crontab. Now everything should be working for you, the values will be read every five minutes and stored in the Domoticz virtual devices.