Page 1 of 2

Domoticz logging the output of a Kostal Piko inverter

Posted: Sunday 28 June 2015 21:26
by niki_lauda
Hi
I made a lua script that logs the output from my solar panels. The actual output I use as a kind lux meter to switch on lights.

It makes use off a Python script piko.py. You can find it here. http://sourceforge.net/projects/piko/files/

I have one problem to solve. Some string manupilation.
And a question how can I get the total energy in Domoticz. Currently only the Current watts and the energy generated today is shown.

By the way if I look in the log at the chart for today it shows the same data as yesterday. Tomorrow it shows the correct data.

Here is it.

Code: Select all

    ----------------------------------------------------------------------------------------------------------------
    -- Get the actual production data from a Kostal Piko Inverter
    -- Base lua used IsItGonnaRain 
		--
    -- Uses Piko.py  http://sourceforge.net/projects/piko/files/
    -- 
    -- Written in LUA by Hans Roijmans
    -- summer 2015
    -- 26-06-2015 v0.1 Initial release
    --  
    -- Todo: routine to get the data between ':' and 'W(h)'
    -- Output of tempfilename = '/var/tmp/piko.tmp' 
    -- Total energy    : 11651331 Wh
    -- Today energy    : 13104 Wh
		-- DC Power        : 1454 W
		-- AC Power        : 1342 W
		-- Efficiency      : 92.3%
    ----------------------------------------------------------------------------------------------------------

    ----------------------------------------------------------------------------------------------------------
    -- Domoticz IDX and names of the needed device
    ----------------------------------------------------------------------------------------------------------
    local PIKOIDX = 1121
    ----------------------------------------------------------------------------------------------------------
    -- Script parameter
    ----------------------------------------------------------------------------------------------------------
    tempfilename = '/var/tmp/piko.tmp' 

    ----------------------------------------------------------------------------------------------------------
    -- CommandArray
    ----------------------------------------------------------------------------------------------------------
    commandArray = {}
       read = os.execute('python /home/pi/domoticz/scripts/piko.py --host=10.0.0.2 -p -i -d > /var/tmp/piko.tmp') -- 
       file = io.open(tempfilename, "r")
       -- Read lines.
       line = file:read("*line")
    -- Total energy    : 11651331 Wh
       total=string.sub(tostring(line),18,27)
       line = file:read("*line")
    -- Today energy    : 13104 Wh
       today=string.sub(tostring(line),18,23)
       line = file:read("*line")
    -- DC Power        : 1454 W
       nowdc=string.sub(tostring(line),18,22)
       line = file:read("*line")
    -- AC Power        : 1342 W
       nowac=string.sub(tostring(line),18,22)
       file:close()       
       commandArray = {['UpdateDevice'] = PIKOIDX .. '|0|' .. nowac .. ';' .. today }
    return commandArray

Re: Domoticz logging the output of a Kostal Piko inverter

Posted: Tuesday 29 March 2016 10:20
by luusje
Hi,

Was just browsing the forum. Did you manage to get the Piko logging fully working? I have one also and would be nice to add to Domoticz.


Greetz


Verzonden vanaf mijn iPhone met Tapatalk

Re: Domoticz logging the output of a Kostal Piko inverter

Posted: Tuesday 29 March 2016 19:10
by niki_lauda
1.jpg
1.jpg (50.23 KiB) Viewed 8356 times
Ja
Yes

Re: Domoticz logging the output of a Kostal Piko inverter

Posted: Friday 05 May 2017 12:42
by sejonr
Hi

I tryed to implement this code but i cant get any data from Kostal Inverter 4.2 that i have. I have stored the piko.py in right place and did exactlly as decribed in code above but i get nothing.

I realy need help!!!! I have tryed for several houers. This is my first LUA code.

Re: Domoticz logging the output of a Kostal Piko inverter

Posted: Friday 05 May 2017 12:42
by sejonr
Of cource i changed IP adress

Re: Domoticz logging the output of a Kostal Piko inverter

Posted: Friday 05 May 2017 13:52
by niki_lauda
Hi
Do you run domitcz on a raspberry Pi?

What happens if you run from the commandline
python /home/pi/domoticz/scripts/piko.py --host=10.0.0.2 -p -i -d > /var/tmp/piko.tmp

Re: Domoticz logging the output of a Kostal Piko inverter

Posted: Friday 05 May 2017 13:52
by niki_lauda
on a Pi look in /var/temp

Re: Domoticz logging the output of a Kostal Piko inverter

Posted: Friday 05 May 2017 22:42
by sejonr
Yes i got the file but i got this message when i run from commandline what is this? Do i need a new file?

Traceback (most recent call last):
File "Piko.py", line 40, in <module>
import MySQLdb as mdb
ImportError: No module named MySQLdb

Re: Domoticz logging the output of a Kostal Piko inverter

Posted: Saturday 06 May 2017 22:22
by niki_lauda
I think in your case this is the solution.
http://stackoverflow.com/questions/3504 ... ed-mysqldb

First ensure you have a python mysql driver installed:
sudo pip install pymysql

Re: Domoticz logging the output of a Kostal Piko inverter

Posted: Saturday 06 May 2017 22:31
by niki_lauda
sejonr wrote:Yes i got the file but i got this message when i run from commandline what is this? Do i need a new file?

