Domoticz logging the output of a Kostal Piko inverter

In this subforum you can show projects you have made, or you are busy with. Please create your own topic.

Moderator: leecollings

twosteps
Posts: 2
Joined: Thursday 23 August 2018 7:41
Target OS: -
Domoticz version:
Contact:

Re: Domoticz logging the output of a Kostal Piko inverter

Post by twosteps »

niki_lauda wrote: Sunday 09 September 2018 10:36
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.


You're right, I forgot to reply to the message.

Thanks for your answer. I think the problem is that my inverter is a piko 3.0 MP and the webinterface is different than for the other versions (piko MP 5.5 for instance)

Kostal Piko 3.0 MP web.png
Kostal Piko 3.0 MP web.png (55.19 KiB) Viewed 3174 times

I'm not an expert but it's like a "picture" (frame?) of the screen of the inverter instead of a simple table of values.

So I guess it's not possible to retrieve data from my inverter...?

Thanks
bjornp
Posts: 6
Joined: Saturday 29 June 2019 12:28
Target OS: Raspberry Pi / ODroid
Domoticz version:
Location: Netherlands
Contact:

Re: Domoticz logging the output of a Kostal Piko inverter

Post by bjornp »

I rewrote the script using the new dzVents format so you can change the interval (here it is 5 minutes).
It does not use a temporary file anymore and the counters are fetched even if the number of digits change.

Code: Select all

    ----------------------------------------------------------------------------------------------------------------
    -- Get the actual data from a Kostal Piko Inverter
    -- Uses Piko.py  http://sourceforge.net/projects/piko/files/
	--
    -- Example output of piko.py:
    -- Total energy    : 11651331 Wh
    -- Today energy    : 13104 Wh
	-- DC Power        : 1454 W
	-- AC Power        : 1342 W
	-- Efficiency      : 92.3%
    ----------------------------------------------------------------------------------------------------------


return {
    on      =   {   timer   = { "every 5 minutes"}},   
   
    execute = function(dz)            
        local inverter = dz.devices("DEVICE_NAME_IN_DOMOTICZ")
		local inverter_ip = "X.X.X.X"

        local f = assert(io.popen("python /home/pi/domoticz/scripts/piko.py --host=" .. inverter_ip .. " -p -i -d", 'r'))
        local s = assert(f:read('*a'))
        f:close()
        
        power=s:match('AC Power.-:(.-)W') -- in W
        energy=s:match('Total energy.-:(.-)Wh') -- in Wh

		inverter.updateElectricity(power,energy)
    end
}
niki_lauda
Posts: 115
Joined: Saturday 31 August 2013 14:48
Target OS: Raspberry Pi / ODroid
Domoticz version: beta
Location: Eindhoven (NL)
Contact:

Re: Domoticz logging the output of a Kostal Piko inverter

Post by niki_lauda »

Nice!
bjornp
Posts: 6
Joined: Saturday 29 June 2019 12:28
Target OS: Raspberry Pi / ODroid
Domoticz version:
Location: Netherlands
Contact:

Re: Domoticz logging the output of a Kostal Piko inverter

Post by bjornp »

I wrote a new DzVents based event so you do not need the extra Python script and (http)errors are handled better. The inverter needs current firmware version (>6.0?) so you can use the API to get JSON data directly.

Just fill in the inverter IP and the device name.

Code: Select all

return {
	on = {
		timer = {
			'every 5 minutes'
		},
		httpResponses = {
			'trigger' -- must match with the callback passed to the openURL command
		}
	},
	execute = function(domoticz, item)

		if (item.isTimer) then
			domoticz.openURL({
				url = 'http://INVERTER-IP-ADDRESS/api/dxs.json?dxsEntries=67109120&dxsEntries=251658753', -- 67109120 = current power W and 251658753 = lifetime total kWh
				method = 'GET',
				callback = 'trigger',
			})
		end

		if (item.isHTTPResponse) then
            
			if (item.statusCode == 200) then
			    local json = domoticz.utils.fromJSON(item.data) -- Convert to JSON because Piko does not specify it as json in header
			    if json.dxsEntries[1]['dxsId'] == 67109120 and json.dxsEntries[2]['dxsId'] == 251658753 then
			        local current = json.dxsEntries[1]['value']
			        local lifetime = json.dxsEntries[2]['value']
			        print('Piko - Current power: ' .. domoticz.utils.round(current,0) .. ' W | Lifetime total: ' .. domoticz.utils.round(lifetime,3) .. ' kWh')
			        local inverter = domoticz.devices("Kostal PIKO Virtual device name")
			        inverter.updateElectricity(current,(domoticz.utils.round(lifetime,3)*1000)) -- lifetime needs to be in Wh (not kWh)
		        else
		            print('Entries not found or incorrect entries found in table') 
			    end

			else
				domoticz.log('There was a problem handling the request', domoticz.LOG_ERROR)
				domoticz.log(item, domoticz.LOG_ERROR)
			end

		end

	end
}
Bruno67
Posts: 1
Joined: Wednesday 17 June 2020 19:29
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: Domoticz logging the output of a Kostal Piko inverter

