Page 1 of 7

Lua script for uploading energy values to PVoutput

Posted: Tuesday 30 December 2014 15:08
by roblom
At this moment I have two scripts running, one for the generated energy from my PV installation and one that pulls the data from my smartmeter. Both of these scripts uploads the values to PVoutput and Domoticz. As I would like to have the Domoticz database the primari database as possible and as the consumption calculation of PVoutput isn't accurate as I would like I dived into the Lua scripting. As I'm no programmer and therefore I didn't had any knowledge of Lua it took me a few weeks but my first Lua script was born. As I like sharing my knowledge I created a Wiki of it.

Upload energy data to PVoutput (Lua)

And of course feedback is welcome :D

Re: Lua script for uploading energy values to PVoutput

Posted: Friday 02 January 2015 20:06
by sincze
roblom wrote:At this moment I have two scripts running, one for the generated energy from my PV installation and one that pulls the data from my smartmeter. Both of these scripts uploads the values to PVoutput and Domoticz. As I would like to have the Domoticz database the primari database as possible and as the consumption calculation of PVoutput isn't accurate as I would like I dived into the Lua scripting. As I'm no programmer and therefore I didn't had any knowledge of Lua it took me a few weeks but my first Lua script was born. As I like sharing my knowledge I created a Wiki of it.

Upload energy data to PVoutput (Lua)

And of course feedback is welcome :D
Nice work!
If you can explain to me how you create a new page in the Wiki
I will add information on how to read data from an Omnik Solar Inverter and show the results in domoticz. :D

Re: Lua script for uploading energy values to PVoutput

Posted: Friday 02 January 2015 21:43
by roblom
I don't know if it's the right way but if you edit the front page with the table and add a new wiki in it, then after you have saved it, you can click on it and it opens a new empty wiki.

Re: Lua script for uploading energy values to PVoutput

Posted: Saturday 03 January 2015 14:27
by sincze
roblom wrote:I don't know if it's the right way but if you edit the front page with the table and add a new wiki in it, then after you have saved it, you can click on it and it opens a new empty wiki.
:D It worked. Thanks.

Re: Lua script for uploading energy values to PVoutput

Posted: Saturday 28 February 2015 23:32
by pimvolkert
It was pretty easy to configure. Except for one 1 small error/bug in the Wiki documentation, which avoided the script working.
When you use a P1 meter (like me) an additional change has to be made to the script cript_device_calculate_consumption.lua

Change:

if devicechanged[ImportedDeviceName] then

into:

if devicechanged[EnergyDeviceName] then

Then it worked flawless.

Re: Lua script for uploading energy values to PVoutput

Posted: Sunday 01 March 2015 22:20
by roblom
pimvolkert wrote:It was pretty easy to configure. Except for one 1 small error/bug in the Wiki documentation, which avoided the script working.
When you use a P1 meter (like me) an additional change has to be made to the script cript_device_calculate_consumption.lua

Change:

if devicechanged[ImportedDeviceName] then

into:

if devicechanged[EnergyDeviceName] then

Then it worked flawless.
Nice to hear it worked.
I added your comments to the wiki, thanks!

Re: Lua script for uploading energy values to PVoutput

Posted: Monday 02 March 2015 0:13
by ThinkPad
Maybe this script (Dutch explanation) is also useful: http://tweaken.blogspot.nl/2015/01/domo ... utorg.html
I don't use it myself (no solar panels unfortunately), but the mindergas script from his blog works great.

He is also on this forum, his nickname is 'nickyb2'.

Re: Lua script for uploading energy values to PVoutput

Posted: Monday 02 March 2015 14:01
by markk
Hi. I have my generation and comsumption values loaded into Domoticz via Owl meters and really want to upload these to PVOutput using the LUA time script here. However, as is so often the case with me, I'm stuck because the wiki for this assumes that Domoticz is being run on a Pi and mine is on windows so the section "install socket library" has me stumped. Is there a simple window alternative to use at this stage please?

Re: Lua script for uploading energy values to PVoutput

Posted: Wednesday 08 April 2015 22:58
by bomboclat
Markk,, did you find any solution ,.,
i am getting crazy with socket and lua52... all example are for unix or Pi... nothing for windows.
I try to recompile the socket lib ... but nothing .to do ... do not work

Ciao
Michele

Re: Lua script for uploading energy values to PVoutput

Posted: Friday 10 April 2015 23:36
by markk
bomboclat wrote:Markk,, did you find any solution ,.,
i am getting crazy with socket and lua52... all example are for unix or Pi... nothing for windows.
I try to recompile the socket lib ... but nothing .to do ... do not work

