Da wir jetzt eine HC3-LUA Kategorie haben stelle ich es mal hier ein.
So nebenbei habe ich die html-Ausgabe wieder aktiviert. (Kann man aber auf „false“ setzen.)
-- File : RoutingInfo.lua
-- Version : 0.1.7 - {20.02.2021}
-- nach einer Vorlage aus dem Fibaro Forum (thanks @tinmann)
-- Converted for HC3 Buid by Ändy, Gerhard, Jeep
--
-- Abkürzung : working route respose time = WRRT
local Debug = function ( color, message )
fibaro.debug(string.format('<%s style="font-family:Courier New;font-size:20px;color:%s;">%s', "span", color, message, "span"))
end
local function printf(...) fibaro.debug(tag, string.format(...)) end
local function getSNamebyID(sectionID)
--fibaro.debug (sectionID)
if tonumber(sectionID) > 0 then
local section = api.get("/sections/" .. tostring(sectionID))
return string.sub(tostring(section.name),1, 10)
end
return 'No section'
end
local function getSectionNameByDeviceID(DevID)
if DevID == nil then
return 'nil'
else
local sectionID = fibaro.getSectionID(DevID)
if sectionID == nil then
return 'nil'
else
return getSNamebyID(sectionID)
end
end
end
local function countc(s,c)
local n = 0
local _,n = s:gsub(c,"")
if (n==1) then r1h = r1h +1
elseif n==2 then r2h = r2h +1
elseif n==3 then r3h = r3h +1
elseif n==4 then r4h = r4h +1
end
return n
end
local filter = '/devices/?enabled=true&isPlugin=false'
local allDevices = api.get(filter)
local html = true
local output = ''
if (html == false) then d = true
elseif ( html == true) then d = false;
Debug('cyan','Daten werden im HTML Format ausgegeben - Bitte warten...')
end
local nn,r,nr=0,0,0
r1h,r2h,r3h,r4h=0,0,0,0
local n=0 --nur Geräte mit parentId = 1
-- Ab hier Ausgabe
if html then
print('<font size="2"><font color="green">---------------Starte Ausgabe---------------------</font>' )
else
print("----------------Starte Ausgabe---------------------")
end
for id = 1, #allDevices do
if (allDevices[id].parentId == 1 ) then
local mDevID = allDevices[id].id
if mDevID ~= nil then
local name = fibaro.getName(mDevID+1)
if name == nil then
name = "No Name"
end
if(tonumber(allDevices[id+1].roomID) == 0) then
room = 'No room';
else
room = fibaro.getRoomNameByDeviceID(allDevices[id+1].id)
end
local section = getSectionNameByDeviceID(mDevID+1)
if section == nil then
section = "No Name"
end
n= n+1
-- api.post('/devices/'.. mDevID ..'/action/getNeighborList')
thisDev = "Neighbours of device " .. mDevID ..') '..name ..' (' .. room .. '|' .. section .. ') : ' .. json.encode(fibaro.getValue(mDevID, "neighborList"))
if thisDev:find("%p[%p]") then
print('Device '.. name..'('..mDevID..')'.. ' hat keine Nachbarn')
nn = nn + 1
end
if html then output = "<pre>"..'<font size="2"><font color="yellow">'..output..thisDev.."</font> </pre>" end
if d then print(thisDev) end
local lwr = json.encode(fibaro.getValue(mDevID, "lastWorkingRoute"))
thisDevRoute = "Last working route used by device " .. mDevID .. " : " .. lwr
if thisDevRoute:find("%p[%p]") then
print('Device ' ..name..'('..mDevID..')'.. ' hat keine Routen')
nr = nr +1
end
if string.len(lwr) == 3 then
r = r +1
hops = " "
else
hops=countc(lwr,',')
end
if (hops == nil or hops==0) then hops = " " end
if html then output = "<pre>"..'<font size="2"><font color="yellow">'..output..thisDevRoute..' - hops: '..hops.."</font></pre>" end
if d then print( thisDevRoute.." - hops: "..hops) end
thisDevTimeStamp = tonumber(fibaro.getValue(mDevID, "lastWorkingRouteResponseTimestamp"))
thisDevLWRRTime = "Last WRRT for device ".. mDevID .. ': '.. (os.date("%X - %d %b. %y", thisDevTimeStamp ))
if html then output = "<pre>"..'<font size="2"><font color="yellow">'..output..thisDevLWRRTime.."</font> </pre>"..n..'-- <br />' end
if d then print( thisDevLWRRTime) end
if d then print( n..'--') end
--n =n+1
if d then print ('--------------------------------------') end
fibaro.sleep(100)
end
end
end --for
print(output)
fibaro.trace("SCENE"..sceneId, 'Ausgabe vom '..os.date('%d.%m.%Y')..' über '..n.. ' devices.')
printf("Direkte routen, [1] zum HC2: "..r)
printf("Routen über 1 hop, zum HC2 : "..r1h)
printf("Routen über 2 hops zum HC2 : "..r2h)
printf("Routen über 3 hops zum HC2 : "..r3h)
printf("Routen über 4 hops zum HC2 : "..r4h)
printf("-------------------------------")
printf("Devices ohne Nachbarn [] : "..nn)
printf("Devices ohne routen [] : "..nr)