Page 5 of 7
Re: Lua script for uploading energy values to PVoutput
Posted: Wednesday 16 August 2017 19:35
by Derik
The things i do not understand... [ sorry ]
I do only have a the USB P1.
So what d i fill in by
Code: Select all
local GenerationDeviceName = "xxxxxx" -- Device name of the Generated energy
local ConsumptionIDX = xxx -- IDX of the energy device that shows calculated Consumption
local ConsumptionDeviceName = "xxxxxx" -- Name of the energy device that shows calculated Consumption
Because i have to replace this:
Code: Select all
local ImportedDeviceName = "xxxxxx" -- Name of the energy device that shows imported energy
local ExportedDeviceName = "xxxxxx" -- Name of the energy device that shows exported energy
For:
Only i do not have other devices?
The other part:
Do i need to ad this:
Code: Select all
EnergyImportLow = 0 -- in Watt hours
EnergyImportHigh = 0 -- in Watt hours
EnergyExportLow = 0 -- in Watt hours
EnergyExportHigh = 0 -- in Watt hours
Or replace?
Because when i try to do the both of them no thing is working
The the other thing
Is it correct u calculate in you in script?
That is just the thing Pvo is doing?
Just upload the use and generation separate uploading to pvo is giving the good graphs?
Re: Lua script for uploading energy values to PVoutput
Posted: Wednesday 16 August 2017 20:20
by roblom
Ah, you don't have solar panels? Then it becomes a bit more complex. But why did you want to upload the values to pvoutput if you don't have solar panels?
The script calculates the real consumption. That's because when you generate 100W and consumes 100W at the same time the smart meter register 0W in and 0W out.
But when you don't have solar panels there is nothing to calculate.
Re: Lua script for uploading energy values to PVoutput
Posted: Wednesday 16 August 2017 20:34
by Derik
mmm There is....
My useage and my gas...
Perhaps possible with this script [ gas to V7 ? ]
And i do have a "winddelen" that i upload separate to pvo...
Re: Lua script for uploading energy values to PVoutput
Posted: Wednesday 17 January 2018 16:49
by Derik
Dear Alla..
Something changed in gratisweerdata for my
https://github.com/harold65/SolarMeter system to upload my solarpanels.
The site is from http to https changed, so the solarmeter cannot use the free weather data any more...
Is there perhaps some one that can change my script so i can upload a tempsensor from domoticz to pvoutput.
I use this script to upload my winddelen to Pvo like it is a solarpanel
Code: Select all
commandArray = {}
print ("Winddelen naar P.V.O.")
date = os.date("*t")
if (date.min % 5 == 0) then -- %10 is iedere 10 minuten
solar = otherdevices_svalues['D.M.: 3x Jonge Held']
now, total = solar:match("(%d+);(%d+)")
-- print(solar..' '..now..' '..total)
-- Upload data to PVoutput every 5 mins [ verander %5 in %10 en dan iederre 10 minuten ]
baseURL = "http://pvoutput.org/service/r2/addstatus.jsp?"
SID = "15962"
API = "c53c834f1af40b8035b7eeb61c3210ea535"
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
There is a string where pvo is asking for:
https://pvoutput.org/help.html#api-addoutput
Only one bog problem...
I do not understand this script and the request from Pvo output.. [ bricklayer here

]
Perhaps some that can help..
Thanks for the time
Re: Lua script for uploading energy values to PVoutput
Posted: Saturday 12 January 2019 21:14
by dvdbosch
Guys,
Need some help!
Im using the scripts/snippets as mentioned a few pages ago, but in some kind of way my measurements are incorrect. See below.
Code: Select all
2019-01-12 20:44:24.693 (P1) P1 Smart Meter (Power)
2019-01-12 20:44:24.728 Status: LUA: ----- PowerGeneration = 0.000 W
2019-01-12 20:44:24.728 Status: LUA: ----- EnergyGeneration = 5298730.000 Wh
2019-01-12 20:44:24.728 Status: LUA: ----- PowerImport = 460 W
2019-01-12 20:44:24.728 Status: LUA: ----- EnergyImportLow = 2058351 Wh
2019-01-12 20:44:24.728 Status: LUA: ----- EnergyImportHigh = 1732276 Wh
2019-01-12 20:44:24.728 Status: LUA: ----- EnergyImport = 3790627 Wh
2019-01-12 20:44:24.728 Status: LUA: ----- PowerExport = 0 W
2019-01-12 20:44:24.728 Status: LUA: ----- EnergyExportLow = 1141386 Wh
2019-01-12 20:44:24.729 Status: LUA: ----- EnergyExportHigh = 2645175 Wh
2019-01-12 20:44:24.729 Status: LUA: ----- EnergyExport = 3786561 Wh
2019-01-12 20:44:24.729 Status: LUA: ----- PowerConsumption = 460 W
2019-01-12 20:44:24.729 Status: LUA: ----- EnergyConsumption = 5302796 Wh
At the moment I'm not generating any energy, but it register import. Any suggestions to solve this?
Am using the following calculation:
Code: Select all
----------------------------------------------------------------------------------------------------------
-- CommandArray
----------------------------------------------------------------------------------------------------------
commandArray = {}
-- Generated
PowerGeneration, EnergyGeneration = otherdevices_svalues[GenerationDeviceName]:match("([^;]+);([^;]+)")
if Debug=="YES" then
print(" ----- PowerGeneration = " .. PowerGeneration .. " W");
print(" ----- EnergyGeneration = " .. EnergyGeneration .. " Wh");
end
-- Imported
EnergyImportLow, EnergyImportHigh, EnergyExportLow, EnergyExportHigh, PowerImport, PowerExport = otherdevices_svalues[EnergyDeviceName]:match("([^;]+);([^;]+);([^;]+);([^;]+);([^;]+);([^;]+)")
EnergyImport = EnergyImportLow + EnergyImportHigh
EnergyExport = EnergyExportLow + EnergyExportHigh
if Debug=="YES" then
print(" ----- PowerImport = " .. PowerImport .. " W");
print(" ----- EnergyImportLow = " .. EnergyImportLow .. " Wh");
print(" ----- EnergyImportHigh = " .. EnergyImportHigh .. " Wh");
print(" ----- EnergyImport = " .. EnergyImport .. " Wh");
print(" ----- PowerExport = " .. PowerExport .. " W");
print(" ----- EnergyExportLow = " .. EnergyExportLow .. " Wh");
print(" ----- EnergyExportHigh = " .. EnergyExportHigh .. " Wh");
print(" ----- EnergyExport = " .. EnergyExport .. " Wh");
end
-- Calculate consumption
PowerConsumption = PowerGeneration + PowerImport - PowerExport
if Debug=="YES" then
print(" ----- PowerConsumption = " .. PowerConsumption .. " W");
end
EnergyConsumption = EnergyGeneration + EnergyImport - EnergyExport
if Debug=="YES" then
print(" ----- EnergyConsumption = " .. EnergyConsumption .. " Wh");
end
In some kind of way its perhaps related to the following:
Code: Select all
----------------------------------------------------------------------------------------------------------
-- Domoticz IDX and names of the needed devices
----------------------------------------------------------------------------------------------------------
local GenerationDeviceName = "kWh Meter" -- Device name of the Generated energy
local EnergyDeviceName = "Power" -- Name of the energy device that shows imported and exported energy
local ConsumptionIDX = "5829" -- IDX of the energy device that shows calculated Consumption
local ConsumptionDeviceName = "Electricity" -- Name of the energy device that shows calculated Consumption
For the "ConsumtionDeviceName" im using a virtual sensor (Electric, (instant + counter)).
Thanks in advance!
Re: Lua script for uploading energy values to PVoutput
Posted: Wednesday 15 May 2019 12:02
by rmayne
I cant make the relation betaween the asked parameters and my SBFSpot device.
local GenerationDeviceName = "xxxxxx" -- Device name of the Generated energy
local ImportedDeviceName = "xxxxxx" -- Name of the energy device that shows imported energy
local ExportedDeviceName = "xxxxxx" -- Name of the energy device that shows exported energy
local ConsumptionIDX = xxx -- IDX of the energy device that shows calculated Consumption
local ConsumptionDeviceName = "xxxxxx" -- Name of the energy device that shows calculated Consumption
Whitch on have to be selected?
My devices
SBFSpot 00000001 1 SolarMain General kWh 659.759 kWh
SBFSpot 00000001 1 Volt uac1 General Voltage 243.72 V
SBFSpot 00000001 1 Efficiency General Percentage 0%
SBFSpot 00000002 1 Hz General Percentage 50%
SBFSpot 00000003 1 BT_Signal General Percentage 0%
SBFSpot 0001 1 Temperature Temp
Re: Lua script for uploading energy values to PVoutput
Posted: Monday 27 May 2019 14:08
by knielen
Thanks for those great scripts, works perfect!
Re: Lua script for uploading energy values to PVoutput
Posted: Monday 27 May 2019 14:11
by knielen
rmayne wrote: ↑Wednesday 15 May 2019 12:02
I cant make the relation betaween the asked parameters and my SBFSpot device.
local GenerationDeviceName = "xxxxxx" -- Device name of the Generated energy
SolarMain General kWh
local ImportedDeviceName = "xxxxxx" -- Name of the energy device that shows imported energy
Your energy meter
local ExportedDeviceName = "xxxxxx" -- Name of the energy device that shows exported energy
Your energy meter
local ConsumptionIDX = xxx -- IDX of the energy device that shows calculated Consumption
Dummy device in Domoticz created by you
local ConsumptionDeviceName = "xxxxxx" -- Name of the energy device that shows calculated Consumption
Dummy device in Domoticz created by you
Whitch on have to be selected?
My devices
SBFSpot 00000001 1 SolarMain General kWh 659.759 kWh
SBFSpot 00000001 1 Volt uac1 General Voltage 243.72 V
SBFSpot 00000001 1 Efficiency General Percentage 0%
SBFSpot 00000002 1 Hz General Percentage 50%
SBFSpot 00000003 1 BT_Signal General Percentage 0%
SBFSpot 0001 1 Temperature Temp
see
bolt comments above
Re: Lua script for uploading energy values to PVoutput
Posted: Sunday 09 June 2019 16:39
by Merlin1201
Hi..iam trying to use this upload and calculation script and have one problem so far in the first script
Calculation give's me a 770.617 kWh my gues that's to high? or do I missing something.
1 Slimme meter 0001 1 Power P1 Smart Meter Energy 782243;880866;301139;611053;0;852 -
2 Slimme meter 00000001 1 Voltage L1 General Voltage 233.4 V - -
3 Slimme meter 0000000 1 Usage L1 Usage Electric 0 Watt - -
4 Slimme meter 0000000 4 Delivery L1 Usage Electric 852 Watt -
5 Slimme meter 0001 2 Gas P1 Smart Meter Gas 1166.925 -
11 goodwe 00082011 1 Goodwe General kWh 19.700 kWh
12 Calculation 00082012 1 Consumption General kWh 770.617 kWh
Re: Lua script for uploading energy values to PVoutput
Posted: Tuesday 11 June 2019 22:16
by Merlin1201
I still don't get it,
PowerConsumption = PowerGeneration + PowerImport - PowerExport.
PowerConsumption = 21600 (solarpannels) + 2473 (import energy) - 14396 (Returned energy)
PowerConsumption = 9677
So my PowerConsumption is 9677 kWh for that day, en that's right, so my question is why is the outcome 2000 kWh and not 9677 ???????
Is this something in PVoutput? is the script wrong somewhere?
Re: Lua script for uploading energy values to PVoutput
Posted: Saturday 15 June 2019 12:53
by roblom
I think you are mixing up energy and power. Power is in W and Energy is in kWh. An average household consumes 3000kWh a year. So if you consumes 9677kWh a day there is something seriously wrong.
I think the numbers are the values registered by the meter since it started measuring. And not the values of that day.
Re: Lua script for uploading energy values to PVoutput
Posted: Sunday 16 June 2019 10:57
by Merlin1201
ah ok.. PowerConsumption = PowerGeneration + PowerImport - PowerExport.
PowerConsumption = 21,600 kWh (solarpannels) + 2,473 kWh (import energy) - 14,396 kWh (Returned energy)
PowerConsumption = 9,677 kWh
That 9,677 kWh is exact mij Consumption for a day.
but this script show's me just 2,000 kWh and that's wrong
Re: Lua script for uploading energy values to PVoutput
Posted: Sunday 16 June 2019 12:30
by roblom
As said, I think you are mixing up the devices.
- Power are the values in W
- Energy are the values in Wh
It doesn't really matter for the formula but if your consumption isn't correct then I think you are using the formula with the wrong values. I think you put in the power values and think it is energy.
So check if the values you are using in
PowerConsumption = 21,600 kWh (solarpannels) + 2,473 kWh (import energy) - 14,396 kWh (Returned energy)
PowerConsumption = 9,677 kWh
And change it so it become
EnergyConsumption = EnergyGeneration + EnergyImport - EnergyExport
EnergyConsumption = 21600 Wh (solarpannels) + 2473 Wh (import energy) - 14396 Wh (Returned energy)
EnergyConsumption = 9677 Wh
Or maybe you can post some debug values?
Re: Lua script for uploading energy values to PVoutput
Posted: Sunday 16 June 2019 15:15
by Merlin1201
some data
2019-06-16 15:15:08.121 Status: EventSystem: Script event triggered: /home/pi/domoticz/scripts/lua/script_device_calculate_consumption.lua
2019-06-16 15:15:08.213 Status: LUA: ----- PowerGeneration = 1610 W
2019-06-16 15:15:08.213 Status: LUA: ----- EnergyGeneration = 13400 Wh
2019-06-16 15:15:08.213 Status: LUA: ----- PowerImport = 0 W
2019-06-16 15:15:08.213 Status: LUA: ----- EnergyImportLow = 802820 Wh
2019-06-16 15:15:08.213 Status: LUA: ----- EnergyImportHigh = 892727 Wh
2019-06-16 15:15:08.213 Status: LUA: ----- EnergyImport = 1695547 Wh
2019-06-16 15:15:08.213 Status: LUA: ----- PowerExport = 1211 W
2019-06-16 15:15:08.213 Status: LUA: ----- EnergyExportLow = 329318 Wh
2019-06-16 15:15:08.213 Status: LUA: ----- EnergyExportHigh = 655179 Wh
2019-06-16 15:15:08.213 Status: LUA: ----- EnergyExport = 984497 Wh
2019-06-16 15:15:08.213 Status: LUA: ----- PowerConsumption = 399 W
2019-06-16 15:15:08.213 Status: LUA: ----- EnergyConsumption = 724450 Wh
2019-06-16 15:15:08.228 Status: LUA: ----- PowerGeneration = 1610 W
2019-06-16 15:15:08.228 Status: LUA: ----- EnergyGeneration = 13400 Wh
2019-06-16 15:15:08.228 Status: LUA: ----- PowerImport = 0 W
2019-06-16 15:15:08.228 Status: LUA: ----- EnergyImportLow = 802820 Wh
2019-06-16 15:15:08.228 Status: LUA: ----- EnergyImportHigh = 892727 Wh
2019-06-16 15:15:08.228 Status: LUA: ----- EnergyImport = 1695547 Wh
2019-06-16 15:15:08.228 Status: LUA: ----- PowerExport = 1211 W
2019-06-16 15:15:08.228 Status: LUA: ----- EnergyExportLow = 329318 Wh
2019-06-16 15:15:08.228 Status: LUA: ----- EnergyExportHigh = 655179 Wh
2019-06-16 15:15:08.228 Status: LUA: ----- EnergyExport = 984497 Wh
2019-06-16 15:15:08.228 Status: LUA: ----- PowerConsumption = 399 W
2019-06-16 15:15:08.228 Status: LUA: ----- EnergyConsumption = 724450 Wh
2019-06-16 15:15:08.241 Status: LUA: ----- PowerGeneration = 1610 W
2019-06-16 15:15:08.241 Status: LUA: ----- EnergyGeneration = 13400 Wh
2019-06-16 15:15:08.241 Status: LUA: ----- PowerImport = 0 W
2019-06-16 15:15:08.241 Status: LUA: ----- EnergyImportLow = 802820 Wh
2019-06-16 15:15:08.241 Status: LUA: ----- EnergyImportHigh = 892727 Wh
2019-06-16 15:15:08.241 Status: LUA: ----- EnergyImport = 1695547 Wh
2019-06-16 15:15:08.241 Status: LUA: ----- PowerExport = 1211 W
2019-06-16 15:15:08.241 Status: LUA: ----- EnergyExportLow = 329318 Wh
2019-06-16 15:15:08.242 Status: LUA: ----- EnergyExportHigh = 655179 Wh
2019-06-16 15:15:08.242 Status: LUA: ----- EnergyExport = 984497 Wh
2019-06-16 15:15:08.242 Status: LUA: ----- PowerConsumption = 399 W
2019-06-16 15:15:08.242 Status: LUA: ----- EnergyConsumption = 724450 Wh
Re: Lua script for uploading energy values to PVoutput
Posted: Monday 17 June 2019 8:00
by Merlin1201
And another strange value, Energy used is not right, it's too much.
Date Time Energy Efficiency Power Average Normalised Temperature Voltage Energy Used Power Used
17/06/19 08:00 0.900kWh 0.188kWh/kW 1,635W - 0.341kW/kW 0.0C 229.6V 708.971kWh 359W
17/06/19 07:55 0.800kWh 0.167kWh/kW 1,643W - 0.342kW/kW 0.0C 230.4V 708.899kWh 349W
17/06/19 07:50 0.700kWh 0.146kWh/kW 1,625W - 0.339kW/kW 0.0C 230.2V 708.899kWh 378W
17/06/19 07:45 0.600kWh 0.125kWh/kW 1,552W - 0.323kW/kW 0.0C 231.4V 708.883kWh 324W
Re: Lua script for uploading energy values to PVoutput
Posted: Monday 29 July 2019 22:33
by R0yk3
Hello,
I used this script for ages and i am very happy about it.
But now i have upgraded my solar 'plant'
Now i have a 3 phase meter.
For some reason i cannot get the data right.
This is the error i get.
2019-08-18 15:39:41.492 Error: EventSystem: in /home/pi/domoticz/scripts/lua/script_device_calculate_consumption.lua: ...ticz/scripts/lua/script_device_calculate_consumption.lua:52: attempt to concatenate global 'PowerGeneration' (a nil value)
Made a spoiler to keer the post compact.
- Spoiler: show
-
----------------------------------------------------------------------------------------------------------
-- Domoticz IDX and names of the needed devices
----------------------------------------------------------------------------------------------------------
#1 - local GenerationDeviceName = "PV_WATT" -- Device name of the Generated energy
#2 - local EnergyDeviceName = "Power" -- Name of the energy device that shows imported and exported energy
#3 - local ConsumptionIDX = "310" -- IDX of the energy device that shows calculated Consumption
#4 - local ConsumptionDeviceName = "Consumption" -- Name of the energy device that shows calculated Consumption
I numbered the lines so that is not in the script.
#1 is the output in Watt from my panels, also tried the daily output in kwh same error
Values are: name state value
PV_WATT 805 0/805
Or as i use daily output
Values are: name state value
PV_DagTotaal 8.2 0/8.2
#2 This is the output prom my P1
Values are: name State value
Power 2508553;1420218;1248032;2946828;49;490 0/2508553;1420218;1248032;2946828;49;490
#3 and #4 is the same device and made it as written in the tutorial.
Values are: name state value
Consumption 0;0.0 0/0;0.0
What do i miss here???
Re: Lua script for uploading energy values to PVoutput
Posted: Monday 30 September 2019 12:54
by sjoemie1985
R0yk3 wrote: ↑Monday 29 July 2019 22:33
Hello,
I used this script for ages and i am very happy about it.
But now i have upgraded my solar 'plant'
Now i have a 3 phase meter.
For some reason i cannot get the data right.
This is the error i get.
2019-08-18 15:39:41.492 Error: EventSystem: in /home/pi/domoticz/scripts/lua/script_device_calculate_consumption.lua: ...ticz/scripts/lua/script_device_calculate_consumption.lua:52: attempt to concatenate global 'PowerGeneration' (a nil value)
Made a spoiler to keer the post compact.
- Spoiler: show
-
----------------------------------------------------------------------------------------------------------
-- Domoticz IDX and names of the needed devices
----------------------------------------------------------------------------------------------------------
#1 - local GenerationDeviceName = "PV_WATT" -- Device name of the Generated energy
#2 - local EnergyDeviceName = "Power" -- Name of the energy device that shows imported and exported energy
#3 - local ConsumptionIDX = "310" -- IDX of the energy device that shows calculated Consumption
#4 - local ConsumptionDeviceName = "Consumption" -- Name of the energy device that shows calculated Consumption
I numbered the lines so that is not in the script.
#1 is the output in Watt from my panels, also tried the daily output in kwh same error
Values are: name state value
PV_WATT 805 0/805
Or as i use daily output
Values are: name state value
PV_DagTotaal 8.2 0/8.2
#2 This is the output prom my P1
Values are: name State value
Power 2508553;1420218;1248032;2946828;49;490 0/2508553;1420218;1248032;2946828;49;490
#3 and #4 is the same device and made it as written in the tutorial.
Values are: name state value
Consumption 0;0.0 0/0;0.0
What do i miss here???
i have the same problem at the moment?
do you already have an solution?
Re: Lua script for uploading energy values to PVoutput
Posted: Monday 30 September 2019 15:00
by R0yk3
No, no solution.
i am using dsmr now
https://dsmr-reader.readthedocs.io/nl/latest/index.html
Although i prefer it via Domoticz.
Re: Lua script for uploading energy values to PVoutput
Posted: Wednesday 23 October 2019 15:44
by knielen
I had the same issue, by manually extracting the right values from my meter I solved this issue.
Code: Select all
-- Update comsumption device in Domoticz
if devicechanged[EnergyDeviceName] then
Total = "http://127.0.0.1:8080/json.htm?type=command¶m=udevice&idx=328&nvalue=0&svalue=" .. PowerConsumption .. ";" .. EnergyConsumption;
os.execute('curl "' .. Total .. '"');
end
Re: Lua script for uploading energy values to PVoutput
Posted: Wednesday 25 March 2020 11:40
by hansonexperience
Hi,
I upgraded my rpi with domomoticz to buster (new version debian) and new version of domoticz. Now this does not work anymore:
local http = require("socket.http")
I am using the pvoutput upload script which was functioning great but now I have errors that it cannot find the socket a.s.o.
Can anyone help?