Ciao
Michele
Hi
No, I had to give up. It's not like me to do so but I'm just not clued up enough. I was really gutted this beat me. I'd love to have been able to get this working.

Re: Lua script for uploading energy values to PVoutput

Posted: Saturday 11 April 2015 22:55
by roblom
Sorry I can't help with this.
But maybe a stupid question, but why are you running it on windows? You can but a Raspberry for about € 30,- then you don't have to get crazy anymore :-)

Re: Lua script for uploading energy values to PVoutput

Posted: Sunday 12 April 2015 0:56
by markk
roblom wrote:Sorry I can't help with this.
But maybe a stupid question, but why are you running it on windows? You can but a Raspberry for about € 30,- then you don't have to get crazy anymore :-)
I already have a Raspberry Pi with Domoticz loaded but got stuck ages ago trying to get further. I need to change the port as I already have port 8080 on another device. I've asked here loads of times but, unfortunately, as helpful as everyone is, no-one has yet given me idiot instructions on how to do this!

Re: Lua script for uploading energy values to PVoutput

Posted: Sunday 12 April 2015 14:14
by roblom
I'm not an expert on this but the manual say's:
To start Domoticz automatically when the system starts perform the following steps:
sudo cp domoticz.sh /etc/init.d sudo chmod +x
/etc/init.d/domoticz.sh
sudo update-rc.d domoticz.sh defaults
Edit the startup script and change the USERNAME, DAEMON and DAEMON_ARGS parameters to reflect your current
settings
sudo vi /etc/init.d/domoticz.sh
USERNAME=pi
DAEMON=/home/$USERNAME/domoticz/$NAME
DAEMON_ARGS="-daemon -www 8080 –sslwww 443"
If you want to use another web interface port change:
DAEMON_ARGS="-daemon -www 8080 –sslwww 443"
So already tried that by changing 8080 to something else?

Re: Lua script for uploading energy values to PVoutput

Posted: Monday 20 April 2015 20:04
by tsybeck
Does anybody know how to install the needed lua libraries on a synology device?

Re: Lua script for uploading energy values to PVoutput

Posted: Sunday 15 November 2015 13:50
by Derik
Sear All.

Do i need all the setting give a idx?
I will only upload my winddelen, so no consumption..

Code: Select all

- Domoticz IDX of devices
----------------------------------------------------------------------------------------------------------
local GenerationDeviceName = "3685" 	-- Device name of the Generated energy
local ConsumptionDeviceName = "xxxxx" 	-- Name of the energy device that shows calculated Consumption
local VoltageDeviceName = "xxxxx"	-- Name of the voltage device that shows voltage of the inverter
local TemperatureDeviceName = "2563" 	-- Name of the temperature device that shows outside temperature
 
Do i need to change this?:

Code: Select all

local PVoutputURL = '://pvoutput.org/service/r2/addstatus.jsp?key='	-- The URL to the PVoutput Service
EDIT:
And do i need a crontab?
Or is lua self starting?


Found;
script_time_upload_to_PVoutput.lua

Only there is nothing uploading?
Should upload every 5 minutes?

Re: Lua script for uploading energy values to PVoutput

Posted: Thursday 26 November 2015 23:08
by roblom
Derik wrote:Sear All.

Do i need all the setting give a idx?
I will only upload my winddelen, so no consumption..

Code: Select all

- Domoticz IDX of devices
----------------------------------------------------------------------------------------------------------
local GenerationDeviceName = "3685" 	-- Device name of the Generated energy
local ConsumptionDeviceName = "xxxxx" 	-- Name of the energy device that shows calculated Consumption
local VoltageDeviceName = "xxxxx"	-- Name of the voltage device that shows voltage of the inverter
local TemperatureDeviceName = "2563" 	-- Name of the temperature device that shows outside temperature
 
You probably need to modify the script a bit to remove the not needed devices.
Derik wrote: Do i need to change this?:

Code: Select all

local PVoutputURL = '://pvoutput.org/service/r2/addstatus.jsp?key='	-- The URL to the PVoutput Service
No
Derik wrote: EDIT:
And do i need a crontab?
Or is lua self starting?
No a crontab is not needed.
Derik wrote: Found;
script_time_upload_to_PVoutput.lua

Only there is nothing uploading?
Should upload every 5 minutes?
What is shown in the log?

Re: Lua script for uploading energy values to PVoutput

Posted: Saturday 28 November 2015 14:21
by Derik
What and when should i see in the log? [ what time? ]
I think i see no thing

Re: Lua script for uploading energy values to PVoutput

