Page 4 of 7

Re: Lua script for uploading energy values to PVoutput

Posted: Tuesday 18 July 2017 22:56
by Domoberry
If the problem still persists, could you add the offending line 58?

Re: Lua script for uploading energy values to PVoutput

Posted: Wednesday 19 July 2017 12:10
by R0yk3
Hi,

I have a integrated P1 logger so i changed the script accordingly.
below the script the way i use it:
Spoiler: show
-- /home/pi/domoticz/scripts/lua/script_device_calculate_consumption.lua
-- This script collects the values below from Domoticz
-- * The Power and energy values (import and export) from a smartmeter
-- * The Power and energy values from a Solar power inverter
-- It then calculates the consumed power and energy from the values above with the formula's
-- * EnergyConsumption = EnergyGeneration + EnergyImport - EnergyExport
-- * PowerConsumption = PowerGeneration + PowerImport - PowerExport
-- It then updates a virtual device which displays the consumed power and energy in Domoticz

----------------------------------------------------------------------------------------------------------
-- Domoticz IDX and names of the needed devices
----------------------------------------------------------------------------------------------------------
local GenerationDeviceName = "Elektra" -- Device name of the Generated energy
local EnergyDeviceName = "Elektra" -- Name of the energy device that shows imported and exported energy
local ConsumptionIDX = "198" -- IDX of the energy device that shows calculated Consumption
local ConsumptionDeviceName = "Elektra_verbruik" -- Name of the energy device that shows calculated Consumption

----------------------------------------------------------------------------------------------------------
-- Require parameters
----------------------------------------------------------------------------------------------------------
local http = require("socket.http")

----------------------------------------------------------------------------------------------------------
-- Script parameters
----------------------------------------------------------------------------------------------------------
EnergyImportLow = 0 -- in Watt hours
EnergyImportHigh = 0 -- in Watt hours
EnergyExportLow = 0 -- in Watt hours
EnergyExportHigh = 0 -- in Watt hours
EnergyGeneration = 0 -- in Watt hours
PowerGeneration = 0 -- in Watts
EnergyImport = 0 -- in Watt hours
PowerImport = 0 -- in Watts
EnergyConsumption = 0 -- in Watt hours
PowerConsumption = 0 -- in Watts
Debug = "YES" -- Turn debugging on ("YES") or off ("NO")

----------------------------------------------------------------------------------------------------------
-- Lua Functions
----------------------------------------------------------------------------------------------------------
function update(device, id, power, energy, index)
commandArray[index] = {['UpdateDevice'] = id .. "|0|" .. power .. ";" .. energy}
end

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

-- Update comsumption device in Domoticz
if devicechanged[EnergyDeviceName] then
update(ConsumptionDeviceName, ConsumptionIDX, PowerConsumption, EnergyConsumption, 1)
end

return commandArray
where line 58 is red

Re: Lua script for uploading energy values to PVoutput

Posted: Wednesday 19 July 2017 21:25
by R0yk3
Activated it tonight, no changes made and i have no errors anymore??
Trying the upload now.
Wel upload goes wrong..

Code: Select all

2017-07-19 22:15:01.271 LUA: Time to go before upload to PVoutput: 5 minutes
2017-07-19 22:15:01.271 LUA: ---- The total generated energy is 1824806 Wh
2017-07-19 22:15:01.271 LUA: ---- The current generated power is 3067693 W
2017-07-19 22:15:01.271 LUA: ---- The voltage of the inverter is 228.600 V
2017-07-19 22:15:01.271 LUA: ---- The outside temperature is 23.4 C.
2017-07-19 22:15:01.271 LUA: ---- The total consumed energy is 6143917 Wh
2017-07-19 22:15:01.271 LUA: ---- The current consumed power is 442 W

2017-07-19 22:15:02.423 LUA: -- Bad request 400: Power value [3067693] too high for system size [2280]

2017-07-19 22:15:02.424 LUA: -- Energy generation (v1) = 1824806 Wh
2017-07-19 22:15:02.424 LUA: -- Power generation (v2) = 3067693 W
2017-07-19 22:15:02.424 LUA: -- Energy consumption (v3) = 6143917 Wh
2017-07-19 22:15:02.424 LUA: -- Power consumption (v4) = 442 W
2017-07-19 22:15:02.424 LUA: -- Current temperature (v5) = 23.4 C
2017-07-19 22:15:02.424 LUA: -- Voltage (v6) = 228.600V
2017-07-19 22:15:02.424 LUA: -- Cumulative Flag (c1) = 1
2017-07-19 22:15:02.437 EventSystem: Fetching url...
2017-07-19 22:15:02.470 LUA: ----- PowerGeneration = 0.000 W
2017-07-19 22:15:02.470 LUA: ----- EnergyGeneration = 2838435.000 Wh
2017-07-19 22:15:02.470 LUA: ----- PowerImport = 442 W

2017-07-19 22:15:02.470 LUA: ----- EnergyImportLow = 3067693 Wh

2017-07-19 22:15:02.470 LUA: ----- EnergyImportHigh = 1824806 Wh
2017-07-19 22:15:02.470 LUA: ----- EnergyImport = 4892499 Wh
2017-07-19 22:15:02.470 LUA: ----- PowerExport = 0 W
2017-07-19 22:15:02.470 LUA: ----- EnergyExportLow = 483873 Wh
2017-07-19 22:15:02.470 LUA: ----- EnergyExportHigh = 1103144 Wh
2017-07-19 22:15:02.470 LUA: ----- EnergyExport = 1587017 Wh
2017-07-19 22:15:02.470 LUA: ----- PowerConsumption = 442 W
2017-07-19 22:15:02.470 LUA: ----- EnergyConsumption = 6143917 Wh
Seems like it uses Energy Import Low as value for the power. :?:

Re: Lua script for uploading energy values to PVoutput

Posted: Thursday 27 July 2017 13:01
by roblom
The problem is
The current generated power is 3067693 W
This van be 2280W at the max. So I think you put in the wrong value.

Re: Lua script for uploading energy values to PVoutput

Posted: Thursday 27 July 2017 13:12
by R0yk3
I put the wrong value??
EnergyImportLow = 3067693 Wh, is used as current generated power is 3067693 W

first one is correct, the last one is not. but where do i change that? i guess i have to change the s value, but that would mean everybody with a P1 meter should do that?

Re: Lua script for uploading energy values to PVoutput

Posted: Thursday 27 July 2017 14:20
by roblom
I have taken a quick look so I might be wrong but it looks like you are using the same device for different things.
local GenerationDeviceName = "Elektra" -- Device name of the Generated energy
local EnergyDeviceName = "Elektra" -- Name of the energy device that shows imported and exported energy
The generated power can't be coming from the P1 as the smart meter only knows the exported energy. Between the energy generated by your solar panels and the exported energy that your meter shows is your internal consumption.

Re: Lua script for uploading energy values to PVoutput

Posted: Thursday 27 July 2017 14:27
by R0yk3
OK, So elektra has to become my solarpanels (SBFSpot)
I wil try that later. I thought i did that already causing another error. wil let you know, thanks for your reply.

Re: Lua script for uploading energy values to PVoutput

Posted: Thursday 27 July 2017 14:52
by roblom
GenerationDeviceName has to be your solar panels energy.
EnergyDeviceName has to be your smart meter.

Re: Lua script for uploading energy values to PVoutput

Posted: Thursday 27 July 2017 17:20
by R0yk3
Hi,

the script is like i thougt, i do have the solarpanels for the generation.
Still i have the same error:

Code: Select all

2017-07-27 17:14:57.290 LUA: ----- PowerGeneration = 402.000 W
2017-07-27 17:14:57.290 LUA: ----- EnergyGeneration = 2905220.000 Wh
2017-07-27 17:14:57.290 LUA: ----- PowerImport = 58 W
2017-07-27 17:14:57.290 LUA: ----- EnergyImportLow = 3098393 Wh
2017-07-27 17:14:57.290 LUA: ----- EnergyImportHigh = 1834983 Wh
2017-07-27 17:14:57.290 LUA: ----- EnergyImport = 4933376 Wh
2017-07-27 17:14:57.290 LUA: ----- PowerExport = 0 W
2017-07-27 17:14:57.290 LUA: ----- EnergyExportLow = 492638 Wh
2017-07-27 17:14:57.290 LUA: ----- EnergyExportHigh = 1136906 Wh
2017-07-27 17:14:57.290 LUA: ----- EnergyExport = 1629544 Wh
2017-07-27 17:14:57.290 LUA: ----- PowerConsumption = 460 W
2017-07-27 17:14:57.290 LUA: ----- EnergyConsumption = 6209052 Wh
2017-07-27 17:15:00.382 LUA: Time to go before upload to PVoutput: 5 minutes
2017-07-27 17:15:00.382 LUA: ---- The total generated energy is 1834983 Wh
2017-07-27 17:15:00.382 LUA: ---- The current generated power is 3098393 W
2017-07-27 17:15:00.382 LUA: ---- The voltage of the inverter is 227.200 V
2017-07-27 17:15:00.382 LUA: ---- The outside temperature is 22.2 C.
2017-07-27 17:15:00.382 LUA: ---- The total consumed energy is 6209052 Wh
2017-07-27 17:15:00.382 LUA: ---- The current consumed power is 460 W
2017-07-27 17:15:00.805 LUA: -- Bad request 400: Power value [3098393] too high for system size [2280]
2017-07-27 17:15:00.806 LUA: -- Energy generation (v1) = 1834983 Wh
2017-07-27 17:15:00.806 LUA: -- Power generation (v2) = 3098393 W
2017-07-27 17:15:00.806 LUA: -- Energy consumption (v3) = 6209052 Wh
2017-07-27 17:15:00.806 LUA: -- Power consumption (v4) = 460 W
2017-07-27 17:15:00.806 LUA: -- Current temperature (v5) = 22.2 C
2017-07-27 17:15:00.806 LUA: -- Voltage (v6) = 227.200V
The power generation has to be 402. So i guess i have to alter some svalues. can you give me a hint? :roll:

Re: Lua script for uploading energy values to PVoutput

Posted: Thursday 27 July 2017 19:59
by roblom
It sounds very unlogic that you need to edit the svalues. Are the devices in domoticz displaying the correct values?
Did you correct the GenerationDeviceName in both scripts?

Re: Lua script for uploading energy values to PVoutput

Posted: Thursday 27 July 2017 20:08
by R0yk3
:oops: :oops: :oops:
Excuses did not change the device in the upload script. Changed it correctly now it works accordingly. https://pvoutput.org/intraday.jsp?id=48861&sid=44499&dt

Sorry for being a n00b. :oops: :oops: :oops:

Re: Lua script for uploading energy values to PVoutput

Posted: Friday 28 July 2017 13:35
by R0yk3
One last thing.. :)
The voltage is now fixed at 232,5 volt? although before the sbfspot upload the voltage varies.
Where do i fix that??

Re: Lua script for uploading energy values to PVoutput

Posted: Friday 28 July 2017 16:02
by roblom
In the upload script there is a VoltageDeviceName this needs to point at the name of the device in domoticz that shows the voltage.

Re: Lua script for uploading energy values to PVoutput

Posted: Friday 28 July 2017 16:48
by R0yk3
Yes, obvious.
as you can see in the code parts i uploaded the voltage is given:
LUA: ---- The voltage of the inverter is 227.200 V
LUA: -- Voltage (v6) = 227.200V

And earlier:
LUA: ---- The voltage of the inverter is 228.600 V
LUA: -- Voltage (v6) = 228.600V

I did not change the device name so it should be right?
going to check it at home, i guess i messed something up in the SBF part.

Re: Lua script for uploading energy values to PVoutput

Posted: Friday 28 July 2017 22:42
by R0yk3
:roll: :roll:
I think i am going crazy..
I have got the device voltage up, and now night time the value is 0.
i get an error in the calculating script..
2017-07-28 22:40:00.076 Error: EventSystem: in /home/pi/domoticz/scripts/lua/script_time_upload_to_PVoutput.lua: .../domoticz/scripts/lua/script_time_upload_to_PVoutput.lua:89: attempt to index field '?' (a nil value)

:x :cry: :cry:
I wil let this run until i have a value again, but i guess this is not the right thing.

Re: Lua script for uploading energy values to PVoutput

Posted: Friday 28 July 2017 22:54
by roblom
Normally the voltage that the inverter was running before it turned off will be kept until the inverter is woken up again the next morning. So it will never be set to zero. So your problem will be fixed tomorrow :-)

Re: Lua script for uploading energy values to PVoutput

Posted: Saturday 29 July 2017 8:04
by R0yk3
roblom wrote:Normally the voltage that the inverter was running before it turned off will be kept until the inverter is woken up again the next morning. So it will never be set to zero. So your problem will be fixed tomorrow :-)
Image Image Image Image Yesss. Thankyou.

Verstuurd vanaf mijn SM-G955F met Tapatalk

Re: Lua script for uploading energy values to PVoutput

Posted: Saturday 05 August 2017 0:56
by Derik
Dear All

Will try to upload my P1 gas meter to Pvo...
For the nice graphs..
Only the Pi show no now value
ScreenShot152.jpg
ScreenShot152.jpg (72.02 KiB) Viewed 4966 times
I did try to upload the meter with this script, only that is not working.
Because there is no now in the P1 gas, and all other sensors do have one...

Is there perhaps some that have a option for this upload?
Or a working script to upload to the V7 in Pvo?

Re: Lua script for uploading energy values to PVoutput

Posted: Wednesday 16 August 2017 18:53
by Derik
Please ....
Fucked up with my settings for the upload of my usb P1 hardware... https://www.slimmemeterkabel.nl/
Is there some one that have a working example scriptfor me ...[ without api and other personal stuff ]
So i do not neet to replace peaces of the code.....

I try different times the wiki...
Replace parts of the code..[ more times ]
Only i do not understand it, and that is where i go wrong...:-(

I am stuck with this P1 part...
And i do like to upload my P1 with domoticz...
Hope there is someone


And perhaps someone have the gas working, to upload it to Pvo?

Re: Lua script for uploading energy values to PVoutput

Posted: Wednesday 16 August 2017 18:59
by roblom
What part you don't understand because the info provided in the wiki contains all the you need.