Help w/ IR code delays in luup for scene with multiple IR codes for same devices

Hi All, long time Vera user, but newbie when it comes to Lua/Luup/scripting. I recently discovered how to incorporate luup code into scenes, but I have pretty much used examples found in the forums that matched the devices I was trying to control. Namely, a Panasonic TV in my kitchen and the Monoprice 6-zone Whole Home Audio receiver. The luup code for both of these devices are sent through an IP2IR Itach for my Panasonic TV and IPSerial Itach for the Monoprice. I am now able to have my wife ask Alexa to turn on TV in the kitchen as well as turn on Kitchen Speakers.

I also have the same Panasonic TV in my kids play room connected to an older Pioneer receiver. Both of these devices are controlled through the same IP2IR itach as the kitchen Panasonic TV. I have a few different gaming consoles connected into the Pioneer including a PS3 in HDMI 1, Classic Super Nintendo in HDMI 2 and a Mac Mini in HDMI 3.

I am trying to create a scene that will 1) Turn on Panasonic TV, 2) Switch Panasonic TV to HDMI 1 (in case its not as my kids often touch buttons on remotes), 3) Turn on Pioneer Receiver and 4) Turn Pioneer Receiver to HDMI 1. Then I want my kids to be able to ask Alexa to Turn On Super Nintendo and everything turns on and switches over for them.

I have all 4 necessary IR commands in the luup code that do work individually. However when I add all 4 codes and test the code on Vera, it will only turn on the TV and the Receiver, but it will not switch the HDMI ports on either the TV or receiver. When I press the test button again, it then will change both HDMI ports. I think I need to insert delays between the 4 IR commands as it takes a moment for the TV and the receiver to turn on. I have tried to research luup.call delay for the past day or so, but I cannot figure out what the commands I am supposed to add for this.

In other control programs I have used (Simple Control and IRule) I can set the delay between commands at whatever interval I want. I cannot figure it out here though. Anyone have any tips or pointers for me on how to achieve what I am trying to do? Here is the code that I am using for simply turning on the Panasonic TV and then trying to switch to HDMI 1. When I test this, it will only turn on the TV…when I test a 2nd time, it will then switch the input to HDMI 1…

local CommandtoSend

CommandtoSend= ‘sendir,1:1,1,37000,1,1,128,63,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,16,16,16,16,16,16,48,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,48,16,48,16,48,16,48,16,48,16,16,16,16,16,16,16,48,16,48,16,48,16,48,16,48,16,16,16,48,16,2712,\r’

print (“test:”, CommandtoSend)
– Connect and Send Command

local socket = require(“socket”)
host = “10.0.1.124” --IP2IR Living Room
c = assert(socket.connect(host, 4998))
c:settimeout(5)

local sres, serr = c:send(CommandtoSend)
print(“Send:”, sres, serr)
local data, rerr = c:receive(5)
print (“Receive:”, data, rerr)

local CommandtoSend

CommandtoSend= ‘sendir,1:1,1,37000,1,1,132,67,17,17,17,51,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,51,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,51,17,17,17,17,17,51,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,51,17,51,17,17,17,51,17,17,17,17,17,51,17,17,17,51,17,51,17,17,17,17,17,2846,\r’
print (“test:”, CommandtoSend)
– Connect and Send Command

local socket = require(“socket”)
host = “10.0.1.124” --IP2IR Living Room
c = assert(socket.connect(host, 4998))
c:settimeout(5)

local sres, serr = c:send(CommandtoSend)
print(“Send:”, sres, serr)
local data, rerr = c:receive(5)
print (“Receive:”, data, rerr)

c:close()

Any help is greatly appreciated and thanks in advance. My kids will thank you too :slight_smile:

No direct ir experience but I believe you want to add a call_delay in your luup

http://wiki.micasaverde.com/index.php/Luup_Lua_extensions

I have an old example from ui5, should work on ui7.


function buzzer()
luup.call_action(‘urn:micasaverde-com:serviceId:ZWaveNetwork1’,‘SendData’,{Node=‘5’,Data=‘112 4 6 1 2’},1)
end

luup.call_delay( ‘buzzer’, 1) – Call the buzzer function after a delay of 1 seconds