Post by Bruno67 »

Hi Bjornp,

Thanks for sharing this!
I'm new to DzVents and also to LUA so forgive my ignorance :)
I tried out your script replacing the URL and device name but I get an error message in the log:

2020-06-17 19:00:10.463 Status: dzVents: Info: Handling httpResponse-events for: "trigger
2020-06-17 19:00:10.463 Status: dzVents: Info: ------ Start internal script: Kostal 1: HTTPResponse: "trigger"
2020-06-17 19:00:10.463 Status: dzVents: Error (2.4.19): There was a problem handling the request
2020-06-17 19:00:10.464 Status: dzVents: Error (2.4.19): {["isTimer"]=false, ["ok"]=false, ["data"]="", ["isDevice"]=false, ["isSecurity"]=false, ["isGroup"]=false, ["trigger"]="trigger", ["isJSON"]=false, ["isScene"]=false, ["statusText"]="Timeout was reached", ["statusCode"]=28, ["callback"]="trigger", ["baseType"]="httpResponse", ["protocol"]="HTTP/1.1", ["isVariable"]=false, ["headers"]={}, ["isHTTPResponse"]=true, ["_contentType"]=""}
2020-06-17 19:00:10.464 Status: dzVents: Info: ------ Finished Kostal 1
2020-06-17 19:00:10.349 Error: Error opening url: http://192.168.0.50/api/dxs.json?dxsEnt ... =251658753

Any idea of what I did wrong?

Thanks

