i've find this Lua script (sorry I don't remember where) for summing consumption from each sensor in one dummy sensor.
This script work fine but sometimes (every minutes) generate an error in LOG on the line 180.
Someone can help me?
Script
Code: Select all
----------------------------------------------------------------------------------------------------------
-- Domoticz IDX and names of the needed devices
----------------------------------------------------------------------------------------------------------
local DeviceName1 = "Consumo Luce Specchio Bagno"
local DeviceName2 = "Consumo Luce Bagno"
local DeviceName3 = "Consumo Luci Scale"
local DeviceName4 = "Consumo Luci Cucina"
local DeviceName5 = "Consumo Luci Parete Sala"
local DeviceName6 = "Consumo Lampada Sale"
local DeviceName7 = "Consumo Luci Camera"
local DeviceName8 = "Consumo Frigo"
local DeviceName9 = "Consumo Lavatrice"
local DeviceName10 = "Consumo Lavastoviglie"
local DeviceName11 = "Consumo HT Camera"
local DeviceName12 = "Consumo TV Sala"
local DeviceName13 = "Consumo HT Sala"
local DeviceName14 = "Consumo Cam Frigo"
local DeviceName15 = "Consumo Cam Pianta"
local DeviceName16 = "Consumo Cam Stufa"
local ConsumptionIDX = 538 -- IDX of the energy device that shows calculated Consumption
local ConsumptionDeviceName = "Consumo Totale" -- Name of the energy device that shows calculated Consumption
----------------------------------------------------------------------------------------------------------
-- Script parameters
----------------------------------------------------------------------------------------------------------
Energy1 = 0 -- in Watt hours
Power1 = 0 -- in Watts
Energy2 = 0 -- in Watt hours
Power2 = 0 -- in Watts
Energy3 = 0 -- in Watt hours
Power3 = 0 -- in Watts
Energy4 = 0 -- in Watt hours
Power4 = 0 -- in Watts
Energy5 = 0 -- in Watt hours
Power5 = 0 -- in Watts
Energy6 = 0 -- in Watt hours
Power6 = 0 -- in Watts
Energy7 = 0 -- in Watt hours
Power7 = 0 -- in Watts
Energy8 = 0 -- in Watt hours
Power8 = 0 -- in Watts
Energy9 = 0 -- in Watt hours
Power9 = 0 -- in Watts
Energy10 = 0 -- in Watt hours
Power10 = 0 -- in Watts
Energy11 = 0 -- in Watt hours
Power11 = 0 -- in Watts
Energy12 = 0 -- in Watt hours
Power12 = 0 -- in Watts
Energy13 = 0 -- in Watt hours
Power13 = 0 -- in Watts
Energy14 = 0 -- in Watt hours
Power14 = 0 -- in Watts
Energy15 = 0 -- in Watt hours
Power15 = 0 -- in Watts
Energy16 = 0 -- in Watt hours
Power16 = 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 = {}
Power1, Energy1 = otherdevices_svalues[DeviceName1]:match("([^;]+);([^;]+)")
if Debug=="YES" then
print(" ----- ".. DeviceName1 .. "Power = " .. Power1 .. " W");
print(" ----- ".. DeviceName1 .. "Energy = " .. Energy1 .. " Wh");
end
Power2, Energy2 = otherdevices_svalues[DeviceName2]:match("([^;]+);([^;]+)")
if Debug=="YES" then
print(" ----- ".. DeviceName2 .. "Power = " .. Power2 .. " W");
print(" ----- ".. DeviceName2 .. "Energy = " .. Energy2 .. " Wh");
end
Power3, Energy3 = otherdevices_svalues[DeviceName3]:match("([^;]+);([^;]+)")
if Debug=="YES" then
print(" ----- ".. DeviceName3 .. "Power = " .. Power3 .. " W");
print(" ----- ".. DeviceName3 .. "Energy = " .. Energy3 .. " Wh");
end
Power4, Energy4 = otherdevices_svalues[DeviceName4]:match("([^;]+);([^;]+)")
if Debug=="YES" then
print(" ----- ".. DeviceName4 .. "Power = " .. Power4 .. " W");
print(" ----- ".. DeviceName4 .. "Energy = " .. Energy4 .. " Wh");
end
Power5, Energy5 = otherdevices_svalues[DeviceName5]:match("([^;]+);([^;]+)")
if Debug=="YES" then
print(" ----- ".. DeviceName5 .. "Power = " .. Power5 .. " W");
print(" ----- ".. DeviceName5 .. "Energy = " .. Energy5 .. " Wh");
end
Power6, Energy6 = otherdevices_svalues[DeviceName6]:match("([^;]+);([^;]+)")
if Debug=="YES" then
print(" ----- ".. DeviceName6 .. "Power = " .. Power6 .. " W");
print(" ----- ".. DeviceName6 .. "Energy = " .. Energy6 .. " Wh");
end
Power7, Energy7 = otherdevices_svalues[DeviceName7]:match("([^;]+);([^;]+)")
if Debug=="YES" then
print(" ----- ".. DeviceName7 .. "Power = " .. Power7 .. " W");
print(" ----- ".. DeviceName7 .. "Energy = " .. Energy7 .. " Wh");
end
Power8, Energy8 = otherdevices_svalues[DeviceName8]:match("([^;]+);([^;]+)")
if Debug=="YES" then
print(" ----- ".. DeviceName8 .. "Power = " .. Power8 .. " W");
print(" ----- ".. DeviceName8 .. "Energy = " .. Energy8 .. " Wh");
end
Power9, Energy9 = otherdevices_svalues[DeviceName9]:match("([^;]+);([^;]+)")
if Debug=="YES" then
print(" ----- ".. DeviceName9 .. "Power = " .. Power9 .. " W");
print(" ----- ".. DeviceName9 .. "Energy = " .. Energy9 .. " Wh");
end
Power10, Energy10 = otherdevices_svalues[DeviceName10]:match("([^;]+);([^;]+)")
if Debug=="YES" then
print(" ----- ".. DeviceName10 .. "Power = " .. Power10 .. " W");
print(" ----- ".. DeviceName10 .. "Energy = " .. Energy10 .. " Wh");
end
Power11, Energy11 = otherdevices_svalues[DeviceName11]:match("([^;]+);([^;]+)")
if Debug=="YES" then
print(" ----- ".. DeviceName11 .. "Power = " .. Power11 .. " W");
print(" ----- ".. DeviceName11 .. "Energy = " .. Energy11 .. " Wh");
end
Power12, Energy12 = otherdevices_svalues[DeviceName12]:match("([^;]+);([^;]+)")
if Debug=="YES" then
print(" ----- ".. DeviceName12 .. "Power = " .. Power12 .. " W");
print(" ----- ".. DeviceName12 .. "Energy = " .. Energy12 .. " Wh");
end
Power13, Energy13 = otherdevices_svalues[DeviceName13]:match("([^;]+);([^;]+)")
if Debug=="YES" then
print(" ----- ".. DeviceName13 .. "Power = " .. Power13 .. " W");
print(" ----- ".. DeviceName13 .. "Energy = " .. Energy13 .. " Wh");
end
Power14, Energy14 = otherdevices_svalues[DeviceName14]:match("([^;]+);([^;]+)")
if Debug=="YES" then
print(" ----- ".. DeviceName14 .. "Power = " .. Power14 .. " W");
print(" ----- ".. DeviceName14 .. "Energy = " .. Energy14 .. " Wh");
end
Power15, Energy15 = otherdevices_svalues[DeviceName15]:match("([^;]+);([^;]+)")
if Debug=="YES" then
print(" ----- ".. DeviceName15 .. "Power = " .. Power15 .. " W");
print(" ----- ".. DeviceName15 .. "Energy = " .. Energy15 .. " Wh");
end
Power16, Energy16 = otherdevices_svalues[DeviceName16]:match("([^;]+);([^;]+)")
if Debug=="YES" then
print(" ----- ".. DeviceName16 .. "Power = " .. Power16 .. " W");
print(" ----- ".. DeviceName16 .. "Energy = " .. Energy16 .. " Wh");
end
-- Calculate consumption
PowerConsumption = Power1 + Power2 + Power3 + Power4 + Power5 + Power6 + Power7 + Power8 + Power9 + Power10 + Power11 + Power12 + Power13 + Power14 + Power15 + Power16
if Debug=="YES" then
print(" ----- PowerConsumption = " .. PowerConsumption .. " W");
end
EnergyConsumption = Energy1 + Energy2 + Energy3 + Energy4 + Energy5 + Energy6 + Energy7 + Energy8 + Energy9 + Energy10 + Energy11 + Energy12 +Energy13 + Energy14 + Energy15 + Energy16
if Debug=="YES" then
print(" ----- EnergyConsumption = " .. EnergyConsumption .. " Wh");
end
-- Update comsumption device in Domoticz
if devicechanged[DeviceName1] or devicechanged[DeviceName2] or devicechanged[DeviceName3] or devicechanged[DeviceName4] or devicechanged[DeviceName5] or devicechanged[DeviceName6] or devicechanged[DeviceName7] or devicechanged[DeviceName8] or devicechanged[DeviceName9] or devicechanged[DeviceName10] or devicechanged[DeviceName11] or devicechanged[DeviceName12] or devicechanged[DeviceName13] or devicechanged[DeviceName14] or devicechanged[DeviceName15] or devicechanged[DeviceName16] then
update(ConsumptionDeviceName, ConsumptionIDX, PowerConsumption, EnergyConsumption,1)
end
return commandArray
Code: Select all
2017-09-06 12:13:00.144 Error: EventSystem: in Consumo Totale: [string "---------------------------------------------..."]:180: attempt to index global 'devicechanged' (a nil value)