Yes, you need to wait until the TV and Receiver power on and are ready for the next command. Here is an example where I turn on a TV and wait 10 seconds to change the input. You will have to experiment with how much time your device needs - but 10 seconds or more is not uncommon… call_delay is the best way to go, [you can test with SLEEP(10), but don’t use SLEEP in production] but it takes some work - you need a function that takes only one parameter. Which means your whole iTach command is a single string, and you then have to parse it out. Example below probably took me two days to figure out. :o

Function as part of Startup LUA:

function SendiTachCommand(ParamString)

	local IPAddress,Port, CommandtoSend = string.match(ParamString,"(%d+.%d+.%d+.%d+),(%d+),(.+)")
	print (IPAddress)
	print (Port)
	print (CommandtoSend)

	local socket = require("socket")
	c = assert(socket.connect(IPAddress, Port))
	c:settimeout(5)

	local sres, serr = c:send(CommandtoSend)
	print("Send:", sres, serr)
	local data, rerr = c:receive(5)
	print ("Receive:", data, rerr)

 	c:close()

end

Now scene to execute.

[code]SendiTachCommand(“192.168.0.121,4998,sendir,1:1,1,38000,1,1,172,172,22,64,22,64,22,64,22,21,22,21,22,21,22,21,22,21,22,64,22,64,22,64,22,21,22,21,22,21,22,21,22,21,22,64,22,21,22,21,22,64,22,64,22,21,22,21,22,64,22,21,22,64,22,64,22,21,22,21,22,64,22,64,22,21,22,1820,\r”) – Turn On Samsung TV in Bedroom

luup.call_delay(“SendiTachCommand”,10, “192.168.0.121,4998,sendir,1:1,1,38000,1,1,173,173,21,65,21,65,21,65,21,21,21,21,21,21,21,21,21,21,21,65,21,65,21,65,21,21,21,21,21,21,21,21,21,21,21,65,21,21,21,21,21,65,21,21,21,65,21,65,21,65,21,21,21,65,21,65,21,21,21,65,21,21,21,21,21,21,21,1832,\r”) – Switch Samsung TV to Input HDMI 1
[/code]

If you only need to pause like 2-3 seconds for the TV to fire up just use luup.sleep(2000) it is in milliseconds so 2000 is a two minute sleep.
You don’t want to do this for long pauses, then you need to use the function calls with delays like examples here. But for a quick pause, you can get away with a quick sleep.

You also don’t need re-connect the socket between your two commands.
Here is your code with a 2 second delay till the second command is sent:

local CommandtoSend

CommandtoSend= ‘sendir,1:1,1,37000,1,1,128,63,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,16,16,16,16,16,16,48,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,48,16,48,16,48,16,48,16,48,16,16,16,16,16,16,16,48,16,48,16,48,16,48,16,48,16,16,16,48,16,2712,\r’

print (“test:”, CommandtoSend)
– Connect and Send Command

local socket = require(“socket”)
host = “10.0.1.124” --IP2IR Living Room
c = assert(socket.connect(host, 4998))
c:settimeout(5)

local sres, serr = c:send(CommandtoSend)
print(“Send:”, sres, serr)
local data, rerr = c:receive(5)
print (“Receive:”, data, rerr)

luup.sleep(2000)

CommandtoSend= ‘sendir,1:1,1,37000,1,1,132,67,17,17,17,51,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,51,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,51,17,17,17,17,17,51,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,51,17,51,17,17,17,51,17,17,17,17,17,51,17,17,17,51,17,51,17,17,17,17,17,2846,\r’
print (“test:”, CommandtoSend)
– Connect and Send Command

sres, serr = c:send(CommandtoSend)
print(“Send:”, sres, serr)
data, rerr = c:receive(5)
print (“Receive:”, data, rerr)

c:close()

I’ve just found this thread and it has answered a myriad of questions, however I’m experiencing a problem not addressed. I’m trying to send IR code to turn on my Sony TV via an iTach WF2IR but the code is not getting through. When I send the IR code from iLearn (a GC utility which connects to the iTach) the code works flawlessly. I hope someone can help me out. Thanks.

Here is my code:

local CommandtoSend

– Turn Off Sony TV
CommandtoSend= ‘sendir,1:3,1,39936,1,1,96,24,48,24,24,24,48,24,24,24,48,24,24,24,24,24,48,24,24,24,24,24,24,24,24,1033,96,24,48,24,24,24,48,24,24,24,48,24,24,24,24,24,48,24,24,24,24,24,24,24,24,1033,96,24,48,24,24,24,48,24,24,24,48,24,24,24,24,24,48,24,24,24,24,24,24,24,24,5111,\r’

print (“test:”, CommandtoSend)
– Connect and Send Command

local socket = require(“socket”)
host = “192.168.1.114”
c = assert(socket.connect(host, 4998))
c:settimeout(5)

local sres, serr = c:send(CommandtoSend)
print(“Send:”, sres, serr)
local data, rerr = c:receive(5)
print (“Receive:”, data, rerr)
c:close()

Try this, I also put a 3 after 39936 (tcp:send("sendir,1:3,1,39936,3) to serve as a repeat. Some Sonys need a repeat count of 3 but 1 may work as well depending on your TV.

–[[Sony TV power off----]]
local socket = require(“socket”)
tcp = assert(socket.connect(“192.168.1.114”, 4998))
tcp:send(“sendir,1:3,1,39936,3,1,96,24,48,24,24,24,48,24,24,24,48,24,24,24,24,24,48,24,24,24,24,24,24,24,24,1033,96,24,48,24,24,24,48,24,24,24,48,24,24,24,24,24,48,24,24,24,24,24,24,24,24,1033,96,24,48,24,24,24,48,24,24,24,48,24,24,24,24,24,48,24,24,24,24,24,24,24,24,5111” … “\r\n”)
luup.sleep(1050)
tcp:close()

Tarkus. - I cut and pasted the code exactly as you sent into “test Lua” and Vera came back with a Failed to test code. Is there a syntax error in the code? I looked at it, but couldn’t see anything. Thanks for your help.

Bob

Try this, replace 192.168.x.x with your iTachs IP. This passes lua test with my IP. The wrong IP or a connectivity issue will cause it to fail.

–[[Sony TV power off----]]
local socket = require(“socket”)
tcp = assert(socket.connect(“192.168.x.x”, 4998))
tcp:send(“sendir,1:3,1,39936,3,1,96,24,48,24,24,24,48,24,24,24,48,24,24,24,24,24,48,24,24,24,24,24,24,24,24,1033,96,24,48,24,24,24,48,24,24,24,48,24,24,24,24,24,48,24,24,24,24,24,24,24,24,1033,96,24,48,24,24,24,48,24,24,24,48,24,24,24,24,24,48,24,24,24,24,24,24,24,24,5111” … “\r\n”)
luup.sleep(1050)
tcp:close()

Also where did you get that sendir string? GC data daabase only has one string for Sony TV’s power off and it is

sendir,1:1,1,40000,1,1,96,24,48,24,48,24,48,24,48,24,24,24,48,24,24,24,48,24,24,24,24,24,24,24,24,990

This is the one I use for my Sony. Of course you need to change the 1:1:1 to your application and possibly the 1 after 40000 to 3 if necessary. My Sony needs a repeat count of 3 to respond.

Looks like something is getting altered in the copy / paste since I copied the code back from post and it did fail. For what ever reason they dont allow text files to be attached so view sony lua.txt fom the following link and copy and paste from that. BTW it looks like your code is a Sony code however it looks like it is a power toggle vs off.

https://1drv.ms/t/s!Ao-vabBdIS3UgYUHGRRUx-iSQPOSvQ

That worked like a charm…must have something in the cut/paste. And yes, my Sony code is a toggle. I don’t have a source for on or off, so just used iLearn to get it from the remote. If you have on/off that you can share, that would be great…or even a sight where I can get it myself.

Thanks again Tarkus.

Go to

https://irdb.globalcache.com/Home/Database

create an account, select your manufacturer / Brand and device type and select Send Code Set

Codes will be e-mailed to you

Pronto hex is also included but just use the Global Cache code.

They are all set to sendir 1:1,1 so change to what is needed.

On and off discrete codes are included.

If codes don’t respond, try setting repeat to 3 as I described earlier.

Glad it worked out!