Below the script:
return {
on = {
timer = {
'every 5 minutes'
},
httpResponses = {
'trigger' -- must match with the callback passed to the openURL command
}
},
execute = function(domoticz, item)

if (item.isTimer) then
domoticz.openURL({
url = 'http://192.168.0.50/api/dxs.json?dxsEnt ... =251658753', -- 67109120 = current power W and 251658753 = lifetime total kWh
method = 'GET',
callback = 'trigger',
})
end

if (item.isHTTPResponse) then

if (item.statusCode == 200) then
local json = domoticz.utils.fromJSON(item.data) -- Convert to JSON because Piko does not specify it as json in header
if json.dxsEntries[1]['dxsId'] == 67109120 and json.dxsEntries[2]['dxsId'] == 251658753 then
local current = json.dxsEntries[1]['value']
local lifetime = json.dxsEntries[2]['value']
print('Piko - Current power: ' .. domoticz.utils.round(current,0) .. ' W | Lifetime total: ' .. domoticz.utils.round(lifetime,3) .. ' kWh')
local inverter = domoticz.devices('Kostal')
inverter.updateElectricity(current,(domoticz.utils.round(lifetime,3)*1000)) -- lifetime needs to be in Wh (not kWh)
else
print('Entries not found or incorrect entries found in table')
end

else
domoticz.log('There was a problem handling the request', domoticz.LOG_ERROR)
domoticz.log(item, domoticz.LOG_ERROR)
end

end

end
WimTh
Posts: 4
Joined: Sunday 31 January 2021 15:26
Target OS: -
Domoticz version:
Contact:

Re: Domoticz logging the output of a Kostal Piko inverter

Post by WimTh »

Hi guys,

Thanks for sharing all of this information. I've been trying to get this working on my Domoticz, but to no avail.
I have the used the LUA and Python scripts from the start of this topic (the downloadable py script) and they give no error in my command line.

My problem is that I have no clue on how to get the Piko device in my Domoticz interface. Is there a tutorial which starts by adding the Piko device to domoticz? After that I should be able to use the scripts in this topic, I guess?

Best regards and thanks in advance!

Wim
niki_lauda
Posts: 115
Joined: Saturday 31 August 2013 14:48
Target OS: Raspberry Pi / ODroid
Domoticz version: beta
Location: Eindhoven (NL)
Contact:

Re: Domoticz logging the output of a Kostal Piko inverter

Post by niki_lauda »

WimTh wrote: Sunday 31 January 2021 15:34 Hi guys,

Thanks for sharing all of this information. I've been trying to get this working on my Domoticz, but to no avail.
I have the used the LUA and Python scripts from the start of this topic (the downloadable py script) and they give no error in my command line.

My problem is that I have no clue on how to get the Piko device in my Domoticz interface. Is there a tutorial which starts by adding the Piko device to domoticz? After that I should be able to use the scripts in this topic, I guess?

Best regards and thanks in advance!

Wim
Which Piko do you have?
Mine is an PIKO 3.6 https://www.kostal-solar-electric.com/e ... oad/archiv#
WimTh
Posts: 4
Joined: Sunday 31 January 2021 15:26
Target OS: -
Domoticz version:
Contact:

Re: Domoticz logging the output of a Kostal Piko inverter

Post by WimTh »

niki_lauda wrote: Sunday 31 January 2021 19:05
WimTh wrote: Sunday 31 January 2021 15:34 Hi guys,

Thanks for sharing all of this information. I've been trying to get this working on my Domoticz, but to no avail.
I have the used the LUA and Python scripts from the start of this topic (the downloadable py script) and they give no error in my command line.

My problem is that I have no clue on how to get the Piko device in my Domoticz interface. Is there a tutorial which starts by adding the Piko device to domoticz? After that I should be able to use the scripts in this topic, I guess?

Best regards and thanks in advance!

Wim
Which Piko do you have?
Mine is an PIKO 3.6 https://www.kostal-solar-electric.com/e ... oad/archiv#
I have a Kostal Piko 4.2 MP. https://www.dutchsolarsystems.com/kosta ... iko-4-2-mp
Regards, Wim
niki_lauda
Posts: 115
Joined: Saturday 31 August 2013 14:48
Target OS: Raspberry Pi / ODroid
Domoticz version: beta
Location: Eindhoven (NL)
Contact:

Re: Domoticz logging the output of a Kostal Piko inverter

Post by niki_lauda »

WimTh wrote: Sunday 31 January 2021 20:13
niki_lauda wrote: Sunday 31 January 2021 19:05
WimTh wrote: Sunday 31 January 2021 15:34 Hi guys,

Thanks for sharing all of this information. I've been trying to get this working on my Domoticz, but to no avail.
I have the used the LUA and Python scripts from the start of this topic (the downloadable py script) and they give no error in my command line.

My problem is that I have no clue on how to get the Piko device in my Domoticz interface. Is there a tutorial which starts by adding the Piko device to domoticz? After that I should be able to use the scripts in this topic, I guess?

Best regards and thanks in advance!

Wim
Which Piko do you have?
Mine is an PIKO 3.6 https://www.kostal-solar-electric.com/e ... oad/archiv#
I have a Kostal Piko 4.2 MP. https://www.dutchsolarsystems.com/kosta ... iko-4-2-mp
Regards, Wim
Hoi Wim
Make a new dummy device zonnepanelen type elektra

I think with this inverter you should use the dzvents script.

Change the following lines
url = 'http://INVERTER-IP-ADDRESS/api/dxs.json ... =251658753', -- 67109120 = current power W and 251658753 = lifetime total kWh

local inverter = domoticz.devices("Kostal PIKO Virtual device name")

Maybe then it works
Hans
WimTh
Posts: 4
Joined: Sunday 31 January 2021 15:26
Target OS: -
Domoticz version:
Contact:

Re: Domoticz logging the output of a Kostal Piko inverter

Post by WimTh »

niki_lauda wrote: Sunday 31 January 2021 20:40
WimTh wrote: Sunday 31 January 2021 20:13
niki_lauda wrote: Sunday 31 January 2021 19:05
Which Piko do you have?
Mine is an PIKO 3.6 https://www.kostal-solar-electric.com/e ... oad/archiv#
I have a Kostal Piko 4.2 MP. https://www.dutchsolarsystems.com/kosta ... iko-4-2-mp
Regards, Wim
Hoi Wim
Make a new dummy device zonnepanelen type elektra

I think with this inverter you should use the dzvents script.

Change the following lines
url = 'http://INVERTER-IP-ADDRESS/api/dxs.json ... =251658753', -- 67109120 = current power W and 251658753 = lifetime total kWh

local inverter = domoticz.devices("Kostal PIKO Virtual device name")

Maybe then it works
Hans
Hello Hans,
Can you send me a link to the right script?
Kind Regards Wim
niki_lauda
Posts: 115
Joined: Saturday 31 August 2013 14:48
Target OS: Raspberry Pi / ODroid
Domoticz version: beta
Location: Eindhoven (NL)
Contact:

Re: Domoticz logging the output of a Kostal Piko inverter

Post by niki_lauda »

I use this script. It makes use of home/pi/domoticz/scripts/piko.py see attachement

Code: Select all

  ----------------------------------------------------------------------------------------------------------------
    -- Get the actual data from a Kostal Piko Inverter
    -- Uses Piko.py  http://sourceforge.net/projects/piko/files/
	--
    -- Example output of piko.py:
    -- Total energy    : 11651331 Wh
    -- Today energy    : 13104 Wh
	-- DC Power        : 1454 W
	-- AC Power        : 1342 W
	-- Efficiency      : 92.3%
    ----------------------------------------------------------------------------------------------------------


return {
    on      =   {   timer   = { "every 10 minutes"}},   
    execute = function(dz)            
        local inverter = dz.devices("KostalDZ")
        --- local invtotal = dz.devices("Zonneenergie")
		local inverter_ip = "10.0.0.2"

        local f = assert(io.popen("/usr/bin/python2.7 /home/pi/domoticz/scripts/piko.py --host=10.0.0.2 -p -i -d", 'r'))
        local s = assert(f:read('*a'))
        f:close()
        --print("Device is On")
        power=s:match('AC Power.-:(.-)W') -- in W
        --print(s)
        energy=s:match('Today energy.-:(.-)Wh') -- in Wh
        total =s:match('Total energy.-:(.-)Wh') -- in Wh
       -- print (power)
       -- print (total)
        if dz.time.matchesRule("between sunrise and sunset") then
		    inverter.updateElectricity(power+1,energy)
		-- invtotal.updateElectricity(total)
		end
    end
}
Attachments
piko.py.txt
(21.3 KiB) Downloaded 85 times
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest