Lua script for uploading energy values to PVoutput

Moderator: leecollings

pgit
Posts: 12
Joined: Monday 04 August 2014 17:54
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: Lua script for uploading energy values to PVoutput

Post 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!
Derik
Posts: 1602
Joined: Friday 18 October 2013 23:33
Target OS: Raspberry Pi / ODroid
Domoticz version: BETA
Location: Arnhem/Nijmegen Nederland
Contact:

Re: Lua script for uploading energy values to PVoutput

Post 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? ]
 
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: Lua script for uploading energy values to PVoutput

Post 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++)?
roblom
Posts: 408
Joined: Wednesday 26 February 2014 15:28
Target OS: Raspberry Pi / ODroid
Domoticz version:
Location: the Netherlands
Contact:

Re: Lua script for uploading energy values to PVoutput

Post 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".
Pietervs
Posts: 1
Joined: Monday 21 March 2016 15:47
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: Lua script for uploading energy values to PVoutput

Post 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".
Derik
Posts: 1602
Joined: Friday 18 October 2013 23:33
Target OS: Raspberry Pi / ODroid
Domoticz version: BETA
Location: Arnhem/Nijmegen Nederland
Contact:

Re: Lua script for uploading energy values to PVoutput

Post 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 4904 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?
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
User avatar
Westcott
Posts: 423
Joined: Tuesday 09 December 2014 17:04
Target OS: Raspberry Pi / ODroid
Domoticz version: Beta
Location: UK - Glos
Contact:

Re: Lua script for uploading energy values to PVoutput

Post 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
Last edited by Westcott on Monday 21 March 2016 21:56, edited 2 times in total.
Zwave - Sigma Z+ stick, Fibaro, Horstmann, Neo Coolcam, EUROtronic
RFlink - IR detectors and temperatures
Wifi - YeeLights, ESP32s, Anoop sockets
Zigbee - lots with zigbee2mqtt and ZbBridge
Derik
Posts: 1602
Joined: Friday 18 October 2013 23:33
Target OS: Raspberry Pi / ODroid
Domoticz version: BETA
Location: Arnhem/Nijmegen Nederland
Contact:

Re: Lua script for uploading energy values to PVoutput

Post 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 4890 times
What do you think i do wrong..
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
User avatar
Westcott
Posts: 423
Joined: Tuesday 09 December 2014 17:04
Target OS: Raspberry Pi / ODroid
Domoticz version: Beta
Location: UK - Glos
Contact:

Re: Lua script for uploading energy values to PVoutput

Post 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.
Zwave - Sigma Z+ stick, Fibaro, Horstmann, Neo Coolcam, EUROtronic
RFlink - IR detectors and temperatures
Wifi - YeeLights, ESP32s, Anoop sockets
Zigbee - lots with zigbee2mqtt and ZbBridge
Derik
Posts: 1602
Joined: Friday 18 October 2013 23:33
Target OS: Raspberry Pi / ODroid
Domoticz version: BETA
Location: Arnhem/Nijmegen Nederland
Contact:

Re: Lua script for uploading energy values to PVoutput

Post 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!!
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
User avatar
Westcott
Posts: 423
Joined: Tuesday 09 December 2014 17:04
Target OS: Raspberry Pi / ODroid
Domoticz version: Beta
Location: UK - Glos
Contact:

Re: Lua script for uploading energy values to PVoutput

Post by Westcott »

Glad to be of help.
Have fun taking the script forward!
Zwave - Sigma Z+ stick, Fibaro, Horstmann, Neo Coolcam, EUROtronic
RFlink - IR detectors and temperatures
Wifi - YeeLights, ESP32s, Anoop sockets
Zigbee - lots with zigbee2mqtt and ZbBridge
markk
Posts: 267
Joined: Tuesday 14 January 2014 14:50
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: Lua script for uploading energy values to PVoutput

