Anyway to detect what tripped a device or see all the scene it belongs to?

I have one particular light that comes on a couple times a day and I can’t figure out what caused it to do so. Is there a way to detect what triggered it?

This might help…

http://forum.micasaverde.com/index.php/topic,15360.msg116759.html#msg116759

[quote=“akbooer, post:2, topic:197587”]This might help…

http://forum.micasaverde.com/index.php/topic,15360.msg116759.html#msg116759[/quote]

followed your instruction, installed datamine modified first line to json-dm lua ran just fine but my text come out with only scene: and blank from there on.

Ah, it may be that recent firmware encodes the response. I’ll try and take a look.

I forgot to mention I’m on ui5

I can replicate this error, although the code runs fine under openLuup.

Probably something, as expected, with encoded strings. Will dig further if you’re still interested.

OK, so this error arises from not finding the json module, so you need to make sure that you’re requiring it correctly.

You could run a little test code to ensure that you can find and use json.decode()

Thanks for looking into it, I also upload the dkjson file as well but that didn’t work either. How do I test for the json file?

Are you using AltUI? If not, why not? (It makes it easier to debug code, because you can use print statements.)

I had it installed but found that I never used it so I deleted it. I’ll reinstall it and see if there’s any useful things I can do to troubleshoot it.

installed alt ui and tried again and got this error

? 11/11/2017, 10:32:11 AM Code execution failed
? 11/11/2017, 10:32:11 AM Lua Command execution on vera failed.()

below is what I have. Basically a copy and paste of your script with the added json-dm. Tried this on the code from the first post as well

[code]-- Build list of scenes with trigger devices and actioned devices

– version = “2013.11.14 @akbooer

json = require “json-dm”

– sceneBlog (), build list of scenes with trigger devices and actioned devices
– as posted to http://forum.micasaverde.com/index.php/topic,15360.msg116759.html#msg116759
local function sceneBlog (filename)

-- classic map utility - cf. pairs
local function map (Xs , fct)   -- map function to each item in table, returns {} if none
	local table = {}
	for i,x in pairs (Xs or {}) do table[i] = fct(x) end
	return table 
end

-- classic list flatten
local function flatten (array)
	local l = {}
	local function add_item (x) l[#l+1] = x; end
	for _,x in ipairs(array) do
		if type(x) == "table" then
			map(flatten(x), add_item )
		else
			add_item (x)
		end
	end
	return l
end

-- set operations, only what we need here: add, list 
local function set()								-- create new empty set
	local s = {}		-- holder for set
	return {
		add  = function (x) s[x] = x; end, 			-- add element to the set
		list = function ( ) 						-- return sorted list of set elements
			local l = {}; 
			for i in pairs(s) do l[#l+1] = i; end; 
			table.sort (l);
			return l; end
		}
end

-- formatting functions for printing data structure
local function format_devices(d)
	return map (d, function (x) return string.format ('[%d] %s', x, (luup.devices[tonumber(x)] or {description = ''}).description); end)
end

local function format_names(d)
	return map (d, function (x) return x.name or ''; end)
end

local function format_timers (t)
	t = t or {}
	if #t == 0 then return '' end
	return table.concat {'   schedules = {', table.concat(format_names(t), ', '), '}\n' }
end

local function format_triggers (t)
	if #t == 0 then return '' end
	return table.concat {'   triggers = {', table.concat(format_devices(t), ', '), '}\n' }
end

local function format_actions (t)
	if #t == 0 then return '' end
	return table.concat {'   actions = {', table.concat(format_devices(t), ', '), '}\n' }
end

local function format_lua (lua)
	if not lua then return '' end
	return '   Lua code: \n' .. lua 
end

local function scene_tostring (s)
	return  ("\n[%d] '%s' \n%s%s%s%s "): format (s.id, s.name, 
				format_timers(s.timers), format_triggers(s.triggers), format_actions(s.actions), format_lua(s.lua) )
end

-- functions to build data structure of devices triggering scenes, and actioned by scenes
local function get_device (x) return x.device end

local function trigger_devices (t)
	local trigger_set = set()  					-- create a new empty set (of device numbers)
	local device_list = map (t, get_device)		-- create list of device numbers
	map (device_list, trigger_set.add)			-- add elements to set
	return trigger_set.list ()					-- return sorted list of set members
end

local function action_devices (groups)
	local action_set = set() 					-- create a new empty set (of device numbers)
	local function actions (g) return map (g.actions, get_device) end
	local action_list = map (groups, actions)	-- create list of actions
	map (flatten(action_list), action_set.add)	-- mash together all the action device lists
	return action_set.list ()					-- return sorted list of set members
end

local function attached_devices (sceneNo) 
	local _, s = luup.inet.wget("http://127.0.0.1:3480/data_request?id=scene&action=list&scene=" .. sceneNo)
	if s == "ERROR" then return end
	
	s = json.decode(s)
	s.triggers = trigger_devices (s.triggers)		-- restructure slightly
	s.actions  = action_devices  (s.groups) 

	return setmetatable (s, { __tostring = scene_tostring} )
end

-- sceneBlog ()

local file = io.open(filename, "w")

if file then
	luup.log ("Opening: " .. filename)
	file:write '\nSCENES: \n\n '

	for i in pairs (luup.scenes) do
		local scene_devices = attached_devices (i)
		file:write( tostring(scene_devices) )
	end
	
	file:close()
	luup.log ("Closing: " .. filename)	
else
	luup.log ("Failed to open: " .. filename)
end	

end

– main: build and write the database

sceneBlog “/www/scene_devices.txt”
[/code]

OK, that’s very surprising…

I cut and pasted the code you posted, changed the json module (because I haven’t installed dataMine), and it works just fine.

The error message ‘Code execution failed’ means that the code never even got to run, so there must be something strange going on. Perhaps a problem with hidden control characters (line endings?) or an editor changing things like ASCII quotes to apostrophes.

Can you just try:

json = require "json-dm"
print (pretty(json))

From my module, I get:

{
  decode = function: 0x1183ba0,
  default = {
    huge = "8.88e888",
    max_array_length = 1000
  },
  encode = function: 0x1184350,
  version = "2013.11.06 @akbooer"
}

same result…

I did a restore to the vera before all this, tried to upload the dkjson file in your post but it’s not sticking. I have ecobee and smart switch apps which both appears to use a json file. Do you know how I can try using those instead of datamine?

Under AltUI > Misc > OS Command there is a ‘Find Json’ button, which should be able to find every file with that in the name (not the extension)

FWIW after I restore I tried installing DM2 hence the json-dm2 shows below which I also tried same error.

/etc/cmh-ludl/L_SmartSwitch_dkjson.lua
/etc/cmh-ludl/L_ecobee_dkjson.lua
/overlay/etc/cmh-ludl/L_SmartSwitch_dkjson.lua
/overlay/etc/cmh-ludl/L_ecobee_dkjson.lua
/overlay/usr/lib/lua/json-dm2.lua
/overlay/usr/lib/lua/ihjson.lua
/usr/lib/lua/json-dm2.lua
/usr/lib/lua/ihjson.lua

You ARE running this under the AltUI > Misc > Lua Code Test window?

Yes tried both ui

Well, I have to say that I don’t understand this. There’s obviously something basic we’re missing and it’s nothing to do with the code which is not even getting to the point of running.

Have you tried a different browser? I can only assume, as I said before, that rogue characters are somehow getting in there and mucking up the basic parsing of the code.

Thanks for all your help, I also have a Vera lite that has only 1 item on it I will test it when I get home.

Just to give a little updates… i was able to run this on my Veralite in UI7 with populated results.

On the Vera 3 Ui5 that I’ve been having issues with, I can run it with no error in ALTUI now but still coming up with a blank screen. :frowning: I’m gonna keep trying. At least we know it’s not the script but most likely my Vera.