Ik probeer een lua script te het een en ander te laten berekenen voor mijn zonnepanelen, om dit vervolgens te uploaden naar PVoutput. (https://www.domoticz.com/wiki/Upload_energy_data_to_PVoutput)
Zie hieronder het script:
In het log van domoticz zie ik het volgende verschijnen:
Wanneer ik debug op "yes" zet, krijg ik de volgende error:
Ik heb de hele handleiding gevolgt en een uitgebreide zoektocht op google gehad, echter kom ik niets tegen wat helpt. Ik snap dat de error te maken heeft met een mismatch, alleen kan ik er niet achter komen wat dat nu exact is. Iemand een idee hoe dit te verhelpen?
Edit: Dit zijn de devices van mijn p1 kabel:

...
Zie hieronder het script:
code:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
| -- /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 = "Bruto opbrengst" -- Device name of the Generated energy local EnergyDeviceName = "Stroom" -- Name of the energy device that shows imported and exported energy local ConsumptionIDX = 414 -- IDX of the energy device that shows calculated Consumption local ConsumptionDeviceName = "Consumption" -- 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 = "NO" -- 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 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 |
In het log van domoticz zie ik het volgende verschijnen:
code:
1
| 2019-06-18 21:15:33.497 Error: EventSystem: in /home/rob/domoticz/scripts/lua/script_device_calculate_consumption.lua: ...ticz/scripts/lua/script_device_calculate_consumption.lua:54: attempt to concatenate global 'PowerGeneration' (a nil value) |
Wanneer ik debug op "yes" zet, krijg ik de volgende error:
code:
1
| 2019-06-18 21:12:44.629 Error: EventSystem: in /home/rob/domoticz/scripts/lua/script_device_calculate_consumption.lua: ...ticz/scripts/lua/script_device_calculate_consumption.lua:73: attempt to perform arithmetic on global 'PowerGeneration' (a nil value) |
Ik heb de hele handleiding gevolgt en een uitgebreide zoektocht op google gehad, echter kom ik niets tegen wat helpt. Ik snap dat de error te maken heeft met een mismatch, alleen kan ik er niet achter komen wat dat nu exact is. Iemand een idee hoe dit te verhelpen?
Edit: Dit zijn de devices van mijn p1 kabel:

...