openURL to PVoutput  [Solved]

Easy to use, 100% Lua-based event scripting framework.

Moderator: leecollings

Post Reply
roblom
Posts: 408
Joined: Wednesday 26 February 2014 15:28
Target OS: Raspberry Pi / ODroid
Domoticz version:
Location: the Netherlands
Contact:

openURL to PVoutput

Post by roblom »

I'm rewriting my pvoutput script from lua to dzVents but I ran into a problem.

Code: Select all

			domoticz.openURL({
				url = PVoutputURL,
				method = 'POST',
				headers = {
					['X-Pvoutput-Apikey']	= PVoutputApi,
					['X-Pvoutput-SystemId']	= PVoutputSystemID
				},
				callback = 'UploadToPVoutput',
				postData = {
					['d']		= PostDate,
					['t']		= PostTime,
					['v1']		= EnergyGeneration,
					['v2']		= PowerGeneration,
					['v3']		= EnergyConsumption,
					['v4']		= PowerConsumption,
					['v5']		= CurrentTemp,
					['v6']		= Voltage,
					['c1']		= c1,
					['n']		= n,
					['delay']	= Delay,
					['v7']		= WaterConsumption,
					['v8']		= InverterFrequency,
					['v11']		= InverterTemp,
					['v12']		= GasConsumption
				},
			})
where

Code: Select all

			local PostDate			=	os.date("%Y%m%d")
			local PostTime			= 	os.date("%H:%M")
The log says

Code: Select all

OpenURL: post data = {"c1":1,"d":"20190520","delay":0,"n":0,"t":"23:55","v1":3700,"v11":25,"v12":7346.107,"v2":0,"v3":14067,"v4":380,"v5":13.9,"v6":239.9,"v7":866441.799,"v8":50.06}
OpenURL: headers = {["X-Pvoutput-SystemId"]="xxxxx", ["X-Pvoutput-Apikey"]="xxxxxxx"}

Bad request 400: Invalid Time [null]
So there is a time send (as "t":"23:55") but it looks like there is something wrong with it but can't figure out what. Somebody an idea?

If I do

Code: Select all

curl -d "d=20190520" -d "t=23:55" -d "v1=0" -d "v2=0" -d "v3=100" -H "X-Pvoutput-Apikey: xxxxxxxxx" -H "X-Pvoutput-SystemId: xxxx" https://pvoutput.org/service/r2/addstatus.jsp
then the data is uploaded successfully
roblom
Posts: 408
Joined: Wednesday 26 February 2014 15:28
Target OS: Raspberry Pi / ODroid
Domoticz version:
Location: the Netherlands
Contact:

Re: openURL to PVoutput

Post by roblom »

In the mean time I found out that

Code: Select all

			PVoutputURLtotal = 	PVoutputURL ..  
								"?d=" .. os.date("%Y%m%d") .. 
								"&t=" .. os.date("%H:%M") .. 
								"&v1=" .. EnergyGeneration .. 
								"&v2=" .. PowerGeneration .. 
								"&v3=" .. EnergyConsumption .. 
								"&v4=" .. PowerConsumption .. 
								"&v5=" .. CurrentTemp .. 
								"&v6=" .. Voltage .. 
								"&c1=" .. c1 .. 
								"&n=" .. n .. 
								"&delay=" .. Delay .. 
								"&v7=" .. WaterConsumption .. 
								"&v8=" .. InverterFrequency .. 
								"&v11=".. InverterTemp .. 
								"&v12=" .. GasConsumption
			
			domoticz.log(' ---- PVoutputURLtotal ' .. PVoutputURLtotal, domoticz.LOG_INFO)
			
			domoticz.openURL({
				url = PVoutputURLtotal,
				method = 'POST',
				headers = {
					['X-Pvoutput-Apikey']	= PVoutputApi,
					['X-Pvoutput-SystemId']	= PVoutputSystemID
				},
				callback = 'UploadToPVoutput',
			})
Does work, so it seems like the "postdata" isn't accepted.
User avatar
waaren
Posts: 6028
Joined: Tuesday 03 January 2017 14:18
Target OS: Linux
Domoticz version: Beta
Location: Netherlands
Contact:

Re: openURL to PVoutput

