Discover IR codes for lost remote
-
Thanks so much @akbooer
I’ve run it a couple of times now, but it doesn’t seem to write to the file? It prints to the screen ok, but not to the write?
To get around that I’ve just been coping and pasting the print output into a text fileI’m close to the final piece now, I’ve captured and converted all the ‘POWER’ codes listed across all of those .csv files and I’d like to convert them into a table, or .csv, with their associated command name as the variable name, so I can then call them.
Example content of text1.txt (created by IrScrutinizer).
Power 0000 0070 0000 0032 0080 0040 0010 0010 0010 0030 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0030 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0030 0010 0010 0010 0010 0010 0030 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0030 0010 0010 0010 0030 0010 0010 0010 0030 0010 0030 0010 0030 0010 0030 0010 0010 0010 0010 0010 0030 0010 0010 0010 0030 0010 0030 0010 0010 0010 0030 0010 0030 0010 0030 0010 0ACD Power$1 0000 006C 0022 0002 015B 00AD 0016 0016 0016 0016 0016 0016 0016 0016 0016 0016 0016 0016 0016 0041 0016 0016 0016 0041 0016 0041 0016 0041 0016 0041 0016 0041 0016 0016 0016 0041 0016 0041 0016 0016 0016 0041 0016 0016 0016 0016 0016 0041 0016 0016 0016 0016 0016 0016 0016 0041 0016 0016 0016 0041 0016 0041 0016 0016 0016 0041 0016 0041 0016 0041 0016 05F7 015B 0057 0016 0E6C Power$2 0000 0068 0000 0022 0169 00B4 0017 0044 0017 0044 0017 0017 0017 0017 0017 0017 0017 0044 0017 0017 0017 0044 0017 0017 0017 0017 0017 0044 0017 0044 0017 0044 0017 0017 0017 0044 0017 0017 0017 0044 0017 0017 0017 0017 0017 0044 0017 0044 0017 0017 0017 0017 0017 0044 0017 0017 0017 0044 0017 0044 0017 0017 0017 0017 0017 0044 0017 0044 0017 0017 0017 0636
And I’m now trying to get that above into a more usable format, such a Lua array/table or maybe another .csv. Below is th3 code I’ve been working on to do that, but i’m not having much success doing the conversion.
function convertCodestoarray (filename) local lfs = require "lfs" local dir = "mnt/nas/vera/ircodes/" -- the path to the files print(dir .. filename) for filename in lfs.dir(dir) do if filename: match "%.txt$" then for line in io.lines(dir .. filename) do local params = "([^,]+)/n([^,]+)" local codename, prontocode = params local params = table.concat ({codename, prontocode}, ", ") print(params) for filename in lfs.dir(dir) do local file = io.open("powerircodes.csv", 'a') filename:write(params .. "\n") end end filename:close() end end end convertCodestoarray("text1.txt")
-
@parkerc said in Discover IR codes for lost remote:
it doesn’t seem to write to the file?
No, the file is opened in the wrong mode... you should have spotted that.
local file = io.open ("/www/powerircodes.txt", “wb”)
-
Thanks again @akbooer
Last ask
- how would you convert the IrScrutinizer created file (the one with all the converted ProntoCodes posted above) into a list/table/array/.csv - that I can then use with @alurker’s original post for his Broadlink irsender ?
-
@parkerc said in Discover IR codes for lost remote:
Last ask
Last answer...
A demo program that reads lines from a string with your data format and converts to tables of numbers.
local t = [[ Power 0000 0070 0000 0032 0080 0040 0010 0010 0010 0030 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0030 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0030 0010 0010 0010 0010 0010 0030 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0030 0010 0010 0010 0030 0010 0010 0010 0030 0010 0030 0010 0030 0010 0030 0010 0010 0010 0010 0010 0030 0010 0010 0010 0030 0010 0030 0010 0010 0010 0030 0010 0030 0010 0030 0010 0ACD Power$1 0000 006C 0022 0002 015B 00AD 0016 0016 0016 0016 0016 0016 0016 0016 0016 0016 0016 0016 0016 0041 0016 0016 0016 0041 0016 0041 0016 0041 0016 0041 0016 0041 0016 0016 0016 0041 0016 0041 0016 0016 0016 0041 0016 0016 0016 0016 0016 0041 0016 0016 0016 0016 0016 0016 0016 0041 0016 0016 0016 0041 0016 0041 0016 0016 0016 0041 0016 0041 0016 0041 0016 05F7 015B 0057 0016 0E6C Power$2 0000 0068 0000 0022 0169 00B4 0017 0044 0017 0044 0017 0017 0017 0017 0017 0017 0017 0044 0017 0017 0017 0044 0017 0017 0017 0017 0017 0044 0017 0044 0017 0044 0017 0017 0017 0044 0017 0017 0017 0044 0017 0017 0017 0017 0017 0044 0017 0044 0017 0017 0017 0017 0017 0044 0017 0017 0017 0044 0017 0044 0017 0017 0017 0017 0017 0044 0017 0044 0017 0017 0017 0636 ]] local function decode(line) local code = {} for n in line: gmatch "%x+" do code[#code+1] = tonumber(n,0x10) end return code end for l in t: gmatch "[^\n]+" do if l: match "^%x+" then print(pretty(decode(l))) end end
Gives this output:
{0,112,0,50,128,64,16,16,16,48,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,48,16,16,16,16,16,16,16,16,16,16,16,16,16,48,16,16,16,16,16,48,16,16,16,16,16,16,16,16,16,16,16,16,16,48,16,16,16,48,16,16,16,48,16,48,16,48,16,48,16,16,16,16,16,48,16,16,16,48,16,48,16,16,16,48,16,48,16,48,16,2765} {0,108,34,2,347,173,22,22,22,22,22,22,22,22,22,22,22,22,22,65,22,22,22,65,22,65,22,65,22,65,22,65,22,22,22,65,22,65,22,22,22,65,22,22,22,22,22,65,22,22,22,22,22,22,22,65,22,22,22,65,22,65,22,22,22,65,22,65,22,65,22,1527,347,87,22,3692} {0,104,0,34,361,180,23,68,23,68,23,23,23,23,23,23,23,68,23,23,23,68,23,23,23,23,23,68,23,68,23,68,23,23,23,68,23,23,23,68,23,23,23,23,23,68,23,68,23,23,23,23,23,68,23,23,23,68,23,68,23,23,23,23,23,68,23,68,23,23,23,1590}
-
Thanks @akbooer, although I’m ideally trying to get the output of that array to be something like this..
Power = "0000 0070 0000 0032 0080 0040 0010 0010 0010 0030 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0030 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0030 0010 0010 0010 0010 0010 0030 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0030 0010 0010 0010 0030 0010 0010 0010 0030 0010 0030 0010 0030 0010 0030 0010 0010 0010 0010 0010 0030 0010 0010 0010 0030 0010 0030 0010 0010 0010 0030 0010 0030 0010 0030 0010 0ACD" Power$1 = "0000 006C 0022 0002 015B 00AD 0016 0016 0016 0016 0016 0016 0016 0016 0016 0016 0016 0016 0016 0041 0016 0016 0016 0041 0016 0041 0016 0041 0016 0041 0016 0041 0016 0016 0016 0041 0016 0041 0016 0016 0016 0041 0016 0016 0016 0016 0016 0041 0016 0016 0016 0016 0016 0016 0016 0041 0016 0016 0016 0041 0016 0041 0016 0016 0016 0041 0016 0041 0016 0041 0016 05F7 015B 0057 0016 0E6C" Power$2 = "0000 0068 0000 0022 0169 00B4 0017 0044 0017 0044 0017 0017 0017 0017 0017 0017 0017 0044 0017 0017 0017 0044 0017 0017 0017 0017 0017 0044 0017 0044 0017 0044 0017 0017 0017 0044 0017 0017 0017 0044 0017 0017 0017 0017 0017 0044 0017 0044 0017 0017 0017 0017 0017 0044 0017 0017 0017 0044 0017 0044 0017 0017 0017 0017 0017 0044 0017 0044 0017 0017 0017 0636’
Running the script you chafed above retuned this...
LuaTest 1.7 Lua file: /etc/cmh-ludl/luatest.lua Results No errors Runtime: 55.4 ms Code returned: nil Print output { [1]=0, [2]=112, [3]=0, [4]=50, [5]=128, [6]=64, [7]=16, [8]=16, [9]=16, [10]=48, [11]=16, [12]=16, [13]=16, [14]=16, [15]=16, [16]=16, [17]=16, [18]=16, [19]=16, [20]=16, [21]=16, [22]=16, [23]=16, [24]=16, [25]=16, [26]=16, [27]=16, [28]=16, [29]=16, [30]=16, [31]=16, [32]=16, [33]=16, [34]=48, [35]=16, [36]=16, [37]=16, [38]=16, [39]=16, [40]=16, [41]=16, [42]=16, [43]=16, [44]=16, [45]=16, [46]=16, [47]=16, [48]=48, [49]=16, [50]=16, [51]=16, [52]=16, [53]=16, [54]=48, [55]=16, [56]=16, [57]=16, [58]=16, [59]=16, [60]=16, [61]=16, [62]=16, [63]=16, [64]=16, [65]=16, [66]=16, [67]=16, [68]=48, [69]=16, [70]=16, [71]=16, [72]=48, [73]=16, [74]=16, [75]=16, [76]=48, [77]=16, [78]=48, [79]=16, [80]=48, [81]=16, [82]=48, [83]=16, [84]=16, [85]=16, [86]=16, [87]=16, [88]=48, [89]=16, [90]=16, [91]=16, [92]=48, [93]=16, [94]=48, [95]=16, [96]=16, [97]=16, [98]=48, [99]=16, [100]=48, [101]=16, [102]=48, [103]=16, [104]=2765 } { [1]=0, [2]=108, [3]=34, [4]=2, [5]=347, [6]=173, [7]=22, [8]=22, [9]=22, [10]=22, [11]=22, [12]=22, [13]=22, [14]=22, [15]=22, [16]=22, [17]=22, [18]=22, [19]=22, [20]=65, [21]=22, [22]=22, [23]=22, [24]=65, [25]=22, [26]=65, [27]=22, [28]=65, [29]=22, [30]=65, [31]=22, [32]=65, [33]=22, [34]=22, [35]=22, [36]=65, [37]=22, [38]=65, [39]=22, [40]=22, [41]=22, [42]=65, [43]=22, [44]=22, [45]=22, [46]=22, [47]=22, [48]=65, [49]=22, [50]=22, [51]=22, [52]=22, [53]=22, [54]=22, [55]=22, [56]=65, [57]=22, [58]=22, [59]=22, [60]=65, [61]=22, [62]=65, [63]=22, [64]=22, [65]=22, [66]=65, [67]=22, [68]=65, [69]=22, [70]=65, [71]=22, [72]=1527, [73]=347, [74]=87, [75]=22, [76]=3692 } { [1]=0, [2]=104, [3]=0, [4]=34, [5]=361, [6]=180, [7]=23, [8]=68, [9]=23, [10]=68, [11]=23, [12]=23, [13]=23, [14]=23, [15]=23, [16]=23, [17]=23, [18]=68, [19]=23, [20]=23, [21]=23, [22]=68, [23]=23, [24]=23, [25]=23, [26]=23, [27]=23, [28]=68, [29]=23, [30]=68, [31]=23, [32]=68, [33]=23, [34]=23, [35]=23, [36]=68, [37]=23, [38]=23, [39]=23, [40]=68, [41]=23, [42]=23, [43]=23, [44]=23, [45]=23, [46]=68, [47]=23, [48]=68, [49]=23, [50]=23, [51]=23, [52]=23, [53]=23, [54]=68, [55]=23, [56]=23, [57]=23, [58]=68, [59]=23, [60]=68, [61]=23, [62]=23, [63]=23, [64]=23, [65]=23, [66]=68, [67]=23, [68]=68, [69]=23, [70]=23, [71]=23, [72]=1590 }
Sorry to ask this, but how can that be achieved?
-
I had been working on something like this, is it close?
local ircodearray = {} local rfile = io.open("mnt/nas/vera/text1.txt", "r") for line in rfile:lines() do local commandname = line:match("^Powe.*") local prontocode = line:match("^0000.*") local ircodearray = {"local = " .. commandname, prontocode} end print(ircodearray)
-
Hi,
If you're looking for a specific brand/model, you might try https://irdb.globalcache.com/Home/About. Registering is free and access to normal users has rate limited access to the DB, but it does contain IR codes which can be converted to Pronto codes via other free programs. I've used it for a number of codes for my devices.
-
Thanks @htchemg - I’ve actually already tried that route, I had a GC-100 for years, but sadly they do not have the manufacturer and/or model I need listed. Hence I’m sadly trying this long winded route to discover what it is
-
I fear, I may have hit my Vera/Lua wall.
I seem to have been able to partially rework the output from IrScrutinizer, but I can’t seem to get it into an appropriate format for @a-lurker’s code to then run through them all in sequence..
Input file (text1.txt) from IrScrutinizer
Power 0000 0070 0000 0032 0080 0040 0010 0010 0010 0030 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0030 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0030 0010 0010 0010 0010 0010 0030 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0030 0010 0010 0010 0030 0010 0010 0010 0030 0010 0030 0010 0030 0010 0030 0010 0010 0010 0010 0010 0030 0010 0010 0010 0030 0010 0030 0010 0010 0010 0030 0010 0030 0010 0030 0010 0ACD Power$1 0000 006C 0022 0002 015B 00AD 0016 0016 0016 0016 0016 0016 0016 0016 0016 0016 0016 0016 0016 0041 0016 0016 0016 0041 0016 0041 0016 0041 0016 0041 0016 0041 0016 0016 0016 0041 0016 0041 0016 0016 0016 0041 0016 0016 0016 0016 0016 0041 0016 0016 0016 0016 0016 0016 0016 0041 0016 0016 0016 0041 0016 0041 0016 0016 0016 0041 0016 0041 0016 0041 0016 05F7 015B 0057 0016 0E6C Power$2 0000 006C 0022 0002 015B 00AD 0016 0016 0016 0016 0016 0016 0016 0016 0016 0016 0016 0016 0016 0041 0016 0016 0016 0041 0016 0041 0016 0041 0016 0041 0016 0041 0016 0016 0016 0041 0019 0041 0016 0016 0016 0041 0016 0016 0016 0016 0016 0041 0016 0016 0016 0016 0016 0016 0016 0041 0016 0019 0016 0041 0016 0041 0016 0016 0016 0041 0016 0041 0016 0041 0016 05F7 015B 0057 0016 0E6C
Current Output file (text2.txt)
The ‘print’ looks positive, however I can’t seem to get each line in the correct format in the text2.txt file, it always spans 2 lines.
local Power = "0000 0070 0000 0032 0080 0040 0010 0010 0010 0030 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0030 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0030 0010 0010 0010 0010 0010 0030 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0030 0010 0010 0010 0030 0010 0010 0010 0030 0010 0030 0010 0030 0010 0030 0010 0010 0010 0010 0010 0030 0010 0010 0010 0030 0010 0030 0010 0010 0010 0030 0010 0030 0010 0030 0010 0ACD " local Power$1 = "0000 006C 0022 0002 015B 00AD 0016 0016 0016 0016 0016 0016 0016 0016 0016 0016 0016 0016 0016 0041 0016 0016 0016 0041 0016 0041 0016 0041 0016 0041 0016 0041 0016 0016 0016 0041 0016 0041 0016 0016 0016 0041 0016 0016 0016 0016 0016 0041 0016 0016 0016 0016 0016 0016 0016 0041 0016 0016 0016 0041 0016 0041 0016 0016 0016 0041 0016 0041 0016 0041 0016 05F7 015B 0057 0016 0E6C " local Power$2 = "0000 0068 0000 0022 0169 00B4 0017 0044 0017 0044 0017 0017 0017 0017 0017 0017 0017 0044 0017 0017 0017 0044 0017 0017 0017 0017 0017 0044 0017 0044 0017 0044 0017 0017 0017 0044 0017 0017 0017 0044 0017 0017 0017 0017 0017 0044 0017 0044 0017 0017 0017 0017 0017 0044 0017 0017 0017 0044 0017 0044 0017 0017 0017 0017 0017 0044 0017 0044 0017 0017 0017 0636 " local Power$3 = "0000 006D 0011 000E 0013 005F 0013 0026 0026 0013 0013 0013 0013 0013 0013 0013 0013 0013 0013 0013 0013 0013 0013 0013 0013 0013 0013 0013 0013 0013 0013 0013 0013 0013 0013 0013 0013 0227 0013 005F 0013 0026 0013 0013 0026 0013 0013 0026 0013 0013 0013 0013 0013 0013 0013 0013 0026 0026 0026 0026 0013 0013 0026 0026 0013 1054 "
Latest code is below.. All ideas/suggestions welcome
-- https://oc.cil.li/topic/1524-how-can-i-store-each-line-of-a-file-in-an-array-in-lua/#comment-6763 -- CP: does not Work -- v0.9 function sendProntoCodeToBroadLinkDevice(prontoCode) local BROADLINK_DEVICE_ID = 49 luup.call_action('urn:a-lurker-com:serviceId:IrTransmitter1', 'SendProntoCode', {ProntoCode = prontoCode}, BROADLINK_DEVICE_ID) end local write_file_path = "/mnt/nas/vera/text2.txt" -- # path to your file here local read_file_path = "/mnt/nas/vera/text1.txt" -- # path to your file here local pattern1 = "^.*Power.*$" -- # your pattern to find local pattern2 = "^.*0000.*$" -- # your pattern to find local matches = {} io.open(write_file_path,"w+"):close() local function contains(str, pattern) return string.match(str, pattern) and true or false end for line in io.lines(read_file_path) do if contains(line, pattern1) then command = (line) -- table.insert(matches, line1) end if contains(line, pattern2) then ProntoCode = (line) -- table.insert(matches, line1, line2) local irstr = command .. "" .. ProntoCode --print(irstr) print(string.format('local %s = "%s"\n',command,ProntoCode)) local file = io.open(write_file_path, 'a') -- file:write(command .. "" .. ProntoCode .. "\n") -- file:write(irstr .. "\n") file:write(string.format('local %s = "%s"\n',command,ProntoCode)) file:close() end end local INTERVAL_SECS = 2 luup.call_delay('sendProntoCodeToBroadLinkDevice', INTERVAL_SECS, prontoCode)
-
Well, they say in life "nothing ventured, nothing gained" and thanks to this forum and stackoverflow, I’ve got a working solution.
Code is below, any feedback on optimisation is always appreciated.
local lfs = require "lfs" local read_file_path = "/mnt/nas/vera/text1.txt" -- # path to your file here local write_file_path = "/mnt/nas/vera/text2.txt" -- # path to your file here local pattern1 = "^.*Power.*$" -- # your pattern to find local pattern2 = "^.*0000.*$" -- # your pattern to find io.open("/mnt/nas/vera/text5.txt", 'a'):close() --local logFile = io.open(write_file_path, 'w') local logs = {} -- We will use this to log the messages to log.txt later local i = 1;for line in io.lines(read_file_path) do if (line:find(pattern1) or not line:find('%A')) and line:len() > 1 then local powerref = line logs[#logs+ 1] = 'Command: ' .. powerref elseif line:find(pattern2) then local prontoCode = line local x = 1 do x = x + 1 local pause = os.clock() print('"' ..prontoCode..'"') luup.call_action('urn:a-lurker-com:serviceId:IrTransmitter1', 'SendProntoCode', {ProntoCode = prontoCode}, 49) -- x = x + 1 -- local pause = os.clock() repeat until os.clock() > pause + 3 local time = os.date("%Y-%m-%d %H:%M:%S") local xfile = io.open("/mnt/nas/vera/text5.txt", 'a') xfile:write(time .. " - " .. prontoCode .. "\n") xfile:close() end logs[#logs + 1] = 'Sequence: ' .. line end; i = i + 1 -- Raise the line number end local logFile = io.open(write_file_path, 'w') logFile:write(table.concat(logs, '\n')) logFile:flush()