Posted: Saturday 28 November 2015 18:18
by pgit
Hi.
I am trying to "migrate" my PV and energy usage monitoring from WebSolarLog to Domotics.
I have created device in Domoticz, reading-out and displaying the data frm the P1 port of my ISKRA ME382 smart meter. This works great.
After that followed https://www.domoticz.com/wiki/Omnik_Solar_Inverter to get all the values of my Omnik inverter into Domoticz. This also works great.
Then I followed your instructions on http://www.domoticz.com/wiki/Upload_ene ... o_PVoutput to get all this data into PVoutput.
Sadly no data is being send to PVoutput.

Debugging the lua time script I found:
2015-11-28 17:14:53.845 (ISKRA ME382) P1 Smart Meter (ISKRA ME382 Electricity)
2015-11-28 17:15:03.290 LUA: Time to go before upload to PVoutput: 5 minutes
2015-11-28 17:15:03.290 LUA: ---- The total generated energy is 3860.0 Wh
2015-11-28 17:15:03.290 LUA: ---- The current generated power is 0 W
2015-11-28 17:15:03.290 LUA: ---- The voltage of the inverter is 234.9 V
2015-11-28 17:15:03.291 LUA: ---- The outside temperature is 21.3 C.
2015-11-28 17:15:03.291 LUA: ---- The total consumed energy is -20044 Wh
2015-11-28 17:15:03.291 LUA: ---- The current consumed power is 140 W
2015-11-28 17:15:03.774 LUA: -- Bad request 400: Invalid energy value [-20044]
2015-11-28 17:15:03.776 LUA: -- Energy generation (v1) = 3860.0 Wh
2015-11-28 17:15:03.776 LUA: -- Power generation (v2) = 0 W
2015-11-28 17:15:03.776 LUA: -- Energy consumption (v3) = -20044 Wh
2015-11-28 17:15:03.777 LUA: -- Power consumption (v4) = 140 W
2015-11-28 17:15:03.779 LUA: -- Current temperature (v5) = 21.3 C
2015-11-28 17:15:03.779 LUA: -- Voltage (v6) = 234.9V
2015-11-28 17:15:03.779 LUA: -- Cumulative Flag (c1) = 1


Debugging the lua device script (This was after sundown) showed me:

2015-11-28 17:51:44.273 EventSystem: Script event triggered: /home/pi/domoticz/scripts/lua/script_device_calculate_consumption.lua
2015-11-28 17:51:44.109 (ISKRA ME382) P1 Smart Meter (ISKRA ME382 Electricity)
2015-11-28 17:51:44.400 LUA: ----- PowerGeneration = 0 W
2015-11-28 17:51:44.400 LUA: ----- EnergyGeneration = 3860.0 Wh
2015-11-28 17:51:44.400 LUA: ----- PowerImport = 210 W
2015-11-28 17:51:44.401 LUA: ----- EnergyImportLow = 2530541 Wh
2015-11-28 17:51:44.401 LUA: ----- EnergyImportHigh = 1572032 Wh
2015-11-28 17:51:44.401 LUA: ----- EnergyImport = 4102573 Wh
2015-11-28 17:51:44.401 LUA: ----- PowerExport = 0 W
2015-11-28 17:51:44.402 LUA: ----- EnergyExportLow = 1222662 Wh
2015-11-28 17:51:44.402 LUA: ----- EnergyExportHigh = 2903686 Wh
2015-11-28 17:51:44.402 LUA: ----- EnergyExport = 4126348 Wh
2015-11-28 17:51:44.402 LUA: ----- PowerConsumption = 210 W
2015-11-28 17:51:44.403 LUA: ----- EnergyConsumption = -19915 Wh

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).

How can this be fixed?

thanks in advance,

Peter

Re: Lua script for uploading energy values to PVoutput

Posted: Wednesday 02 December 2015 22:03
by pgit
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!

Re: Lua script for uploading energy values to PVoutput

Posted: Wednesday 02 December 2015 23:04
by Toulon7559
In my opinion, PVOutput correctly assumes that import = consumption = flow from the grid to the user, and should be reported as a positive value v3.
'Negative consumption' is the same as export from the user to the grid and should be only reported by means of a positive value v1.
Looking at the listings in the message http://www.domoticz.com/forum/viewtopic ... 714#p63418 the script possibly somewhere may have a sign-error:
a subtraction the-wrong-way-around creates a similar (negative) result.

Remark after the edit by pgit on his previous message on Thu Dec 03, 2015 2:16 am
Not a candidate for beauty, but perhaps a rude way of 'correction' is to put a tweak in your lua-script which inserts a bias by means of reading of a custom-made user variable:
in that way the bias is semi-resident and you have full control on its magnitude.
The 'better solution' would be to adapt the historic info in the database, but in a similar situation I have not been successful to achieve that:
would like yo hear for more experienced users how to effectively make such change.