Post by waaren »

roblom wrote: Tuesday 21 May 2019 1:25 Bad request 400: Invalid Time [null][/code]
So there is a time send (as "t":"23:55") but it looks like there is something wrong with it but can't figure out what. Somebody an idea?
What is the result if you try

Code: Select all

['t']		= domoticz.utils.urlEncode(PostTime),
?
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
roblom
Posts: 408
Joined: Wednesday 26 February 2014 15:28
Target OS: Raspberry Pi / ODroid
Domoticz version:
Location: the Netherlands
Contact:

Re: openURL to PVoutput

Post by roblom »

waaren wrote: Tuesday 21 May 2019 2:55
roblom wrote: Tuesday 21 May 2019 1:25 Bad request 400: Invalid Time [null][/code]
So there is a time send (as "t":"23:55") but it looks like there is something wrong with it but can't figure out what. Somebody an idea?
What is the result if you try

Code: Select all

['t']		= domoticz.utils.urlEncode(PostTime),
?
I tried

Code: Select all

[ 't'] = '23:55'
but that also didn't work.
The problem isn't related to the time value but it looks like it won't accept the "postData" values. When I generate an URL with all the values in (see my post above) then it works. Is this because I use the wrong postData format or something? (remember that i'm no programmer so I have no clue how to be able to determine what "format" the PVoutput wants to have. Nothing is mentioned about this in the API documentation.)
User avatar
waaren
Posts: 6028
Joined: Tuesday 03 January 2017 14:18
Target OS: Linux
Domoticz version: Beta
Location: Netherlands
Contact:

Re: openURL to PVoutput

Post by waaren »

If I try to do the same from the CLI using curl POST,

Code: Select all

  curl -v -d '{"d":"20190521","t":"11:01","v1":2065,"v5":13.3,"v6":241.2}' \
   -H "Content-Type: application/json"  \
   -H "X-Pvoutput-Apikey: validcode" \
   -H "X-Pvoutput-SystemId: validid" \
   -X POST \
   https://pvoutput.org/service/r2/addstatus.jsp
I get the same error message.

Code: Select all

*   Trying 45.56.66.169...
* TCP_NODELAY set
* Connected to pvoutput.org (45.56.66.169) port 443 (#0)
* ALPN, offering h2
* ALPN, offering http/1.1
* Cipher selection: ALL:!EXPORT:!EXPORT40:!EXPORT56:!aNULL:!LOW:!RC4:@STRENGTH
* successfully set certificate verify locations:
*   CAfile: /etc/ssl/certs/ca-certificates.crt
  CApath: /etc/ssl/certs
* TLSv1.2 (OUT), TLS header, Certificate Status (22):
* TLSv1.2 (OUT), TLS handshake, Client hello (1):
* TLSv1.2 (IN), TLS handshake, Server hello (2):
* TLSv1.2 (IN), TLS handshake, Certificate (11):
* TLSv1.2 (IN), TLS handshake, Server key exchange (12):
* TLSv1.2 (IN), TLS handshake, Server finished (14):
* TLSv1.2 (OUT), TLS handshake, Client key exchange (16):
* TLSv1.2 (OUT), TLS change cipher, Client hello (1):
* TLSv1.2 (OUT), TLS handshake, Finished (20):
* TLSv1.2 (IN), TLS change cipher, Client hello (1):
* TLSv1.2 (IN), TLS handshake, Finished (20):
* SSL connection using TLSv1.2 / ECDHE-RSA-AES256-GCM-SHA384
* ALPN, server did not agree to a protocol
* Server certificate:
*  subject: OU=Domain Control Validated; OU=PositiveSSL; CN=pvoutput.org
*  start date: Dec 21 00:00:00 2017 GMT
*  expire date: Feb  4 23:59:59 2021 GMT
*  subjectAltName: host "pvoutput.org" matched cert's "pvoutput.org"
*  issuer: C=GB; ST=Greater Manchester; L=Salford; O=COMODO CA Limited; CN=COMODO RSA Domain Validation Secure Server CA
*  SSL certificate verify ok.
> POST /service/r2/addstatus.jsp HTTP/1.1
> Host: pvoutput.org
> User-Agent: curl/7.52.1
> Accept: */*
> Content-Type: application/json
> X-Pvoutput-Apikey: valid Apikey
> X-Pvoutput-SystemId: validID
> Content-Length: 59
>
* upload completely sent off: 59 out of 59 bytes
< HTTP/1.1 400 Bad Request
< Date: Tue, 21 May 2019 12:01:54 GMT
< Set-Cookie: JSESSIONID=validkey;Path=/
< Expires: Thu, 01 Jan 1970 00:00:00 GMT
< Content-Type: text/plain;charset=ISO-8859-1
< Connection: close
< Server: Jetty(7.6.17.v20150415)
< Strict-Transport-Security: max-age=15768000
<
* TLSv1.2 (IN), TLS alert, Client hello (1):
* Curl_http_done: called premature == 0
* Closing connection 0
* TLSv1.2 (OUT), TLS alert, Client hello (1):
Bad request 400: Invalid Time [null]
My understanding is that pvoutput does no longer accept calls to http
  • set by Strict-Transport-Security: max-age=15768000
but I do not understand why I receive this message as I clearly (try to) call https
Sending the same data via GET does work but I want to understand what is going wrong here.

I posted this also on the pvoutput forum
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
User avatar
waaren
Posts: 6028
Joined: Tuesday 03 January 2017 14:18
Target OS: Linux
Domoticz version: Beta
Location: Netherlands
Contact:

Re: openURL to PVoutput

Post by waaren »

roblom wrote: Tuesday 21 May 2019 11:36 Nothing is mentioned about this in the API documentation.)
I found this helpful document
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
Toulon7559
Posts: 859
Joined: Sunday 23 February 2014 17:56
Target OS: Raspberry Pi / ODroid
Domoticz version: <2025
Location: Hengelo(Ov)/NL
Contact:

Re: openURL to PVoutput

Post by Toulon7559 »

The documentation of PVOutput indicates that https is required, but still http is accepted.
Perhaps first try to make your new script running with http, and then switch to https?
Set1 = RPI-Zero+RFXCom433+S0PCM+Shield for BMP180/DS18B20/RS485+DDS238-1ZNs
Set2 = RPI-3A++RFLinkGTW+ESP8266s+PWS_WS7000
Common = KAKUs+3*PVLogger+PWS_TFA_Nexus
plus series of 'satellites' for dedicated interfacing, monitoring & control.
User avatar
waaren
Posts: 6028
Joined: Tuesday 03 January 2017 14:18
Target OS: Linux
Domoticz version: Beta
Location: Netherlands
Contact:

Re: openURL to PVoutput

Post by waaren »

roblom wrote: Tuesday 21 May 2019 11:36 Bad request 400: Invalid Time [null][/code]
Got an answer on the PVOutput forum that the 'addstatus' site does not accept JSON.

with that in mind I converted the postdata to a string and that does the trick.

Code: Select all

local stringVar = 'PVOutput'

return {
            on =    { 
                        timer = { 'every 10 minutes'},
                        httpResponses = { stringVar },
                       },
 
       logging =    {   
                        level   =   domoticz.LOG_DEBUG,
                        marker  =   "pvOutput" 
                    },    

    execute = function(dz, item)
            
        local function post2PVOutput(PVSettings, postData)
            dz.openURL({
                url = PVSettings.url,
                method = 'POST',
                headers = {
                    ['X-Pvoutput-Apikey'] = PVSettings.api,
                    ['X-Pvoutput-SystemId'] = PVSettings.id
                },
                callback = stringVar,
                postData = postData
            })
        end
        
        local function makepostData()
            local postdDataAsString = 
            'd=' .. os.date("%Y%m%d") ..
            '&t=' .. os.date("%H:%M") .. 
            '&v1=' .. dz.devices('Youless').powerYield ..
            '&v5=' ..  dz.devices('myTemperature').temperature .. 
            '&v6=' .. dz.devices('myVoltage').voltage 
            
            --[[ 
            '&v2= .. PowerGeneration
            '&v3= ..  EnergyConsumption
            '&v4= ..  PowerConsumption
            '&c1= ..  c1
            '&n= .. n
                                            Donation mode only parms
            '&delay=' .. Delay
            '&v7=' .. WaterConsumption
            '&v8=' .. InverterFrequency
            '&v11=' .. InverterTemp
            '&v12=' .. GasConsumption
            ]] -- 
            return postdDataAsString
        end

        if item.isHTTPResponse then
            dz.log("Return from PVOutput \n" .. item.data,dz.LOG_DEBUG)
        else
            
            PVSettings = 
            {
            url = 'HTTPS://pvoutput.org/service/r2/addstatus.jsp',
            api = dz.variables('PVoutput_API').value,
            id  = dz.variables('PVoutput_ID').value,
            }
            
            post2PVOutput(PVSettings, makepostData())
        end
    end
}
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
roblom
Posts: 408
Joined: Wednesday 26 February 2014 15:28
Target OS: Raspberry Pi / ODroid
Domoticz version:
Location: the Netherlands
Contact:

Re: openURL to PVoutput

Post by roblom »

Interesting!

But I try to understand it.
If there is no httpresonse there are some variables set in PVSettings
The makepostData generates a post data string and puts it in postdDataAsString

But in the function post2PVOutput you use PVSettings and postData.

Code: Select all

postData = postData
But where is the postData coming from? Do I understand it right that the code below

Code: Select all

post2PVOutput(PVSettings, makepostData())
- collects the PVSettings and put it in the PVSettings of the post2PVOutput function
- collects the makepostData sing the makepostData function and put it in the postData of the post2PVOutput function
User avatar
waaren
Posts: 6028
Joined: Tuesday 03 January 2017 14:18
Target OS: Linux
Domoticz version: Beta
Location: Netherlands
Contact:

Re: openURL to PVoutput

Post by waaren »

roblom wrote: Tuesday 21 May 2019 21:47 If there is no httpresonse there are some variables set in PVSettings
The makepostData generates a post data string and puts it in postdDataAsString
Correct but postdDataAsString is declared local within the function so this variable does not live outside the function. The return of the function is the value of that variable.
But in the function post2PVOutput you use PVSettings and postData.

Code: Select all

postData = postData
The table PVSettings and the string postData are passed to the function post2PVOutput as parms.
But where is the postData coming from? Do I understand it right that the code below

Code: Select all

post2PVOutput(PVSettings, makepostData())
- collects the PVSettings and put it in the PVSettings of the post2PVOutput function
- collects the makepostData sing the makepostData function and put it in the postData of the post2PVOutput function
I realize that it is not very easy to understand if you are not used to Lua functions.
Let me try to explain with this small code snippet. Copy this in an editor on the CLI and save as function.lua
then type lua < function.lua

If lua is not yet installed on your system then do this first

Code: Select all

apt install lua5.2

Code: Select all

function test(parm)
        print ("In function test; printing the value of parm ==>> " .. parm)
        return (parm + 1)
end

counter = 1
for i=1,5 do
        print ("In main code; printing value of counter ==>> " .. counter)
        counter = test(counter * 2) -- new value of counter will be set to the return value of function test
end
Or peek here
Spoiler: show
In main code; printing value of counter ==>> 1
In function test; printing the value of parm ==>> 2
In main code; printing value of counter ==>> 3
In function test; printing the value of parm ==>> 6
In main code; printing value of counter ==>> 7
In function test; printing the value of parm ==>> 14
In main code; printing value of counter ==>> 15
In function test; printing the value of parm ==>> 30
In main code; printing value of counter ==>> 31
In function test; printing the value of parm ==>> 62
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
roblom
Posts: 408
Joined: Wednesday 26 February 2014 15:28
Target OS: Raspberry Pi / ODroid
Domoticz version:
Location: the Netherlands
Contact:

Re: openURL to PVoutput

Post by roblom »

waaren wrote: Tuesday 21 May 2019 22:37
roblom wrote: Tuesday 21 May 2019 21:47 If there is no httpresonse there are some variables set in PVSettings
The makepostData generates a post data string and puts it in postdDataAsString
Correct but postdDataAsString is declared local within the function so this variable does not live outside the function. The return of the function is the value of that variable.
But what will happen if postdDataAsString isn't declared local? Then it does exist outside the function but what is de disadvantage?

Really appreciate your help and effort in trying to share your knowledge!
User avatar
waaren
Posts: 6028
Joined: Tuesday 03 January 2017 14:18
Target OS: Linux
Domoticz version: Beta
Location: Netherlands
Contact:

Re: openURL to PVoutput

Post by waaren »

roblom wrote: Tuesday 21 May 2019 23:32 But what will happen if postdDataAsString isn't declared local? Then it does exist outside the function but what is de disadvantage?
The disadvantage in general of declaring Global variables (In Lua that is true for all variables not declared as local) that they can be accessed and changed outside the scope you intend.
Rule of thumb in programming is to limit the scope of your variables to a minimum. For one reason because it makes debugging a lot easier but there are many more reasons. True for all programming languages but certainly also for Lua / dzVents.

If you want to dive into it...
Google with "Why are or global variables bad" or "Why are global variables evil" You will find a ton of statements / comments and examples.
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
Derik
Posts: 1605
Joined: Friday 18 October 2013 23:33
Target OS: Raspberry Pi / ODroid
Domoticz version: BETA
Location: Arnhem/Nijmegen Nederland
Contact:

Re: openURL to PVoutput

Post by Derik »

Dear...
i try to set more scripts into dz....
I will try to set my upload lua also into dz.

Is there a complete script?
Upload solar
usage
temp
v8 etc

see multiple scripts only what is working well?
Xu4: Beta Extreme antenna RFXcomE,WU Fi Ping ip P1 Gen5 PVOutput Harmony HUE SolarmanPv OTG Winddelen Alive ESP Buienradar MySensors WOL Winddelen counting RPi: Beta SMAspot RFlinkTest Domoticz ...Different backups
roblom
Posts: 408
Joined: Wednesday 26 February 2014 15:28
Target OS: Raspberry Pi / ODroid
Domoticz version:
Location: the Netherlands
Contact:

Re: openURL to PVoutput

Post by roblom »

OK I need some help. THe script below was working for a really long time. A few days ago I changed to a new Voltage logging device so the only thing that I changed was the idx of this device. But since then I get the flowing error in the log. When I change it back to the original idx the error stays the same.
2020-11-14 15:05:12.151 Error: dzVents: Error: (3.0.16) pvOutput: HTTP/1.1 response: 401 ==>> Unauthorized
2020-11-14 15:05:12.151 Error: dzVents: Error: (3.0.16) pvOutput: Error: the return from PVOutput was : Unauthorized 401: Invalid System ID
2020-11-14 15:05:12.152 Error: dzVents: Error: (3.0.16) pvOutput: An error occurred when calling event handler pvoutput
2020-11-14 15:05:12.153 Error: dzVents: Error: (3.0.16) pvOutput: /home/pi/domoticz/scripts/dzVents/scripts/pvoutput.lua:113: attempt to index a nil value (global 'Solar')
The real problem is the "Unauthorized 401: Invalid System ID" but of course I've checked this several times but the ID is correct. THe second error about line 113 is possible that it was already there but when the response is successful this isn't noticed. I think it has something to do with local variables that are declared outside this function...
Spoiler: show

Code: Select all

-- The base of this scrip comes from
-- https://www.domoticz.com/forum/viewtopic.php?f=61&t=4714&p=251778#p251778

[spoiler]local scriptVar = 'PVOutput'

return {
			on =	{
						timer = { 'every 1 minutes'},
						httpResponses = { scriptVar },
					},
 
		logging =	{
--						level   =   domoticz.LOG_INFO,
						level   =   domoticz.LOG_DEBUG,
						marker  =   "pvOutput" 
					},

	execute = function(dz, item)

		local function post2PVOutput(PVSettings, postData)
			dz.openURL({
				url = PVSettings.url,
				method = 'POST',
				headers = {
					['X-Pvoutput-Apikey'] = PVSettings.api,
					['X-Pvoutput-SystemId'] = PVSettings.id
				},
				callback = scriptVar,
				postData = postData
			})
		end

		local function makepostData()
			----------------------------------------------------------------------------------------------------------
			-- Domoticz IDX of the needed devices
			----------------------------------------------------------------------------------------------------------

			local Solar 				= dz.devices(96)	-- (v1+v2) IDX of Solar Panels
			local Consumption 			= dz.devices(93)	-- (v3+v4) IDX of Consumption device (from consumption.lua script)
			local Temperature 			= dz.devices(1123) 	-- (v5) IDX of outside temp device
			local Voltage 				= dz.devices(1689) 	-- (v6) IDX of a device with a Voltage value
			local c1 					= 1 				-- (c1) Cumulative Flag. c1 = 0 when v1 is today's energy. c1 = 1 when v1 is lifetime energy.
			local n 					= 0					-- (n) Net Flag. n = 0 is default, n = 1 When the net export/import and generation/consumption data is uploaded separately
			local Water 				= dz.devices(81)	-- (v7) IDX of the water consumption
			local InverterFrequency 	= dz.devices(1632)	-- (v8) IDX of the inverter frequency
			local InverterVoltage 		= dz.devices(561)	-- (v9) IDX of the inverter temperature
			local InverterCurrent 		= dz.devices(389) 	-- (v10) IDX of the inverter current
			local InverterTemperature 	= dz.devices(166)	-- (v11) IDX of the inverter temperature
			local Gas 					= dz.devices(176)	-- (v12) IDX of Smart Gas Meter
			
			local round = dz.utils.round
			
			dz.log('-- Energy generation (v1) = ' .. Solar.WhTotal/1000 .. ' Wh ', dz.LOG_DEBUG)
			dz.log('-- Power generation (v2) = ' .. Solar.actualWatt .. ' W ', dz.LOG_DEBUG)
			dz.log('-- Energy consumption (v3) = ' .. Consumption.WhTotal/1000 .. ' Wh ', dz.LOG_DEBUG)
			dz.log('-- Power consumption (v4) = ' .. Consumption.actualWatt .. ' W ', dz.LOG_DEBUG)
			dz.log('-- Temperature (v5) = ' .. round(Temperature.temperature,1) .. ' C ', dz.LOG_DEBUG)
			dz.log('-- Voltage (v6) = ' .. round(Voltage.voltage,1) .. ' V ', dz.LOG_DEBUG)
			dz.log('-- c1 = ' .. c1 .. ' ', dz.LOG_DEBUG)
			dz.log('-- n = ' .. n .. ' ', dz.LOG_DEBUG)
			dz.log('-- Water (v7) = ' .. Water.counterToday .. ' l ', dz.LOG_DEBUG)
			dz.log('-- Inverter Frequency FAC (v8) = ' .. InverterFrequency.rawData[1] .. ' Hz ', dz.LOG_DEBUG)
			dz.log('-- Inverter voltage VAC (v9) = ' .. round(InverterVoltage.voltage,1) .. ' V ', dz.LOG_DEBUG)
			dz.log('-- Inverter current UAC (v10) = ' .. InverterCurrent.rawData[1] .. ' A ', dz.LOG_DEBUG)
			dz.log('-- Inverter Temperature (v11) = ' .. round(InverterTemperature.temperature,1) .. ' C ', dz.LOG_DEBUG)
			dz.log('-- Gas (v12) = ' .. Gas.counterToday .. ' m3 ', dz.LOG_DEBUG)

			
			local postdDataAsString = 

			--[[ 
				v1 - energy generation
				v2 - power generation
				v3 - energy consumption
				v4 - power consumption
				v5 - Temperature
				v6 - Voltage
				v7 - Water Consumption in l
				v8 - Frequency (FAC)
				v9 - Voltage (VAC)
				v10 - Current (IAC)
				v11 - Inverter Temperature
				v12 - Gas Consumption
			]] -- 

			'd=' .. os.date("%Y%m%d") ..
			'&t=' .. os.date("%H:%M") ..
			'&v1=' .. Solar.WhTotal ..
			'&v2=' .. Solar.actualWatt ..
			'&v3=' .. Consumption.WhTotal ..
			'&v4=' .. Consumption.actualWatt ..
			'&v5=' .. round(Temperature.temperature,1) ..
			'&v6=' .. round(Voltage.voltage,1) ..
			'&c1=' .. c1 ..
			'&n=' .. n ..
			'&v7=' .. Water.counterToday ..
			'&v8=' .. InverterFrequency.rawData[1] ..
			'&v9=' .. round(InverterVoltage.voltage,1) ..
			'&v10=' .. InverterCurrent.rawData[1] ..
			'&v11=' .. round(InverterTemperature.temperature,1) ..
			'&v12=' .. Gas.counterToday

			return postdDataAsString
		end


        if item.isHTTPResponse then
			if item.statusText=='OK' then
				dz.log("Data successfully added to PVoutput")
			else
				dz.log("Error: the return from PVOutput was : " .. item.data,dz.LOG_ERROR)
--				dz.log('-- Energy generation (v1) = ' .. Solar.WhTotal .. ' Wh ', dz.LOG_ERROR)
				dz.log('-- Power generation (v2) = ' .. Solar.actualWatt .. ' W ', dz.LOG_ERROR)
				dz.log('-- Energy consumption (v3) = ' .. Consumption.WhTotal .. ' Wh ', dz.LOG_ERROR)
				dz.log('-- Power consumption (v4) = ' .. Consumption.actualWatt .. ' W ', dz.LOG_ERROR)
			end
		else

			----------------------------------------------------------------------------------------------------------
			-- Settings for pvoutput.org
			----------------------------------------------------------------------------------------------------------

			PVSettings = 
			{
				url = 'HTTPS://pvoutput.org/service/r2/addstatus.jsp',
				api = 'xxxxxxxxxx',
				id  = 'xxxxx',
			}

			post2PVOutput(PVSettings, makepostData())
		end
	end
}
Of course I removed the api and id in the above script....

The complete output of the log.
Spoiler: show

Code: Select all

2020-11-14 15:18:01.464 Status: dzVents: Info: pvOutput: ------ Start external script: pvoutput.lua:, trigger: "every 1 minutes"
2020-11-14 15:18:01.660 Status: dzVents: Debug: pvOutput: Processing device-adapter for Opgewekt (Script): kWh device adapter
2020-11-14 15:18:01.672 Status: dzVents: Debug: pvOutput: Processing device-adapter for Consumptie: kWh device adapter
2020-11-14 15:18:01.685 Status: dzVents: Debug: pvOutput: Processing device-adapter for Buiten - Zonnepanelen (DS18B20): Temperature device adapter
2020-11-14 15:18:01.696 Status: dzVents: Debug: pvOutput: Processing device-adapter for Ketel oud - Voltage: Voltage device adapter
2020-11-14 15:18:01.707 Status: dzVents: Debug: pvOutput: Processing device-adapter for Water: Counter device adapter
2020-11-14 15:18:01.720 Status: dzVents: Debug: pvOutput: Processing device-adapter for Omvormer Frequentie (Script): Custom sensor device adapter
2020-11-14 15:18:01.729 Status: dzVents: Debug: pvOutput: Processing device-adapter for Omvormer Voltage (Script): Voltage device adapter
2020-11-14 15:18:01.739 Status: dzVents: Debug: pvOutput: Processing device-adapter for Omvormer Amperage (Script): 1-phase Ampere device adapter
2020-11-14 15:18:01.749 Status: dzVents: Debug: pvOutput: Processing device-adapter for Omvormer Temperatuur (Script): Temperature device adapter
2020-11-14 15:18:01.760 Status: dzVents: Debug: pvOutput: Processing device-adapter for Gas (P1): Gas device adapter
2020-11-14 15:18:01.761 Status: dzVents: Debug: pvOutput: -- Energy generation (v1) = 2075.7 Wh
2020-11-14 15:18:01.762 Status: dzVents: Debug: pvOutput: -- Power generation (v2) = 90.0 W
2020-11-14 15:18:01.762 Status: dzVents: Debug: pvOutput: -- Energy consumption (v3) = 10688.767 Wh
2020-11-14 15:18:01.762 Status: dzVents: Debug: pvOutput: -- Power consumption (v4) = 840.0 W
2020-11-14 15:18:01.763 Status: dzVents: Debug: pvOutput: -- Temperature (v5) = 12.3 C
2020-11-14 15:18:01.764 Status: dzVents: Debug: pvOutput: -- Voltage (v6) = 229.7 V
2020-11-14 15:18:01.764 Status: dzVents: Debug: pvOutput: -- c1 = 1
2020-11-14 15:18:01.765 Status: dzVents: Debug: pvOutput: -- n = 0
2020-11-14 15:18:01.765 Status: dzVents: Debug: pvOutput: -- Water (v7) = 182 l
2020-11-14 15:18:01.766 Status: dzVents: Debug: pvOutput: -- Inverter Frequency FAC (v8) = 50.04 Hz
2020-11-14 15:18:01.766 Status: dzVents: Debug: pvOutput: -- Inverter voltage VAC (v9) = 229.5 V
2020-11-14 15:18:01.767 Status: dzVents: Debug: pvOutput: -- Inverter current UAC (v10) = 0.6 A
2020-11-14 15:18:01.767 Status: dzVents: Debug: pvOutput: -- Inverter Temperature (v11) = 21.3 C
2020-11-14 15:18:01.768 Status: dzVents: Debug: pvOutput: -- Gas (v12) = 3.452 m3
2020-11-14 15:18:01.769 Status: dzVents: Debug: pvOutput: OpenURL: url = HTTPS://pvoutput.org/service/r2/addstatus.jsp
2020-11-14 15:18:01.769 Status: dzVents: Debug: pvOutput: OpenURL: method = POST
2020-11-14 15:18:01.769 Status: dzVents: Debug: pvOutput: OpenURL: post data = d=20201114&t=15:18&v1=2075700.0&v2=90.0&v3=10688767.0&v4=840.0&v5=12.3&v6=229.7&c1=1&n=0&v7=182&v8=50.04&v9=229.5&v10=0.6&v11=21.3&v12=3.452
2020-11-14 15:18:01.770 Status: dzVents: Debug: pvOutput: OpenURL: headers = {["X-Pvoutput-SystemId"]="xxxxx", ["X-Pvoutput-Apikey"]="xxxxxxxxxx"}
2020-11-14 15:18:01.770 Status: dzVents: Debug: pvOutput: OpenURL: callback = PVOutput
2020-11-14 15:18:01.771 Status: dzVents: Info: pvOutput: ------ Finished pvoutput.lua
2020-11-14 15:18:07.877 Status: dzVents: Info: Handling httpResponse-events for: "PVOutput"
2020-11-14 15:18:07.878 Status: dzVents: Info: pvOutput: ------ Start external script: pvoutput.lua: HTTPResponse: "PVOutput"
2020-11-14 15:18:07.882 Status: dzVents: Info: pvOutput: ------ Finished pvoutput.lua
roblom
Posts: 408
Joined: Wednesday 26 February 2014 15:28
Target OS: Raspberry Pi / ODroid
Domoticz version:
Location: the Netherlands
Contact:

Re: openURL to PVoutput

Post by roblom »

I compared it with an backup I found but the script is exactly the same.... must be something at pvoutput so I ask also there.
User avatar
waaren
Posts: 6028
Joined: Tuesday 03 January 2017 14:18
Target OS: Linux
Domoticz version: Beta
Location: Netherlands
Contact:

Re: openURL to PVoutput

Post by waaren »

roblom wrote: Saturday 14 November 2020 15:15 OK I need some help. THe script below was working for a really long time. A few days ago I changed to a new Voltage logging device so the only thing that I changed was the idx of this device. But since then I get the flowing error in the log. When I change it back to the original idx the error stays the same.
Thx for reporting. Something seem to have changed in recent domoticz Beta. I will check with which Beta this error first occurred.
Build 12607 is still OK.
Build 12622 is no longer OK

I created issue 4462 for this
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
User avatar
waaren
Posts: 6028
Joined: Tuesday 03 January 2017 14:18
Target OS: Linux
Domoticz version: Beta
Location: Netherlands
Contact:

Re: openURL to PVoutput

Post by waaren »

waaren wrote: Saturday 14 November 2020 16:03 I created issue 4462 for this
Fixed in build 12644
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
roblom
Posts: 408
Joined: Wednesday 26 February 2014 15:28
Target OS: Raspberry Pi / ODroid
Domoticz version:
Location: the Netherlands
Contact:

Re: openURL to PVoutput  [Solved]

Post by roblom »

Great to hear it's solved I thought I went crazy because I thought I broke something but couldn't find it.
Post Reply

Who is online

Users browsing this forum: Google [Bot] and 1 guest