Spoiler
os.unloadAPI("sensors")
os.unloadAPI("sensorsUI")
os.loadAPI("/rom/apis/sensors")
os.loadAPI("/rom/apis/sensorsUI")
local writeAt=sensorsUI.writeAt
local sizeX, sizeY = term.getSize()
mon = peripheral.wrap("top")
mX, mY = mon.getSize()
text = {}
file = fs.open("sensorBorder.txt", "r")
repeat
    line = file.readLine()
    table.insert(text, line)
until line == nil
file.close()
mon.clear()
for i = 1, #text do
    mon.setCursorPos(1, i)
    mon.write(text[i])
end
function monW(x, y, str)
    mon.setCursorPos(x, y)
    mon.write(str)
end
function cp(c, x, y) if c==1 then term.clear() end term.setCursorPos(x,y) end
function select(x,y,title,tData)
    local r=nil;
    writeAt(x,y,title..": "..#tData);
    
    for i,v in pairs(tData) do
        writeAt(x+2,y+1+i,v);
    end
    
    local done=false;
    local isel=1;
    local vsel=1;
    writeAt(x+1,y+1+isel,"*")
    repeat
        evt,k = os.pullEvent()
        if evt=="key" then
            writeAt(x+1,y+1+isel," ")
            if k == 200    then    --up
                isel=isel-1
            elseif k== 208 then        --down
                isel = isel+1
            elseif k == 28 or k ==57 then    -- selection made    
                r = tData[isel];
                done=true;
            end
            if isel<1 then isel=#tData
            elseif isel > #tData then isel=1 end
            writeAt(x+1,y+1+isel,"*")
            
        end
    until done
    return r
end
term.clear()
-- Get and Select a sensor
Sensors = sensors.getSensors("right")
dataSensor = select(1, 1, "Available Sensors", Sensors)
-- Get and Select a probe
Probes = sensors.getProbes("right",dataSensor)
dataProbe = select(1, #Sensors+4, "Available Probes",Probes)
-- Get and Select a target
Targets = sensors.getAvailableTargetsforProbe("right",dataSensor,dataProbe)
--dataTarget = select(1, 1, "Available Targets", Targets)
while true do
Targets = sensors.getAvailableTargetsforProbe("right",dataSensor,dataProbe)
    total_max_storage = 0
    total_curr_storage = 0
    total_tier_BatBox = 0
    total_tier_MFE = 0
    total_tier_MFSU = 0
    local maxStorage = {}
    local currStorage = {}
    local tier = {}
    
    for i = 1, #Targets do
        dataReadings = sensors.getSensorReadingAsDict("right",dataSensor,Targets[i],dataProbe)
        table.insert(maxStorage, tonumber(dataReadings.maxStorage))
        table.insert(currStorage, tonumber(dataReadings.energy))
        table.insert(tier, tonumber(dataReadings.tier))
    end
    cp(1, 1, 1)
    for i = 1, #maxStorage do
        total_max_storage = total_max_storage + maxStorage[i]
    end
    for i = 1, #currStorage do
        total_curr_storage = total_curr_storage + currStorage[i]
    end
    for i = 1, #tier do
        if tier[i] == 1 then total_tier_BatBox = total_tier_BatBox + 1
        elseif tier[i] == 2 then total_tier_MFE = total_tier_MFE + 1
        elseif tier[i] == 3 then total_tier_MFSU = total_tier_MFSU + 1 end
    end
    if total_curr_storage > total_max_storage then total_curr_storage = total_max_storage end
    print("Total storage: "..total_max_storage)
    print("Total Current Storage: "..total_curr_storage)
    print("Tiers:nMFSU: "..total_tier_MFSU.."nMFE: "..total_tier_MFE.."nBatBox: "..total_tier_BatBox)
    monW(11, 11, total_max_storage)
    monW(11, 14, total_curr_storage)
    monW(45, 10, string.sub(total_tier_MFSU,-2))
    monW(45, 11, string.sub(total_tier_MFE,-2))
    monW(45, 12, string.sub(total_tier_BatBox,-2))
    sleep(10)
end