Lua script for uploading energy values to PVoutput

roblom
Posts: 563
Joined: Wednesday 26 February 2014 16:28
Target OS: Raspberry Pi
Domoticz version:
Location: the Netherlands
Contact:

Lua script for uploading energy values to PVoutput

Post by roblom » Tuesday 30 December 2014 16:08

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

User avatar
sincze
Posts: 988
Joined: Monday 02 June 2014 22:46
Target OS: Raspberry Pi
Domoticz version: 4.9700
Location: Netherlands
Contact:

Re: Lua script for uploading energy values to PVoutput

Post by sincze » Friday 02 January 2015 21:06

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
Using Pass2php since 2016-12
LAN: RFLink, P1-Port, OTGW, MySensors
USB: RFXCom, ZWave
WIFI: Mi-light Wifi-Bridge, Sonoff, ESP8266, Xiaomi Gateway
Solar: Omnik Inverter, PVOutput
Video: Kodi clients with Harmony HUB
Sensors: You name it I probably got 1.

roblom
Posts: 563
Joined: Wednesday 26 February 2014 16:28
Target OS: Raspberry Pi
Domoticz version:
Location: the Netherlands
Contact:

Re: Lua script for uploading energy values to PVoutput

Post by roblom » Friday 02 January 2015 22:43

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.

User avatar
sincze
Posts: 988
Joined: Monday 02 June 2014 22:46
Target OS: Raspberry Pi
Domoticz version: 4.9700
Location: Netherlands
Contact:

Re: Lua script for uploading energy values to PVoutput

Post by sincze » Saturday 03 January 2015 15:27

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.
Using Pass2php since 2016-12
LAN: RFLink, P1-Port, OTGW, MySensors
USB: RFXCom, ZWave
WIFI: Mi-light Wifi-Bridge, Sonoff, ESP8266, Xiaomi Gateway
Solar: Omnik Inverter, PVOutput
Video: Kodi clients with Harmony HUB
Sensors: You name it I probably got 1.

pimvolkert
Posts: 13
Joined: Sunday 11 January 2015 20:32
Target OS: Raspberry Pi
Domoticz version:
Contact:

Re: Lua script for uploading energy values to PVoutput

Post by pimvolkert » Sunday 01 March 2015 0:32

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.

roblom
Posts: 563
Joined: Wednesday 26 February 2014 16:28
Target OS: Raspberry Pi
Domoticz version:
Location: the Netherlands
Contact:

Re: Lua script for uploading energy values to PVoutput

Post by roblom » Sunday 01 March 2015 23:20

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!

User avatar
ThinkPad
Posts: 1754
Joined: Tuesday 30 September 2014 8:49
Target OS: Linux
Domoticz version: beta
Location: The Netherlands
Contact:

Re: Lua script for uploading energy values to PVoutput

Post by ThinkPad » Monday 02 March 2015 1:13

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'.
ThinkTheme - theme for Domoticz
My (Dutch) blog: http://thinkpad.tweakblogs.net - My Domoticz scripts: Bitbucket
I'm not (very) active anymore on this forum as i don't use Domoticz anymore.

markk
Posts: 433
Joined: Tuesday 14 January 2014 15:50
Target OS: Raspberry Pi
Domoticz version:
Contact:

Re: Lua script for uploading energy values to PVoutput

Post by markk » Monday 02 March 2015 15:01

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

bomboclat
Posts: 12
Joined: Tuesday 31 March 2015 20:44
Target OS: Windows
Domoticz version:
Contact:

Re: Lua script for uploading energy values to PVoutput

Post by bomboclat » Wednesday 08 April 2015 22:58

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

markk
Posts: 433
Joined: Tuesday 14 January 2014 15:50
Target OS: Raspberry Pi
Domoticz version:
Contact:

Re: Lua script for uploading energy values to PVoutput

Post by markk » Friday 10 April 2015 23:36

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

roblom
Posts: 563
Joined: Wednesday 26 February 2014 16:28
Target OS: Raspberry Pi
Domoticz version:
Location: the Netherlands
Contact:

Re: Lua script for uploading energy values to PVoutput

Post by roblom » Saturday 11 April 2015 22:55

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

markk
Posts: 433
Joined: Tuesday 14 January 2014 15:50
Target OS: Raspberry Pi
Domoticz version:
Contact:

Re: Lua script for uploading energy values to PVoutput

Post by markk » Sunday 12 April 2015 0:56

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

roblom
Posts: 563
Joined: Wednesday 26 February 2014 16:28
Target OS: Raspberry Pi
Domoticz version:
Location: the Netherlands
Contact:

Re: Lua script for uploading energy values to PVoutput

Post by roblom » Sunday 12 April 2015 14:14

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?

tsybeck
Posts: 8
Joined: Wednesday 01 April 2015 14:43
Target OS: NAS (Synology & others)
Domoticz version:
Contact:

Re: Lua script for uploading energy values to PVoutput

Post by tsybeck » Monday 20 April 2015 20:04

Does anybody know how to install the needed lua libraries on a synology device?

User avatar
Derik
Posts: 2183
Joined: Friday 18 October 2013 23:33
Target OS: Raspberry Pi
Domoticz version: BETA
Location: Arnhem/Nijmegen Nederland
Contact:

Re: Lua script for uploading energy values to PVoutput

Post by Derik » Sunday 15 November 2015 14:50

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?
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: 563
Joined: Wednesday 26 February 2014 16:28
Target OS: Raspberry Pi
Domoticz version:
Location: the Netherlands
Contact:

Re: Lua script for uploading energy values to PVoutput

Post by roblom » Friday 27 November 2015 0:08

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?

User avatar
Derik
Posts: 2183
Joined: Friday 18 October 2013 23:33
Target OS: Raspberry Pi
Domoticz version: BETA
Location: Arnhem/Nijmegen Nederland
Contact:

Re: Lua script for uploading energy values to PVoutput

Post by Derik » Saturday 28 November 2015 15:21

What and when should i see in the log? [ what time? ]
I think i see no thing
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

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

Re: Lua script for uploading energy values to PVoutput

Post by pgit » Saturday 28 November 2015 19:18

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

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

Re: Lua script for uploading energy values to PVoutput

Post by pgit » Wednesday 02 December 2015 23:03

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!
Last edited by pgit on Thursday 03 December 2015 2:16, edited 1 time in total.

Toulon7559
Posts: 478
Joined: Sunday 23 February 2014 18:56
Target OS: Raspberry Pi
Domoticz version: latest
Location: Hengelo(Ov)/NL
Contact:

Re: Lua script for uploading energy values to PVoutput

Post by Toulon7559 » Thursday 03 December 2015 0:04

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.
Last edited by Toulon7559 on Friday 04 December 2015 14:37, edited 3 times in total.
Set1 = RPI-B+RFXCom433+S0PCM+Linksprite-shield for BMP180/DS18B20/RS485+DDS238-1ZN
Set2 = RPI-3+RFLinkGTW+ESP8266s+PWS_WS7000
Common = 3*PVLogger+PWS_TFA_Nexus+KAKUs
=> Energy & Data Management based on Time and on PV&Consumption&Meteo

Post Reply

Who is online

Users browsing this forum: No registered users and 0 guests