full devices reset
-
Just for fun, am I able to execute the script myself when I'm doing changes ?
-
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 I decided to update the bridge to make this a bit easier.
Please update to the latest development versions of both openLuup and ZWay.
Then I'll provide a test script to see if this pulls the relevant data correctly.
-
Done. I'm not on both dev version
-
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, I thought we should probably build up slowly, but went for broke.
Try just this in the LuaTest:
local zway = luup.openLuup.find_device {device_type = "ZWay"} local DEVS = luup.devices[zway].environment.DEVS print(pretty(DEVS))
-
-
Ah, I feared that would be the case…
..and ZWay is up and running OK? -
yeah of course
-
We could revert to reading the file, but if you’re not too much in a rush, then I’ll try to fix this.
-
nah no worries, I can copy the file... zway and openLuup is on the same machine, so it's pretty easy to copy the file
-
I can even make a symbolic link
-
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
-
it's working
-
-
OK, so this script SHOULD make the changes.
Ensure you have a backup user_data.json, change the filename as before, run the script, restart openLuup just to make sure everything is synched.
Let me know how it goes!
-- 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))) dev: rename(newName and name, newRoom and roomName) end end end
-
The only last thing that's not working properly in openLuup since a while, it's the plugin RulesEngine that can't save changes in rules.
Not sure if it's related to ALTUI or openLuup and I've got no error in the openLuup logs
-
Yes to running the script again.
I looked a RulesEngine a while ago and never found out what was wrong, except that I think it’s a JavaScript issue, IIRC. Do you get any error in the browser log?
35/77