Post 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
Running Domoticz on Pi3 with RFXtrx433e. LWRF power sockets and dimmer switches. Integrated my existing wirefree alarm PIRs and door contacts with domoticz. Geofencing with Pilot. Harmony Hub. Tado for Heating. Now playing with mysensors.
User avatar
Westcott
Posts: 423
Joined: Tuesday 09 December 2014 17:04
Target OS: Raspberry Pi / ODroid
Domoticz version: Beta
Location: UK - Glos
Contact:

Re: Lua script for uploading energy values to PVoutput

Post by Westcott »

Hi Derik,
Can you post the exact script you are using, please?
Zwave - Sigma Z+ stick, Fibaro, Horstmann, Neo Coolcam, EUROtronic
RFlink - IR detectors and temperatures
Wifi - YeeLights, ESP32s, Anoop sockets
Zigbee - lots with zigbee2mqtt and ZbBridge
markk
Posts: 267
Joined: Tuesday 14 January 2014 14:50
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: Lua script for uploading energy values to PVoutput

Post 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.
Running Domoticz on Pi3 with RFXtrx433e. LWRF power sockets and dimmer switches. Integrated my existing wirefree alarm PIRs and door contacts with domoticz. Geofencing with Pilot. Harmony Hub. Tado for Heating. Now playing with mysensors.
User avatar
Westcott
Posts: 423
Joined: Tuesday 09 December 2014 17:04
Target OS: Raspberry Pi / ODroid
Domoticz version: Beta
Location: UK - Glos
Contact:

Re: Lua script for uploading energy values to PVoutput

Post by Westcott »

How are you calling the script?
Can you post your complete script, please?
Zwave - Sigma Z+ stick, Fibaro, Horstmann, Neo Coolcam, EUROtronic
RFlink - IR detectors and temperatures
Wifi - YeeLights, ESP32s, Anoop sockets
Zigbee - lots with zigbee2mqtt and ZbBridge
markk
Posts: 267
Joined: Tuesday 14 January 2014 14:50
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: Lua script for uploading energy values to PVoutput

Post 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 138 times
Running Domoticz on Pi3 with RFXtrx433e. LWRF power sockets and dimmer switches. Integrated my existing wirefree alarm PIRs and door contacts with domoticz. Geofencing with Pilot. Harmony Hub. Tado for Heating. Now playing with mysensors.
User avatar
Westcott
Posts: 423
Joined: Tuesday 09 December 2014 17:04
Target OS: Raspberry Pi / ODroid
Domoticz version: Beta
Location: UK - Glos
Contact:

Re: Lua script for uploading energy values to PVoutput

Post 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?
Zwave - Sigma Z+ stick, Fibaro, Horstmann, Neo Coolcam, EUROtronic
RFlink - IR detectors and temperatures
Wifi - YeeLights, ESP32s, Anoop sockets
Zigbee - lots with zigbee2mqtt and ZbBridge
markk
Posts: 267
Joined: Tuesday 14 January 2014 14:50
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: Lua script for uploading energy values to PVoutput

Post 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
Running Domoticz on Pi3 with RFXtrx433e. LWRF power sockets and dimmer switches. Integrated my existing wirefree alarm PIRs and door contacts with domoticz. Geofencing with Pilot. Harmony Hub. Tado for Heating. Now playing with mysensors.
markk
Posts: 267
Joined: Tuesday 14 January 2014 14:50
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: Lua script for uploading energy values to PVoutput

Post 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 133 times
Running Domoticz on Pi3 with RFXtrx433e. LWRF power sockets and dimmer switches. Integrated my existing wirefree alarm PIRs and door contacts with domoticz. Geofencing with Pilot. Harmony Hub. Tado for Heating. Now playing with mysensors.
User avatar
Westcott
Posts: 423
Joined: Tuesday 09 December 2014 17:04
Target OS: Raspberry Pi / ODroid
Domoticz version: Beta
Location: UK - Glos
Contact:

Re: Lua script for uploading energy values to PVoutput

Post 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.
Zwave - Sigma Z+ stick, Fibaro, Horstmann, Neo Coolcam, EUROtronic
RFlink - IR detectors and temperatures
Wifi - YeeLights, ESP32s, Anoop sockets
Zigbee - lots with zigbee2mqtt and ZbBridge
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest