Hi i`m having difficulty when following the wiki
i use the script_device_calculate_consumption.lua wich looks doing ok on the dashboard doiing its calculations from my solarpanels and p1 meter
the script_time_upload_to_PVoutput.lua however does nothing and gives a error in the log
Error: EventSystem: in /home/pi/domoticz/scripts/lua/script_time_upload_to_PVoutput.lua: .../domoticz/scripts/lua/script_time_upload_to_PVoutput.lua:90: attempt to index field '?' (a nil value)
when i run the script manual using
pi@minibian:~/domoticz/scripts/lua$ lua script_time_upload_to_PVoutput.lua
lua: script_time_upload_to_PVoutput.lua:83: attempt to index global 'otherdevices_svalues' (a nil value)
stack traceback:
script_time_upload_to_PVoutput.lua:83: in main chunk
[C]: in ?
this same sort of error is also there in
pi@minibian:~/domoticz/scripts/lua$ lua script_device_calculate_consumption.lua
lua: script_device_calculate_consumption.lua:51: attempt to index global 'otherdevices_svalues' (a nil value)
stack traceback:
script_device_calculate_consumption.lua:51: in main chunk
[C]: in ?
Code: Select all
-- /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 = "Zonnenpanelen" -- Device name of the Generated energy
local EnergyDeviceName = "Power" -- Name of the energy device that shows imported and exported energy
local ConsumptionIDX = 15 -- 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
-- Imported Exported
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
Code: Select all
-- /home/pi/domoticz/scripts/lua/script_time_upload_to_PVoutput.lua
-- This script collects the values below from Domoticz
-- * The Power generation, energy generation and voltage from a Solar power inverter
-- * The temperature from a outside temperature sensor
-- * The Power consumption and energy consumption which is calculated in another Lua script
-- And uploads all of the values to a PVoutput account.
--
-- For more information about PVoutput, see their user documentation on http://www.pvoutput.org/help.html
----------------------------------------------------------------------------------------------------------
-- Domoticz IDX of devices
----------------------------------------------------------------------------------------------------------
local GenerationDeviceName = "Zonnenpanelen" -- Device name of the Generated energy
local ConsumptionDeviceName = "consumption" -- Name of the energy device that shows calculated Consumption
local VoltageDeviceName = "Volt uac1" -- Name of the voltage device that shows voltage of the inverter
local TemperatureDeviceName = "Temperature SMA" -- Name of the temperature device that shows outside temperature
----------------------------------------------------------------------------------------------------------
-- PVoutput parameters
----------------------------------------------------------------------------------------------------------
local PVoutputApi = "xxxxx" -- Your PVoutput api key
local PVoutputSystemID = "xx" -- Your PVoutput System ID
local PVoutputPostInterval = 5 -- The number of minutes between posts to PVoutput (normal is 5 but when in donation mode it's max 1)
local PVoutputURL = '://pvoutput.org/service/r2/addstatus.jsp?key=' -- The URL to the PVoutput Service
----------------------------------------------------------------------------------------------------------
-- Require parameters
----------------------------------------------------------------------------------------------------------
local http = require("socket.http")
----------------------------------------------------------------------------------------------------------
-- Script parameters
----------------------------------------------------------------------------------------------------------
EnergyGeneration = 0 -- v1 in Watt hours
PowerGeneration = 0 -- v2 in Watts
EnergyConsumption = 0 -- v3 in Watt hours
PowerConsumption = 0 -- v4 in Watts
CurrentTemp = 0 -- v5 in celcius
Voltage = 0 -- v6 in volts
c1 = 1 -- c1 = 0 when v1 is today's energy. c1 = 1 when v1 is lifetime energy.
Debug = "NO" -- Turn debugging on ("YES") or off ("NO")
----------------------------------------------------------------------------------------------------------
-- Lua Functions
----------------------------------------------------------------------------------------------------------
function UploadToPVoutput(self)
b, c, h = http.request("http" .. PVoutputURL .. PVoutputApi .. "&sid=".. PVoutputSystemID .. "&d=" .. os.date("%Y%m%d") .. "&t=" .. os.date("%H:%M") ..
"&v1=" .. EnergyGeneration .. "&v2=" .. PowerGeneration .. "&v3=" .. EnergyConsumption .. "&v4=" .. PowerConsumption .. "&v5=" .. CurrentTemp .. "&v6=" .. Voltage .. "&c1=" .. c1 )
if b=="OK 200: Added Status" then
print(" -- Current status successfully uploaded to PVoutput.")
else
print(" -- " ..b)
end
print(" -- Energy generation (v1) = ".. EnergyGeneration .. " Wh")
print(" -- Power generation (v2) = " .. PowerGeneration .. " W")
print(" -- Energy consumption (v3) = " .. EnergyConsumption .. " Wh")
print(" -- Power consumption (v4) = " .. PowerConsumption .. " W")
print(" -- Current temperature (v5) = " .. CurrentTemp .. " C")
print(" -- Voltage (v6) = " .. Voltage .. "V")
print(" -- Cumulative Flag (c1) = " .. c1 .. "")
end
function update(device, id, power, energy, index)
commandArray[index] = {['UpdateDevice'] = id .. "|0|" .. power .. ";" .. energy}
end
----------------------------------------------------------------------------------------------------------
-- CommandArray
----------------------------------------------------------------------------------------------------------
commandArray = {}
time = os.date("*t")
if PVoutputPostInterval>1 then
TimeToGo = PVoutputPostInterval - (time.min % PVoutputPostInterval)
print('Time to go before upload to PVoutput: ' ..TimeToGo.. " minutes")
end
if((time.min % PVoutputPostInterval)==0)then
-- Generated
PowerGeneration, EnergyGeneration = otherdevices_svalues[GenerationDeviceName]:match("([^;]+);([^;]+)")
if Debug=="YES" then
print(" ---- The total generated energy is " .. EnergyGeneration .. " Wh");
print(" ---- The current generated power is " .. PowerGeneration .. " W");
end
-- Voltage
Voltage = otherdevices_svalues[VoltageDeviceName] :match("([^;]+)")
if Debug=="YES" then
print(" ---- The voltage of the inverter is " .. Voltage .. " V");
end
-- Temperature
CurrentTemp = otherdevices_svalues[TemperatureDeviceName]:match("([^;]+)")
if Debug=="YES" then
print(" ---- The outside temperature is " .. CurrentTemp .. " C.");
end
-- Consumption
PowerConsumption, EnergyConsumption = otherdevices_svalues[ConsumptionDeviceName]:match("([^;]+);([^;]+)")
if Debug=="YES" then
print(" ---- The total consumed energy is " .. EnergyConsumption .. " Wh");
print(" ---- The current consumed power is " .. PowerConsumption .. " W");
end
-- Upload data to PVoutput
UploadToPVoutput()
end
return commandArray
i copied the scripting files multiple times with notepad ++ from the wiki just to make sure i didn`t made a copy failure
but i just cant seem to figure this one out with my skills
maybe some package missing