commandArray = {} local function updatenum(dev, value1) local cmd = string.format("%f|0|%f", otherdevices_idx[dev], value1) table.insert (commandArray, { ['UpdateDevice'] = cmd } ) end for deviceName,deviceValue in pairs(devicechanged) do for fase=1, 3, 1 do if (deviceName=='Usage L'..fase) then stroom=deviceValue/otherdevices['Voltage L'..fase] if ( stroom~=0 ) then updatenum('Current L'..fase, stroom) end end if (deviceName=='Delivery L'..fase) then stroom=deviceValue/otherdevices['Voltage L'..fase] if ( stroom~=0 ) then updatenum('Current L'..fase, -1*stroom) end end end end return commandArray