Voici l'adaptation pour ceux qui comme moi sont restés en 3.600.
A placer dans un bouton d'un Virtual Device.
Récupération du résultat dans la fenêtre Debug du bouton.
local dead = true -- true pour exporter les devices morts
local excludeType = {"weather", "HC_user", "iOS_device"}
local excludeID = {}
-- Initiate connection with HC2
HC2 = Net.FHttp("127.0.0.1", 11111)
response ,status, errorCode = HC2:GET("/api/devices")
devicesJSon = json.decode(response)
local devices = {}
local names = {}
local rooms = {}
function addName(name, roomname)
if (type(names[name]) == "nil") then
names[name] = true
return name
else
return addName(name.."_"..roomname, roomname)
end
end
function getRooms()
response ,status, errorCode = HC2:GET("/api/rooms")
roomsJSon = json.decode(response)
rooms[0] = "inconnu"
for k, v in ipairs(roomsJSon) do
rooms[v.id] = v.name
end
end
function rename(name, roomname)
local name = name:upper():gsub("[éêèë]", "E"):gsub("EE", "E"):gsub("[ûüù]", "U"):gsub("UU", "U"):gsub("[àâä]", "A"):gsub("AA", "A"):gsub("[öô]", "O"):gsub("OO", "O"):gsub("[îï]", "I"):gsub("II", "I"):gsub("%W", "_")
local roomname = roomname:upper():gsub("[éêèë]", "E"):gsub("EE", "E"):gsub("[ûüù]", "U"):gsub("UU", "U"):gsub("[àâä]", "A"):gsub("AA", "A"):gsub("[öô]", "O"):gsub("OO", "O"):gsub("[îï]", "I"):gsub("II", "I"):gsub("%W", "_")
return addName(name, roomname)
end
getRooms()
for k, v in pairs(devicesJSon) do
local doit = (dead or not v.dead)
if (doit) then
for h, w in pairs(excludeType) do
if (v.type == w) then
doit = false
end
end
if (doit) then
for h, w in pairs(excludeID) do
if (v.id == w) then
doit = false
end
end
end
end
if (doit) then
table.insert(devices, v)
end
end
table.sort(devices, function(a, return a.roomID<b.roomID end)
local result = "<BR><BR>-- IDs générés le : " .. os.date("%d/%m/%y à%X")
local room = -1
local lastinfo = "";
result = result .. "<BR><BR>local id = {"
for k, v in ipairs(devices) do
if (room ~= v.roomID) then
room = v.roomID
result = result .. "<BR>--"..rooms[v.roomID].."<BR>"
end
lastinfo = rename(v.name, rooms[v.roomID])
result = result .. lastinfo .. " = " .. v.id .. ", "
end
result = result .. "<BR>}"
result = result .. "<BR>"
result = result .. "<BR>-- usage :"
result = result .. "<BR>-- fibaro:getValue(id[\""..lastinfo .."\"], \"value\")"
result = result .. "<BR>-- GEA.add(id[\""..lastinfo .."\"], 30, \"\")"
-- print(result)
fibaro:debug(result)