Once in a while we can find a device doing something we don’t expect. When someone asks for help with this, it is often suggested that it could be caused by a forgotten or inadvertent scene action. This is a common cause but it can be very time-consuming to work through a lot of scenes looking for rogue actions - and they are easily missed.
Another occasional scenario is when a device dies and has to be replaced. This will require all scenes that include actions for the device to be updated to the new one. Now which scenes are those?
The following Lua code will search through your scenes and list all of them that contain actions that affect the specified device number. It can be run in APPS → Develop Apps → Test Luup code (Lua) or using LuaTest. Set the required device number in line 4. The result can be viewed in a browser by entering /sceneactions.txt where is the IP address of your Vera (without the <>).
[code]-- List all scenes with actions that affect the specified device ID
– Result may be viewed at /sceneactions.txt
local deviceNum = 99 – Set to required device ID
local file = io.open(“/www/sceneactions.txt”, “w+”)
file:write(“Scene actions affecting device: " .. deviceNum)
local err,resp = luup.inet.wget(“127.0.0.1:3480/data_request?id=user_data&output_format=xml”)
if err == 0 then
local ptrs = string.find(resp,”<“,1,true)
local ptre = 0
local ptrm = #resp
local inScenes = false
local inAction = false
local sName = “”
local service = “”
local action = “”
while (ptrs ~= nil) do
ptre = string.find(resp,”>“,ptrs,true)
local line = string.sub(resp,ptrs,ptre)
if inScenes then
if string.match(line,”^</scenes") then break end
if inAction then
if string.match(line,“^</action”) then
inAction = false
else
if string.match(line,“^<argument “) then
argument,value = string.match(line,“name="(.-)".-value="(.-)"”)
file:write(” “..argument..”=”..value)
end
end
else
if string.match(line,“^<scene name=”) then
sName = string.match(line,“name="(.-)"”)
elseif string.match(line,“^<action device="”..deviceNum..“"”) then
service,action = string.match(line,“service="(.-)".-action="(.-)"”)
file:write(“\n\nScene: “..sName..”\nServiceId: “..service..”\nAction: “..action)
inAction = true
end
end
else
if string.match(line,”^<scenes”) then inScenes = true end
end
ptrs = string.find(resp,“<”,ptre+1,true)
end
else
file:write(“\n\nCannot read user_data. Error: " .. err)
end
file:write(”\n\nEnd")
file:close()[/code]
If one of your devices shuffles off its mortal coil, becomes an ex-device or ceases to be *, you will need to change all the scene triggers that used it and create new ones for the replacement device. Now what scenes were they?
The following Lua code will search through your scenes and list all of them that contain triggers from the specified device number. It can be run in APPS → Develop Apps → Test Luup code (Lua) or using LuaTest. Set the required device number in line 4. The result can be viewed in a browser by entering /scenetriggers.txt where is the IP address of your Vera (without the <>).
[code]-- List all scenes with triggers from the specified device ID
– Result may be viewed at /scenetriggers.txt
local deviceNum = 61 – Set to required device ID
local file = io.open(“/www/scenetriggers.txt”, “w+”)
file:write(“Scene triggers from device: " .. deviceNum)
local err,resp = luup.inet.wget(“127.0.0.1:3480/data_request?id=user_data&output_format=xml”)
if err == 0 then
local ptrs = string.find(resp,”<“,1,true)
local ptre = 0
local ptrm = #resp
local inScenes = false
local sName = “”
while (ptrs ~= nil) do
ptre = string.find(resp,”>“,ptrs,true)
local line = string.sub(resp,ptrs,ptre)
if inScenes then
if string.match(line,”^</scenes") then break end
if string.match(line,“^<scene name=”) then
sName = string.match(line,“name="(.-)"”)
elseif string.match(line,“^<trigger .-device="”..deviceNum..“"”) then
name = string.match(line,“name="(.-)"”)
file:write(“\n\nScene: “..sName..”\nTrigger: “..name)
end
else
if string.match(line,”^<scenes”) then inScenes = true end
end
ptrs = string.find(resp,“<”,ptre+1,true)
end
else
file:write(“\n\nCannot read user_data. Error: " .. err)
end
file:write(”\n\nEnd")
file:close()[/code]
If you have not encountered the Monty Python Parrot sketch, this will make no sense. Replace with lost its magic smoke or quit working.
[quote=“Z-Waver, post:4, topic:180650”]@RexBeckett - Another fantastic bit of code from RexBeckett!
I feel that these two pieces should be combined into a single plugin. I also feel that this should be built into Vera…[/quote]
Thanks @Z-Waver. I’m reluctant to make this a plugin - it doesn’t really justify the 2MB memory cost. I shall give some thought to making it into an http handler if I can think of a few other tools to go with it. I could add it to LuaTest but, based on the number of downloads, that will not help many people.
I agree it should be part of Vera’s toolkit. Perhaps it will turn-up in UI7? :
Does this only report scenes or can it also report on PLEG conditions? These days I don’t have many scenes as such left. and I’m assuming that many people are also moving in this direction.
It looks like that plugin’s been a collaboration of work for a while now and its already got a number of http handlers /URLS listed (if that’s the correct term).
Therefore considering the great ideas/code you’ve done here and with Lua Test, merging could help it become that Vera ‘must have’ tool-kit you alluded to earlier…
I’ve been using ZeroBraneStudio for my debugging and such. It works great.
I used you code to track down a scene that it turning on my patio TV (device id 312). The scene is 188. Ther my be some lua code somewhere that it call scene 188 when I don’t want it to. Is there a way to search through lua code for a scene # so I can see what is calling this scene?
Is there a way to search through lua code for a scene # so I can see what is calling this scene?
The short answer is no.
I did consider this when I was writing the code. The problem is that device numbers and scene numbers are often not hard-coded in the luup calls. They may be in global or local variables and they could be passed as function arguments. A simple scan of the Lua would not give an accurate answer.