full devices reset
-
This is slightly tricky, partly because it's at least three years since I looked at this, and also because some of the ZWay devices are subsumed into single Luup devices and others are split into separate children.
My philosophy, currently, is not to change the plugin (since I can't easily test it) but to provide a script to run which will make the changes.
You also have a ZWay "global room" which doesn't get uniquely mapped into any single openLuup room...
-
Oh yes, it just runs in the openLuup LuaTest window.
Before I let you loose on it, there are a couple of tweaks needed. I’ve used the ZWay devices file you sent, obviously, and put it into the cmh-ludl folder so that the script can find it. Is that a reasonable mode of working?
Otherwise, I could get it to pick up the info from the bridge itself, but then I’d need to make some changes to that, and an update to openLuup too. Not a huge deal, I hope, but, again, I’m not able to test it.
Either way, you’d need to ensure that you had a backup of your latest user_data.json, in case of emergencies.
-
OK, so running this in LuaTest should (if I modified the bridge correctly) provide the same listing as I sent previously. It should NOT make any changes to the system.
-- script to rename ZWay devices in openLuup local json = require "openLuup.json" local zway = luup.openLuup.find_device {device_type = "ZWay"} local DEVS = luup.devices[zway].environment.DEVS local Offset = luup.variable_get("urn:akbooer-com:serviceId:ZWay1", "Offset", zway) -- lookup table for existing Luup rooms local function room_index() local idx = {} for i,n in pairs(luup.rooms) do idx[i] = n idx[n] = i end return idx end -- Luup device numbers in running system, indexed by altid local function luup_devNos(block) block = tonumber(block) local devs = {} for i,d in pairs(luup.devices) do if i > block then local id = d.id devs[id] = i end end return devs end -- ZWay devices: ids, names, locations local function zDevs(devices) local devs = {} for i, d in ipairs(devices) do local id = d.id: match "ZWayVDev_zway_(.+)" or '?' local shortId = id: match "^%d+%-%d+" local shortId = id: match "^(%d+%-%d)%-%d+$" -- print(id, shortId) devs[i] = {id = id, shortId = shortId, roomName = d.locationName, name = d.metrics.title} end return devs end -- Start here local D = DEVS local rename = "[%d] %45s -> %-s" local placename = "%s / '%s'" local devNos = luup_devNos(Offset) local zdevs = zDevs(D) local rooms = room_index() for i, d in ipairs(zdevs) do local id = d.id local name = d.name local shortId = d.shortId local roomName = d.roomName local dno = devNos[shortId] or devNos[id] if (dno) then local dev = luup.devices[dno] local oldName = dev.description local oldRoom = rooms[tonumber(dev.attributes.room)] roomName = rooms[roomName] and roomName or oldRoom -- leave in place if new room not found newRoom = roomName ~= oldRoom newName = name ~= oldName if newRoom or newName then print(rename:format(dno or 0, placename:format(oldRoom, oldName) , placename:format(roomName, name))) end end end
-
OK, here the modified script.
Change the file name and folder to your chosen place in line 3.
Again, this should just produce the listing, not make changes.-- script to rename ZWay devices in openLuup filename = "Des/DES_ZWay.json" -- change this to the right place local json = require "openLuup.json" local zway = luup.openLuup.find_device {device_type = "ZWay"} local DEVS = luup.devices[zway].environment.DEVS local Offset = luup.variable_get("urn:akbooer-com:serviceId:ZWay1", "Offset", zway) local function read_ZWay_data(filename) local f = io.open (filename) if not f then error "file not found" end local j = f: read "*a" f: close() local D = json.decode (j) return D.data.devices end -- lookup table for existing Luup rooms local function room_index() local idx = {} for i,n in pairs(luup.rooms) do idx[i] = n idx[n] = i end return idx end -- Luup device numbers in running system, indexed by altid local function luup_devNos(block) block = tonumber(block) local devs = {} for i,d in pairs(luup.devices) do if i > block then local id = d.id devs[id] = i end end return devs end -- ZWay devices: ids, names, locations local function zDevs(devices) local devs = {} for i, d in ipairs(devices) do local id = d.id: match "ZWayVDev_zway_(.+)" or '?' local shortId = id: match "^(%d+%-%d)%-%d+$" devs[i] = {id = id, shortId = shortId, roomName = d.locationName, name = d.metrics.title} end return devs end -- Start here local D = read_ZWay_data (filename) local rename = "[%d] %45s -> %-s" local placename = "%s / '%s'" local devNos = luup_devNos(Offset) local zdevs = zDevs(D) local rooms = room_index() for i, d in ipairs(zdevs) do local id = d.id local name = d.name local shortId = d.shortId local roomName = d.roomName local dno = devNos[shortId] or devNos[id] if (dno) then local dev = luup.devices[dno] local oldName = dev.description local oldRoom = rooms[tonumber(dev.attributes.room)] roomName = rooms[roomName] and roomName or oldRoom -- leave in place if new room not found newRoom = roomName ~= oldRoom newName = name ~= oldName if newRoom or newName then print(rename:format(dno or 0, placename:format(oldRoom, oldName) , placename:format(roomName, name))) end end end