Traceback (most recent call last):
File "Piko.py", line 40, in <module>
import MySQLdb as mdb
ImportError: No module named MySQLdb
I think in your case this is the solution.
http://stackoverflow.com/questions/3504 ... ed-mysqldb

First ensure you have a python mysql driver installed:
sudo pip install pymysql
OR
apt-get install python-mysqldb

Re: Domoticz logging the output of a Kostal Piko inverter

Posted: Tuesday 16 May 2017 13:16
by sejonr
Thank you for your help :) :) Everything works now but not kwh.

The Kwh shows the day after (for example sunday kwh is shown on monday) and i cant see kwh per hour .??

Re: Domoticz logging the output of a Kostal Piko inverter

Posted: Tuesday 16 May 2017 21:16
by niki_lauda
Where is your luascript stored?
Mine is stored in /home/pi/domoticz/scripts/lua and is named script_time_kostal.lua so it runs every minute.

2017-05-16 21:09:02.655 EventSystem: Script event triggered: /home/pi/domoticz/scripts/lua/script_time_kostal.lua
2017-05-16 21:10:04.107 EventSystem: Script event triggered: /home/pi/domoticz/scripts/lua/script_time_kostal.lua
2017-05-16 21:11:01.995 EventSystem: Script event triggered: /home/pi/domoticz/scripts/lua/script_time_kostal.lua
2017-05-16 21:12:02.227 EventSystem: Script event triggered: /home/pi/domoticz/scripts/lua/script_time_kostal.lua

You could try to upload your daily yield to Pvoutput http://www.domoticz.com/wiki/Upload_ene ... o_PVoutput

http://www.domoticz.com/wiki/Upload_ene ... o_PVoutput

Re: Domoticz logging the output of a Kostal Piko inverter

Posted: Wednesday 17 May 2017 8:54
by sejonr
My Lua is stored under the right meny - settings / more settings/eventhandling

and i selected Lua in stead of Blockly and the lua script is on time (per min)

Re: Domoticz logging the output of a Kostal Piko inverter

Posted: Wednesday 17 May 2017 19:39
by niki_lauda
try to store the script on the sd card. And name it script_time_kostal.lua

Re: Domoticz logging the output of a Kostal Piko inverter

Posted: Thursday 18 May 2017 18:26
by niki_lauda
sejonr wrote:My Lua is stored under the right meny - settings / more settings/eventhandling

and i selected Lua in stead of Blockly and the lua script is on time (per min)
Did you set the time option under the Lua option in settings / more settings/eventhandling

Re: Domoticz logging the output of a Kostal Piko inverter

Posted: Wednesday 11 October 2017 9:08
by sejonr
niki_lauda wrote: Tuesday 29 March 2016 19:10 1.jpg
Ja
Yes
Hi niki

How did you do?? I copyed your lua but get the same problem as you.

Thank you for help :D

Re: Domoticz logging the output of a Kostal Piko inverter

Posted: Sunday 31 December 2017 17:32
by jonathan12
What am I doing wrong? The temp file is staying empty.

Error in de log:

2017-12-31 17:31:00.300 Error: EventSystem: in /home/pi/domoticz/scripts/lua/script_time_kostal.lua: /home/pi/domoticz/scripts/lua/script_time_kostal.lua:36: attempt to call global 'fileread' (a nil value)

Re: Domoticz logging the output of a Kostal Piko inverter

Posted: Tuesday 15 May 2018 21:01
by niki_lauda
jonathan12 wrote: Sunday 31 December 2017 17:32 What am I doing wrong? The temp file is staying empty.

Error in de log:

2017-12-31 17:31:00.300 Error: EventSystem: in /home/pi/domoticz/scripts/lua/script_time_kostal.lua: /home/pi/domoticz/scripts/lua/script_time_kostal.lua:36: attempt to call global 'fileread' (a nil value)
Nothing an updated script is attached

Re: Domoticz logging the output of a Kostal Piko inverter

Posted: Thursday 23 August 2018 7:48
by twosteps
Hi all,

I have a noob question regarding the connection to the Kostal Inverter:

On my Piko device, I have both Ethernet and RS485 (RJ45 both) connections.

To retrieve the data using the script, do I have to connect to RS485 or ethernet..?

I have a rapberry Pi 3. If RS485 is needed, I guess I need to connect to my Pi using a RS485 card, right?

Many thanks for your help and again sorry for this basic question

Herve

Re: Domoticz logging the output of a Kostal Piko inverter

Posted: Sunday 09 September 2018 10:36
by niki_lauda
twosteps wrote: Thursday 23 August 2018 7:48 Hi all,

I have a noob question regarding the connection to the Kostal Inverter:

On my Piko device, I have both Ethernet and RS485 (RJ45 both) connections.

To retrieve the data using the script, do I have to connect to RS485 or ethernet..?

I have a rapberry Pi 3. If RS485 is needed, I guess I need to connect to my Pi using a RS485 card, right?

Many thanks for your help and again sorry for this basic question

Herve
If you reply to an message you will get an bnotification. I accendentally stumbled over your message.

I connected the PIKO via an Ethernet cable.
Don't excuse yourself for asking a question. Only by asking an question you can learn.