Mr, Lurker, I have the below code (in large part re-purposed from your code posting ) that creates a table of raw IR codes and a table of steps to run the codes.
Everything works except the mini IR does not respond to the program. I can copy the sent code from my openLuup log, paste it into the “Actions” sendCode action on the Altui screen, and the code works. However the codes do not work programmatically. I’m running this test code on the latest openLuup development version (in the test screen).
Beyond excessive verbosity in my code :P, can you see if anything is amiss here. I tried calling the SendCode method using both a command table key/value reference and a variable created from the command table— with no joy.
Edit: problem was that I was passing a string to the action method and not a table. It’s now fixed in the below code and all works well. Thx for the plugin
--function turnOnBedroomActi ()
local TVdeviceID = 10516 -- Bedroom Vizio power outlet
local IRDeviceID = 143 -- Broadlink RM3
-- Steps to turn on your device (using broadlink codes)
local bSteps = {
-- Turn TV ON from now live outlet (should match 5 second delay from above for correct log info)
{bDelay = 5, bCommand = "OnOff"},
-- wait another 60 seconds for TV and firestick to boot from tv on/off
--Assume Firestick is on screen - no way to know with broadlink
-- Press down and
{bDelay = 60, bCommand = "Down"},
-- Press down and
{bDelay = 1, bCommand = "Down"},
-- Press down and
{bDelay = 1, bCommand = "Down"},
-- Press OK on Acti app and
{bDelay = 1, bCommand = "OK"},
-- Press OK on NVR and
{bDelay = 4, bCommand = "OK"},
-- wait 4 seconds Press down and
{bDelay = 4, bCommand = "Down"},
-- wait 1 second Press down and
{bDelay = 1, bCommand = "Down"},
-- wait 1 second Press down and
{bDelay = 1, bCommand = "Down"},
-- wait 1 second Press OK on Acti view
{bDelay = 1, bCommand = "OK"}
}
local BroadLinkCodes={
OnOff={
buttonId= 1,
bName="OnOff",
bCode= {38, 0, 88, 0, 0, 1, 42, -108, 20, 18, 20, 17, 20, 55, 19, 18, 20, 17, 20, 17, 20, 18, 25, 12, 20, 54, 20, 55, 20, 17, 20, 55, 19, 55, 20, 55, 19, 56, 20, 54, 19, 18, 21, 17, 19, 18, 19, 56, 20, 17, 20, 17, 20, 18, 19, 18, 19, 55, 20, 55, 20, 55, 20, 17, 20, 54, 21, 54, 19, 55, 21, 54, 20, 0, 5, 11, 0, 1, 43, 73, 20, 0, 12, 83, 0, 1, 41, 74, 19, 0, 13, 5}},
Down={
buttonId= 2,
bName="Down",
bCode= {38, 0, 88, 0, 0, 1, 44, -108, 21, 17, 19, 18, 20, 55, 20, 17, 19, 18, 20, 17, 20, 18, 19, 18, 19, 55, 21, 54, 20, 17, 20, 55, 20, 54, 20, 55, 20, 54, 21, 54, 20, 17, 20, 55, 20, 54, 20, 18, 19, 18, 20, 17, 20, 54, 21, 17, 19, 56, 20, 17, 19, 18, 20, 55, 20, 54, 20, 55, 19, 18, 19, 56, 19, 0, 5, 12, 0, 1, 41, 74, 20, 0, 12, 83, 0, 1, 42, 73, 22, 0, 13, 5}},
Up={
buttonId= 3,
bName="Up",
bCode= {38, 0, -112, 0, 0, 1, 42, -108, 19, 18, 20, 17, 19, 56, 20, 17, 20, 17, 22, 16, 19, 18, 19, 18, 20, 55, 20, 54, 20, 17, 20, 55, 20, 55, 19, 55, 20, 55, 20, 54, 20, 55, 20, 17, 19, 56, 20, 17, 19, 18, 20, 18, 20, 54, 20, 17, 20, 18, 20, 54, 20, 17, 21, 54, 20, 54, 21, 54, 19, 18, 20, 55, 20, 0, 9, -34, 0, 1, 41, -107, 20, 17, 20, 17, 19, 56, 20, 17, 19, 18, 20, 18, 19, 18, 19, 18, 19, 56, 19, 55, 19, 18, 21, 54, 19, 56, 20, 54, 20, 55, 20, 54, 20, 55, 20, 17, 19, 56, 20, 17, 20, 17, 20, 17, 20, 55, 20, 17, 20, 18, 20, 54, 20, 17, 20, 55, 20, 55, 20, 54, 20, 17, 20, 55, 20, 0, 13, 5, 0, 0, 0, 0, 0, 0, 0, 0}},
Right={
buttonId = 4,
bName="Right",
bCode= {38, 0, 80, 0, 0, 1, 41, -108, 21, 17, 20, 17, 19, 56, 19, 18, 19, 18, 19, 18, 20, 18, 19, 18, 20, 54, 21, 54, 20, 17, 20, 55, 20, 54, 20, 55, 20, 54, 20, 55, 20, 17, 20, 18, 20, 17, 20, 54, 20, 18, 19, 18, 20, 55, 20, 17, 19, 55, 20, 55, 20, 55, 20, 17, 19, 55, 20, 55, 20, 17, 20, 55, 20, 0, 5, 11, 0, 1, 42, 73, 20, 0, 13, 5, 0, 0, 0, 0, 0, 0, 0, 0}},
Left={
buttonId = 5,
bName="Left",
bCode= {38, 0, 80, 0, 0, 1, 41, -110, 23, 17, 20, 17, 20, 55, 20, 17, 19, 18, 19, 18, 20, 18, 20, 17, 19, 56, 19, 55, 19, 18, 20, 55, 20, 54, 21, 54, 19, 56, 19, 55, 20, 55, 20, 54, 19, 56, 19, 18, 19, 18, 19, 19, 19, 55, 19, 18, 20, 18, 20, 17, 20, 17, 19, 56, 19, 55, 19, 56, 19, 18, 19, 56, 19, 0, 5, 12, 0, 1, 41, 74, 19, 0, 13, 5, 0, 0, 0, 0, 0, 0, 0, 0}},
OK={
buttonId= 6,
bName="OK",
bCode= {38, 0, 80, 0, 0, 1, 41, -108, 20, 18, 20, 17, 20, 54, 20, 18, 19, 18, 20, 17, 20, 17, 20, 18, 19, 55, 20, 55, 20, 17, 19, 56, 20, 54, 20, 55, 20, 54, 20, 55, 20, 17, 19, 18, 20, 55, 20, 17, 20, 17, 20, 18, 19, 55, 20, 17, 20, 55, 20, 54, 21, 17, 22, 52, 20, 55, 19, 55, 20, 18, 20, 54, 20, 0, 5, 11, 0, 1, 42, 74, 20, 0, 13, 5, 0, 0, 0, 0, 0, 0, 0, 0}},
Back={
buttonId= 7,
bName="Back",
bCode= {38, 0, 80, 0, 0, 1, 42, -108, 20, 17, 19, 18, 20, 55, 20, 17, 20, 17, 20, 18, 20, 17, 20, 17, 19, 56, 19, 55, 20, 18, 20, 54, 20, 55, 20, 54, 20, 55, 19, 55, 20, 55, 20, 17, 19, 19, 19, 55, 20, 17, 20, 18, 19, 55, 20, 17, 20, 18, 19, 55, 20, 55, 20, 17, 20, 55, 19, 55, 20, 18, 19, 55, 20, 0, 5, 11, 0, 1, 42, 74, 20, 0, 13, 5, 0, 0, 0, 0, 0, 0, 0, 0}},
One={
buttonId= 8,
bName="One",
bCode= {38, 0, 80, 0, 0, 1, 42, -109, 21, 17, 20, 17, 19, 56, 20, 17, 20, 17, 20, 17, 20, 18, 20, 17, 20, 54, 20, 55, 20, 17, 19, 56, 20, 54, 20, 55, 20, 54, 21, 54, 20, 55, 19, 18, 19, 18, 20, 17, 20, 55, 20, 17, 19, 18, 21, 17, 20, 17, 20, 55, 19, 55, 19, 56, 20, 17, 20, 54, 20, 55, 20, 54, 20, 0, 5, 12, 0, 1, 42, 73, 20, 0, 13, 5, 0, 0, 0, 0, 0, 0, 0, 0}},
Two={
buttonId= 9,
bName="Two",
bCode= {38, 0, 80, 0, 0, 1, 43, -109, 20, 18, 19, 18, 19, 55, 21, 17, 19, 18, 19, 18, 20, 18, 20, 17, 19, 55, 20, 55, 20, 17, 20, 55, 20, 54, 20, 55, 20, 54, 20, 55, 19, 18, 19, 56, 20, 17, 20, 17, 20, 55, 20, 17, 20, 17, 20, 18, 20, 54, 20, 18, 19, 55, 20, 55, 20, 17, 19, 55, 20, 55, 20, 54, 20, 0, 5, 11, 0, 1, 42, 74, 20, 0, 13, 5, 0, 0, 0, 0, 0, 0, 0, 0}},
Three={
buttonId= 10,
bName="Three",
bCode= {38, 0, 80, 0, 0, 1, 42, -108, 20, 17, 19, 18, 20, 55, 19, 18, 20, 17, 20, 17, 20, 18, 19, 18, 19, 56, 20, 54, 19, 18, 20, 55, 20, 54, 21, 54, 19, 56, 20, 54, 19, 56, 20, 54, 19, 19, 19, 18, 19, 55, 20, 18, 20, 17, 20, 17, 19, 18, 20, 18, 20, 54, 19, 56, 20, 17, 19, 56, 20, 54, 19, 56, 19, 0, 5, 12, 0, 1, 42, 73, 20, 0, 13, 5, 0, 0, 0, 0, 0, 0, 0, 0}},
Four={
buttonId= 11,
bName="Four",
bCode= {38, 0, 80, 0, 0, 1, 42, -108, 20, 18, 20, 17, 19, 55, 20, 18, 19, 18, 19, 18, 20, 18, 19, 18, 19, 55, 20, 55, 19, 18, 20, 55, 20, 54, 20, 55, 19, 55, 21, 54, 19, 18, 20, 18, 19, 55, 19, 18, 20, 55, 19, 18, 20, 17, 21, 17, 20, 54, 20, 55, 20, 17, 19, 56, 19, 18, 20, 54, 21, 54, 20, 54, 21, 0, 5, 11, 0, 1, 42, 73, 20, 0, 13, 5, 0, 0, 0, 0, 0, 0, 0, 0}},
Five={
buttonId= 12,
bName="Five",
bCode= {38, 0, 80, 0, 0, 1, 42, -108, 20, 17, 19, 19, 20, 54, 19, 18, 20, 18, 20, 17, 19, 18, 20, 17, 20, 55, 20, 55, 20, 17, 19, 55, 20, 55, 20, 54, 21, 54, 19, 56, 20, 54, 20, 17, 20, 55, 20, 17, 20, 55, 19, 18, 20, 17, 19, 19, 20, 17, 19, 55, 20, 18, 19, 55, 20, 17, 21, 54, 19, 56, 20, 54, 20, 0, 5, 11, 0, 1, 43, 73, 20, 0, 13, 5, 0, 0, 0, 0, 0, 0, 0, 0}},
Six={
buttonId= 13,
bName="Six",
bCode= {38, 0, 80, 0, 0, 1, 42, -108, 20, 18, 20, 17, 19, 55, 21, 17, 19, 18, 20, 17, 19, 19, 19, 18, 20, 54, 20, 55, 19, 18, 20, 55, 19, 55, 20, 55, 20, 54, 20, 55, 20, 17, 19, 56, 20, 54, 20, 18, 20, 54, 20, 17, 20, 18, 20, 17, 20, 54, 20, 18, 20, 17, 19, 55, 20, 18, 19, 55, 20, 55, 20, 54, 20, 0, 5, 11, 0, 1, 43, 73, 19, 0, 13, 5, 0, 0, 0, 0, 0, 0, 0, 0}},
Seven={
buttonId= 14,
bName="Seven",
bCode= {38, 0, 80, 0, 0, 1, 42, -108, 20, 17, 20, 17, 20, 55, 20, 17, 19, 18, 20, 18, 19, 18, 20, 17, 20, 55, 19, 55, 20, 18, 20, 54, 20, 55, 19, 55, 20, 55, 19, 55, 21, 54, 20, 55, 20, 54, 19, 18, 20, 55, 20, 17, 20, 17, 21, 17, 19, 18, 20, 17, 20, 18, 20, 54, 20, 17, 20, 55, 20, 54, 20, 55, 19, 0, 5, 12, 0, 1, 42, 74, 20, 0, 13, 5, 0, 0, 0, 0, 0, 0, 0, 0}},
Eight={
buttonId= 15,
bName="Eight",
bCode= {38, 0, 80, 0, 0, 1, 43, -109, 20, 17, 20, 18, 19, 55, 20, 17, 20, 18, 19, 18, 20, 17, 20, 18, 19, 55, 20, 55, 20, 17, 19, 55, 21, 54, 19, 56, 19, 55, 20, 55, 19, 18, 20, 17, 19, 18, 20, 55, 20, 55, 19, 16, 21, 18, 19, 18, 20, 55, 19, 55, 20, 55, 20, 17, 20, 18, 20, 54, 20, 55, 20, 54, 20, 0, 5, 11, 0, 1, 42, 74, 20, 0, 13, 5, 0, 0, 0, 0, 0, 0, 0, 0}},
Nine={
buttonId= 16,
bName="Nine",
bCode= {38, 0, 80, 0, 0, 1, 41, -108, 21, 16, 21, 17, 19, 56, 19, 18, 19, 18, 19, 18, 20, 18, 20, 17, 19, 55, 20, 55, 20, 17, 20, 55, 20, 54, 20, 55, 19, 55, 20, 55, 20, 54, 20, 18, 19, 18, 19, 56, 20, 54, 20, 17, 20, 18, 20, 17, 19, 18, 19, 56, 19, 55, 20, 18, 19, 18, 19, 55, 20, 55, 20, 54, 20, 0, 5, 11, 0, 1, 43, 73, 19, 0, 13, 5, 0, 0, 0, 0, 0, 0, 0, 0}},
Zero={
buttonId= 17,
bName="Zero",
bCode= {38, 0, 80, 0, 0, 1, 42, -108, 20, 17, 21, 17, 19, 55, 20, 17, 21, 17, 20, 17, 19, 18, 20, 18, 20, 54, 19, 56, 20, 17, 20, 54, 21, 54, 19, 55, 21, 54, 20, 55, 19, 18, 20, 17, 19, 18, 20, 18, 19, 55, 19, 18, 20, 18, 19, 18, 19, 55, 21, 54, 19, 56, 20, 54, 20, 17, 19, 56, 19, 55, 20, 55, 20, 0, 5, 11, 0, 1, 42, 73, 20, 0, 13, 5, 0, 0, 0, 0, 0, 0, 0, 0}},
Menu={
buttonId= 18,
bName="Menu",
bCode= {38, 0, 88, 0, 0, 1, 43, -109, 20, 17, 20, 17, 20, 55, 20, 17, 19, 19, 20, 17, 19, 18, 19, 18, 20, 55, 20, 54, 20, 18, 19, 55, 20, 55, 19, 55, 20, 55, 20, 54, 20, 55, 20, 54, 21, 54, 20, 55, 19, 18, 20, 17, 19, 56, 20, 17, 20, 17, 19, 19, 19, 18, 19, 18, 19, 56, 19, 55, 20, 17, 20, 55, 19, 0, 5, 12, 0, 1, 42, 72, 21, 0, 12, 83, 0, 1, 41, 74, 19, 0, 13, 5}},
Exit={
buttonId= 19,
bName="Exit",
bCode= {38, 0, 88, 0, 0, 1, 43, -109, 20, 17, 20, 18, 19, 55, 19, 18, 21, 17, 19, 18, 19, 18, 20, 18, 19, 55, 20, 55, 19, 18, 20, 55, 20, 54, 20, 55, 20, 54, 19, 56, 19, 55, 21, 17, 20, 17, 19, 55, 21, 17, 19, 18, 20, 55, 19, 18, 19, 18, 20, 55, 20, 54, 20, 18, 19, 55, 19, 56, 20, 17, 20, 54, 21, 0, 5, 11, 0, 1, 42, 73, 20, 0, 12, 83, 0, 1, 42, 73, 20, 0, 13, 5}},
Info={
buttonId= 20,
bName="Info",
bCode= {38, 0, 88, 0, 0, 1, 43, -109, 20, 17, 20, 17, 21, 54, 20, 17, 19, 19, 20, 17, 20, 17, 19, 18, 20, 55, 19, 56, 20, 17, 20, 54, 26, 49, 19, 55, 20, 55, 19, 56, 20, 54, 19, 56, 19, 18, 19, 56, 19, 55, 20, 17, 20, 18, 19, 18, 19, 18, 20, 18, 20, 54, 20, 17, 20, 18, 19, 55, 20, 55, 19, 55, 20, 0, 5, 11, 0, 1, 43, 73, 20, 0, 12, 82, 0, 1, 43, 73, 20, 0, 13, 5}}
}
local function allmatching(tbl, kvs)
return function(t, key)
repeat
key, row = next(t, key)
if key == nil then
return
end
for k, v in pairs(kvs) do
if row[k] ~= v then
row = nil
break
end
end
until row ~= nil
return key, row
end, tbl, nil
end
local function decIR2Hex(decCode)
local hexTab = {}
for _,val in ipairs(decCode) do
-- handle negative values: eg 433MHz leadin sendCode is 0xb2 ie 178dec, In the e-control json, it is -78dec. So 256+(-78) = 178dec = 0xb2
if (val < 0) then val = 256 + val end
table.insert(hexTab, string.format('%02x', val))
end
-- send converted hexTab to action
return (table.concat(hexTab,' '))
end
local function BroadLinkConverter(commandName)
-- search table for command, return code as listed (you obtain the codes from the Broadlink app)
for _, r in allmatching(BroadLinkCodes, { bName= commandName}) do
local myCode =r.bCode
myCode = decIR2Hex(myCode)
return myCode --translated command code
end
end
function sendCommand(stepNumber)
stepNumber = tonumber(stepNumber)
luup.log('INC STEP NUMBER ' .. stepNumber,50)
luup.log('CALL DELAY COMMAND '.. myCommandTable[stepNumber][1],50)
luup.log('CALL DELAY TIME ' .. myCommandTable[stepNumber][2],50)
luup.log('COMMAND CODE ' .. myCommandTable[stepNumber][3],50)
local resultCode, resultString, job = luup.call_action('urn:a-lurker-com:serviceId:IrTransmitter1', 'SendCode', {Code =myCommandTable[stepNumber][3]} , IRDeviceID)
luup.log('RETURN MESSAGES '.. resultCode .. ' ' .. resultString .. ' ' .. job)
stepNumber = stepNumber + 1
if (not myCommandTable[stepNumber]) then luup.log('IR FINISHED',50) return end
local timeString = ""
if myCommandTable[stepNumber][2] > 1 then timeString = " SECONDS" else timeString = " SECOND" end
luup.log('WILL NOW WAIT ' .. myCommandTable[stepNumber][2] .. timeString,50)
luup.call_delay('sendCommand', myCommandTable[stepNumber][2], tostring(stepNumber))
end
local function buildTransmitTable(bStepTable)
local myCommand = "" myDelay = 0 sendCode = ""
myCommandTable = {}
for k, v in pairs(bStepTable) do
if v ~= nil then
myCommand = v.bCommand
myDelay = v.bDelay
sendCode = BroadLinkConverter(myCommand)
local myData = {myCommand, myDelay, sendCode}
myCommandTable[k] = myData -- table of sequential codes to send along with delay times.
end
end
-- Turn TV power on
local resultCode, resultString, job, returnArguments = luup.call_action("urn:upnp-org:serviceId:SwitchPower1","SetTarget",{ newTargetValue="1" },TVdeviceID)
if resultCode ~= 0 then luup.call_action("urn:upnp-org:serviceId:SwitchPower1","SetTarget",{ newTargetValue="1" },TVdeviceID) end
local afterPowerOnDelay = myCommandTable[1][2] -- wait 5 seconds for TV to boot from electric power on
--wait afterPowerOnDelay seconds to allow power-up and start sending broadlink commands
luup.call_delay('sendCommand', afterPowerOnDelay,"1")
return true
end
buildTransmitTable(bSteps)
--end