Lua script for uploading energy values to PVoutput

Moderator: leecollings

User avatar
Domoberry
Posts: 122
Joined: Tuesday 30 May 2017 19:00
Target OS: Raspberry Pi / ODroid
Domoticz version: 2024.7
Contact:

Re: Lua script for uploading energy values to PVoutput

Post by Domoberry »

If the problem still persists, could you add the offending line 58?
R0yk3
Posts: 37
Joined: Sunday 24 July 2016 21:51
Target OS: Raspberry Pi / ODroid
Domoticz version: beta
Location: the Netherlands
Contact:

Re: Lua script for uploading energy values to PVoutput

Post 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
Raspberry PI 3, raspbian, ZwaveMe, RFLink
R0yk3
Posts: 37
Joined: Sunday 24 July 2016 21:51
Target OS: Raspberry Pi / ODroid
Domoticz version: beta
Location: the Netherlands
Contact:

Re: Lua script for uploading energy values to PVoutput

Post 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. :?:
Raspberry PI 3, raspbian, ZwaveMe, RFLink
roblom
Posts: 402
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 »

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.
R0yk3
Posts: 37
Joined: Sunday 24 July 2016 21:51
Target OS: Raspberry Pi / ODroid
Domoticz version: beta
Location: the Netherlands
Contact:

Re: Lua script for uploading energy values to PVoutput

Post 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?
Raspberry PI 3, raspbian, ZwaveMe, RFLink
roblom
Posts: 402
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 »

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.
Last edited by roblom on Thursday 27 July 2017 14:20, edited 1 time in total.
R0yk3
Posts: 37
Joined: Sunday 24 July 2016 21:51
Target OS: Raspberry Pi / ODroid
Domoticz version: beta
Location: the Netherlands
Contact:

Re: Lua script for uploading energy values to PVoutput

Post 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.
Raspberry PI 3, raspbian, ZwaveMe, RFLink
roblom
Posts: 402
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 »

GenerationDeviceName has to be your solar panels energy.
EnergyDeviceName has to be your smart meter.
R0yk3
Posts: 37
Joined: Sunday 24 July 2016 21:51
Target OS: Raspberry Pi / ODroid
Domoticz version: beta
Location: the Netherlands
Contact:

Re: Lua script for uploading energy values to PVoutput

Post 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:
Raspberry PI 3, raspbian, ZwaveMe, RFLink
roblom
Posts: 402
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 »

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?
R0yk3
Posts: 37
Joined: Sunday 24 July 2016 21:51
Target OS: Raspberry Pi / ODroid
Domoticz version: beta
Location: the Netherlands
Contact:

Re: Lua script for uploading energy values to PVoutput

Post 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:
Last edited by R0yk3 on Friday 28 July 2017 13:35, edited 1 time in total.
Raspberry PI 3, raspbian, ZwaveMe, RFLink
R0yk3
Posts: 37
Joined: Sunday 24 July 2016 21:51
Target OS: Raspberry Pi / ODroid
Domoticz version: beta
Location: the Netherlands
Contact:

Re: Lua script for uploading energy values to PVoutput

Post 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??
Raspberry PI 3, raspbian, ZwaveMe, RFLink
roblom
Posts: 402
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 »

In the upload script there is a VoltageDeviceName this needs to point at the name of the device in domoticz that shows the voltage.
R0yk3
Posts: 37
Joined: Sunday 24 July 2016 21:51
Target OS: Raspberry Pi / ODroid
Domoticz version: beta
Location: the Netherlands
Contact:

Re: Lua script for uploading energy values to PVoutput

Post 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.
Raspberry PI 3, raspbian, ZwaveMe, RFLink
R0yk3
Posts: 37
Joined: Sunday 24 July 2016 21:51
Target OS: Raspberry Pi / ODroid
Domoticz version: beta
Location: the Netherlands
Contact:

Re: Lua script for uploading energy values to PVoutput

Post 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.
Raspberry PI 3, raspbian, ZwaveMe, RFLink
roblom
Posts: 402
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 »

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 :-)
R0yk3
Posts: 37
Joined: Sunday 24 July 2016 21:51
Target OS: Raspberry Pi / ODroid
Domoticz version: beta
Location: the Netherlands
Contact:

Re: Lua script for uploading energy values to PVoutput

Post 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
Raspberry PI 3, raspbian, ZwaveMe, RFLink
Derik
Posts: 1601
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 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 4700 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?
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
Derik
Posts: 1601
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 »

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?
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: 402
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 »

What part you don't understand because the info provided in the wiki contains all the you need.
Post Reply

Who is online

Users browsing this forum: No registered users and 0 guests