Page 2 of 7

Re: Lua script for uploading energy values to PVoutput

Posted: Thursday 03 December 2015 1:20
by pgit
I just found out the problem is the current "life time" production energy value. It is set way to low, since I created the virtual production sensor just recently. My PV and Smartmeter have been in production for more then 2 years though...
So I must find a way to edit this value manually, or maybe it's easier to start all over by creating a new sensor and find some way to give it an initial value.
Can anyone give me a hint on how to do this?
Seems you posted a reply just before I edited mine!

Re: Lua script for uploading energy values to PVoutput

Posted: Tuesday 08 December 2015 19:28
by Derik
Derik wrote:What and when should i see in the log? [ what time? ]
I think i see no thing
The log is showing:

Code: Select all

2015-12-08 19:25:58.876 (D.M.: P1) P1 Smart Meter (D.M. P1: Gas)
2015-12-08 19:25:59.117 (D.M. :Winddelen) General/kWh (D.M.: 3x Jonge Held)
2015-12-08 19:26:00.414 Error: EventSystem: .../domoticz/scripts/lua/script_time_upload_to_PVoutput.lua:29: module 'pvoutput.org' not found:
no field package.preload['pvoutput.org']
no file '/usr/local/share/lua/5.2/pvoutput/org.lua'
no file '/usr/local/share/lua/5.2/pvoutput/org/init.lua'
no file '/usr/local/lib/lua/5.2/pvoutput/org.lua'
no file '/usr/local/lib/lua/5.2/pvoutput/org/init.lua'
no file './pvoutput/org.lua'
no file '/usr/local/lib/lua/5.2/pvoutput/org.so'
no file '/usr/local/lib/lua/5.2/loadall.so'
no file './pvoutput/org.so'
no file '/usr/local/lib/lua/5.2/pvoutput.so'
no file '/usr/local/lib/lua/5.2/loadall.so'
no file './pvoutput.so'
2015-12-08 19:26:00.816 (D.M.: Zwave) Usage (Z: Pellet)
2015-12-08 19:26:00.824 (D.M.: Zwave) General/kWh (Z: Pellet Totaal)
2015-12-08 19:26:02.917 (D.M.: Slave 1) General/Percentage (Slave 1: Cpu)
2015-12-08 19:26:03.009 (D.M.: Slave 1) Temp (Slave 1: Rpi)
I think this is wrong:

Code: Select all

local PVoutputPostInterval = 5 						-- The number of minutes between posts to PVoutput (normal is 5 but when in donation mode it's max 1)
local PVoutputURL = '://[color=#0040FF]pvoutput.org/service/r2/addstatus.jsp?key=[/color]'	-- The URL to the PVoutput Service [color=#408000]{ Is this line correct? ][/color]
 
----------------------------------------------------------------------------------------------------------
-- Require parameters
----------------------------------------------------------------------------------------------------------
local http = require("[color=#0000FF]www.pvoutput.org[/color]") [ wrong i think, only what does here stay? ]
 

Re: Lua script for uploading energy values to PVoutput

Posted: Wednesday 16 December 2015 23:23
by roblom
Seems like there is some html code in your lua code that shouldn't be there. How did you create the lua script? What editor did you use (I use Notepad++)?

Re: Lua script for uploading energy values to PVoutput

Posted: Wednesday 16 December 2015 23:34
by roblom
pgit wrote:
pgit wrote:The problem is that the virtual device for the consumption, besides showing the current consumption correctly (I think), is also showing a negative cumulative energy consumption value.
I guess the script is querying the wrong value from my PV Production device in Domoticz: not the current production level, but one of the cumulative ones (either the total- or the daily production).
I just found out the problem is the current "life time" production energy value. It is set way to low, since I created the virtual production sensor just recently. My PV and Smartmeter have been in production for more then 2 years though...
So I must find a way to edit this value manually, or maybe it's easier to start all over by creating a new sensor and find some way to give it an initial value.
Can anyone give me a hint on how to do this?

thanks!
The problem is the negative consumption. Consumption can't be negative so therefore PVoutput doesn't accept negative values. Consumption is calculated by
EnergyConsumption = EnergyGeneration + EnergyImport - EnergyExport
. Where
"EnergyGeneration" is measured on the PV inverter
"EnergyImport" is measured on the P1
"EnergyExport" is measured on the P1

So generation and export is not the same.
So I think there is something going wrong in the "script_device_calculate_consumption.lua".

Re: Lua script for uploading energy values to PVoutput

Posted: Monday 21 March 2016 16:55
by Pietervs
I'm no programmer, so please bear with me :) ;
Let me start of by saying I admire the work done. But the description isn't fool proof yet, so I stumbled on some things. :D

For starters: is it still necessary to create a dummy device? The P1 USB cable I'm using in combination with Domoticz P1 Smart Meter USB shows all the correct data, so I wonder if we can use those data instead of having to create a dummy device?
When I create the dummy device, the data shows "0.000 Kwh".

The the lua scripts:
I didn't see this line, but I did have to install lua separately (sudo apt-get install lua5.2). It wasn't installed yet.

It took a bit of work, but then I did find out that you start the script with "lua <scirpt-name>. What I cannot find is if I need to add a cronjob for this, and how we are going to make it so that it only uploads data from sunrise untill sunset (better yet: 15 minutes before sunrise untill 30 minutes after sunset). I do see that there's a line stating that uploads should take place every 5 minutes.

How can I see if there is a script running in lua? What happens if I start the lua-script several times?

How can I debug the script? I did set DEBUG=YES, but I don't see any output arriving in dmesg. Am I looking in the wrong place?
In /var/log/messages I do get errors though:
Mar 21 16:29:07 DomoUpload rsyslogd-2007: action 'action 17' suspended, next retry is Mon Mar 21 16:30:07 2016 [try http://www.rsyslog.com/e/2007 ]
Mar 21 16:30:08 DomoUpload rsyslogd-2007: action 'action 17' suspended, next retry is Mon Mar 21 16:31:08 2016 [try http://www.rsyslog.com/e/2007 ]
Mar 21 16:31:11 DomoUpload rsyslogd-2007: action 'action 17' suspended, next retry is Mon Mar 21 16:32:11 2016 [try http://www.rsyslog.com/e/2007 ]
Mar 21 16:32:12 DomoUpload rsyslogd-2007: action 'action 17' suspended, next retry is Mon Mar 21 16:33:12 2016 [try http://www.rsyslog.com/e/2007 ]
Mar 21 16:33:17 DomoUpload rsyslogd-2007: action 'action 17' suspended, next retry is Mon Mar 21 16:34:17 2016 [try http://www.rsyslog.com/e/2007 ]
Mar 21 16:34:19 DomoUpload rsyslogd-2007: action 'action 17' suspended, next retry is Mon Mar 21 16:35:19 2016 [try http://www.rsyslog.com/e/2007 ]
< etc, one every minute >
But I'm not sure if they're even related :(

When I start the script I get a message:
pi@DomoUpload:~/domoticz/scripts/lua$ lua script_time_upload_to_PVoutput.lua
Time to go before upload to PVoutput: 3 minutes

This sounds wonderful, but no data is collected at PVOutput.

So I'm hoping someone can shed some light onto these newbie-questions, thanks for "listening".

Re: Lua script for uploading energy values to PVoutput

Posted: Monday 21 March 2016 17:26
by Derik
I will give it a try to...
Only is it possible that there is only a upload from a idx to pvoutput?
I will try to upload my winddelen to pvoutput for the nice graphs.
ScreenShot113.jpg
ScreenShot113.jpg (14 KiB) Viewed 4962 times
Only is till get errors:

Code: Select all

2016-03-21 17:26:00.322 Error: EventSystem: in /home/linaro/domoticz/scripts/lua/script_time_upload_to_PVoutput.lua: .../domoticz/scripts/lua/script_time_upload_to_PVoutput.lua:29: module 'pvoutput.org' not found:
no field package.preload['pvoutput.org']
no file '/usr/local/share/lua/5.2/pvoutput/org.lua'
no file '/usr/local/share/lua/5.2/pvoutput/org/init.lua'
no file '/usr/local/lib/lua/5.2/pvoutput/org.lua'
no file '/usr/local/lib/lua/5.2/pvoutput/org/init.lua'
no file './pvoutput/org.lua'
no file '/usr/local/lib/lua/5.2/pvoutput/org.so'
no file '/usr/local/lib/lua/5.2/loadall.so'
no file './pvoutput/org.so'
no file '/usr/local/lib/lua/5.2/pvoutput.so'
no file '/usr/local/lib/lua/5.2/loadall.so'
no file './pvoutput.so'
Lua 29:
-- Require parameters
----------------------------------------------------------------------------------------------------------
local http = require("pvoutput.org")

I do not understand this?

Re: Lua script for uploading energy values to PVoutput

Posted: Monday 21 March 2016 17:57
by Westcott
Hi Derik,
This Lua snippette will send your data to PVoutput every 10 minutes.
You'll need Lua to first get the values of 'total' and 'now' from your 'D.M.: 3x Jonge Held' device.
More info here - http://pvoutput.org/help.html#api-addstatus

Code: Select all

commandArray = {}

        date = os.date("*t")
        if (date.min % 10 == 0) then
            solar = otherdevices_svalues['D.M.: 3x Jonge Held']
            now, total = solar:match("(%d+);(%d+)")
        --  print(solar..' '..now..' '..total)

        -- Upload data to PVoutput every 10 mins
            baseURL = "http://pvoutput.org/service/r2/addstatus.jsp?"
            SID = "<your_systemID>"
            API = "<your-api>"
            PVO_URL = baseURL .. "sid=" .. SID .. "&key=" .. API .. "&d=" .. os.date("%Y%m%d") .. "&t=" .. os.date("%H:%M")
            PVO_URL = PVO_URL .. "&v1=" .. total .. "&v2=" .. now .. "&c1=1"
            --print(PVO_URL)
            commandArray['OpenURL'] = PVO_URL
        end
        
return commandArray

Re: Lua script for uploading energy values to PVoutput

Posted: Monday 21 March 2016 20:58
by Derik
Dear Westscott

Thanks for the support!!!

I still get every minute a error:

Code: Select all

2016-03-21 20:43:00.357 Error: EventSystem: Lua script /home/linaro/domoticz/scripts/lua/script_time_upload_to_PVoutput.lua did not return a commandArray
I have:
ScreenShot114.jpg
ScreenShot114.jpg (48.39 KiB) Viewed 4948 times
What do you think i do wrong..

Re: Lua script for uploading energy values to PVoutput

Posted: Monday 21 March 2016 21:54
by Westcott
Sorry, I didn't publish a full script, just a snippette.
I've edited the code (above).
Make sure it's a 'time' script.

Re: Lua script for uploading energy values to PVoutput

Posted: Tuesday 22 March 2016 8:14
by Derik
@ Wescott

Thank you very much!!!
It works!

http://pvoutput.org/intraday.jsp?id=15321&sid=15962

One small point.
Could it be that I miss dates from 23.50 to 00.10?
[Not a big problem though, but maybe you have a solution, additional upload to 23:59 perhaps]


This script could fill in PvOutput more graphs. [V3, v4, v5, v6 etc ..]
If you create multiple scripts you could upload your gas and water etc.
And you get very nice graphics, just look at all my sids.

An adjustment would be required for temperature, since you have no average upload.
But there are more options that get temp in pvo.

Thanks again!!

Re: Lua script for uploading energy values to PVoutput

Posted: Tuesday 22 March 2016 9:35
by Westcott
Glad to be of help.
Have fun taking the script forward!

Re: Lua script for uploading energy values to PVoutput

Posted: Wednesday 23 March 2016 14:59
by markk
Westcott wrote:Hi Derik,
This Lua snippette will send your data to PVoutput every 10 minutes.
You'll need Lua to first get the values of 'total' and 'now' from your 'D.M.: 3x Jonge Held' device.
More info here - http://pvoutput.org/help.html#api-addstatus

Code: Select all

commandArray = {}

        date = os.date("*t")
        if (date.min % 10 == 0) then
            solar = otherdevices_svalues['D.M.: 3x Jonge Held']
            now, total = solar:match("(%d+);(%d+)")
        --  print(solar..' '..now..' '..total)

        -- Upload data to PVoutput every 10 mins
            baseURL = "http://pvoutput.org/service/r2/addstatus.jsp?"
            SID = "<your_systemID>"
            API = "<your-api>"
            PVO_URL = baseURL .. "sid=" .. SID .. "&key=" .. API .. "&d=" .. os.date("%Y%m%d") .. "&t=" .. os.date("%H:%M")
            PVO_URL = PVO_URL .. "&v1=" .. total .. "&v2=" .. now .. "&c1=1"
            --print(PVO_URL)
            commandArray['OpenURL'] = PVO_URL
        end
        
return commandArray
Hi

I'm trying to use this revised script but am also getting the "PVoutput.lua did not return a commandArray" error. Any ideas please?

Thanks

Re: Lua script for uploading energy values to PVoutput

Posted: Wednesday 23 March 2016 16:10
by Westcott
Hi Derik,
Can you post the exact script you are using, please?

Re: Lua script for uploading energy values to PVoutput

Posted: Wednesday 06 April 2016 13:47
by markk
markk wrote:
Westcott wrote:Hi Derik,
This Lua snippette will send your data to PVoutput every 10 minutes.
You'll need Lua to first get the values of 'total' and 'now' from your 'D.M.: 3x Jonge Held' device.
More info here - http://pvoutput.org/help.html#api-addstatus

Code: Select all

commandArray = {}

        date = os.date("*t")
        if (date.min % 10 == 0) then
            solar = otherdevices_svalues['D.M.: 3x Jonge Held']
            now, total = solar:match("(%d+);(%d+)")
        --  print(solar..' '..now..' '..total)

        -- Upload data to PVoutput every 10 mins
            baseURL = "http://pvoutput.org/service/r2/addstatus.jsp?"
            SID = "<your_systemID>"
            API = "<your-api>"
            PVO_URL = baseURL .. "sid=" .. SID .. "&key=" .. API .. "&d=" .. os.date("%Y%m%d") .. "&t=" .. os.date("%H:%M")
            PVO_URL = PVO_URL .. "&v1=" .. total .. "&v2=" .. now .. "&c1=1"
            --print(PVO_URL)
            commandArray['OpenURL'] = PVO_URL
        end
        
return commandArray
Hi

I'm trying to use this revised script but am also getting the "PVoutput.lua did not return a commandArray" error. Any ideas please?

Thanks
Hi

Sorry to bump this but I'm desperate to be able to use LUA to upload my energy generation and energy usage to PVOutput but none of the wikis match my setup and I don't know how to make the necessary amendments.
I already have my generation and consumption uploaded to Domoticz via Owl monitors, both show in then utilities tab, but can't figure out how to get the data from these uploaded to PVOutput. I'd be grateful for a push in the right direction please.

Re: Lua script for uploading energy values to PVoutput

Posted: Wednesday 06 April 2016 15:51
by Westcott
How are you calling the script?
Can you post your complete script, please?

Re: Lua script for uploading energy values to PVoutput

Posted: Wednesday 06 April 2016 16:19
by markk
hi

this is the script im trying to upload generated energy with. ive edited out my system details. its called script_time_Pvuploadgen

it isnt showing any errors but no data is uploaded to PVOutput
mple.txt
(772 Bytes) Downloaded 139 times

Re: Lua script for uploading energy values to PVoutput

Posted: Wednesday 06 April 2016 16:37
by Westcott
Try un-commenting '--print(PVO_URL)'
Let the script run, and copy the URL text from the log and run it in a browser to see what PVoutput's return status is.
You're not getting a "PVoutput.lua did not return a commandArray" error any more?

Re: Lua script for uploading energy values to PVoutput

Posted: Wednesday 06 April 2016 23:07
by markk
I don't know what you mean by "Try un-commenting '--print(PVO_URL)'", sorry.
The script is running and not showing any errors. the log is showing:

2016-04-06 22:05:00.745 EventSystem: Fetching url...
2016-04-06 22:05:00.746 EventSystem: Script event triggered: C:\Program Files\Domoticz\scripts\lua\script_time_PVOutputgenerated.lua

Re: Lua script for uploading energy values to PVoutput

Posted: Friday 06 May 2016 14:54
by markk
Sorry to bump this. I'm moving my Domoticz system from window to a Pi and now just need to be able to upload my energy generation and consumption to PVupload by some other method and I can ditch the laptop completely. I currently use PVUpload on windows.
I'm trying to upload my energy generation using this LUA script. The generation data is collected with an Owl monitor and logged in my utilities as device "generated". The script seems to run and shows the following in the log but nothing appears in PVoutput:

2016-04-06 22:05:00.745 EventSystem: Fetching url...
2016-04-06 22:05:00.746 EventSystem: Script event triggered: C:\Program Files\Domoticz\scripts\lua\script_time_PVOutputgenerated.lua

I'm obviously missing something so I'd be grateful for any help please
Sample.txt
(772 Bytes) Downloaded 134 times

Re: Lua script for uploading energy values to PVoutput

Posted: Friday 06 May 2016 15:15
by Westcott
Two things -

Try printing PVO_URL and copying it to a browser to see what PVoutput returns.
PVO_URL = PVO_URL .. "&v1=" .. total .. "&v2=" .. now .. "&c1=1"
print(PVO_URL)

Your SID does not look right, mine is a 5 digit number.