Author Topic: Kira IR Receiver and Transmitter Plugins  (Read 62621 times)

Offline RexBeckett

  • Master Member
  • *******
  • Posts: 3888
  • Karma: +477/-10
Kira IR Receiver and Transmitter Plugins
« on: April 27, 2013, 06:29:17 am »
Vera runs my house but I use a Logitech Harmony 1100 to control my AV rig. The part where they interact is for control of the lighting. Previously I had an IR-controlled dimmer for the lights which was fine for the Harmony and I used an iTach so Vera could play too. Then I discovered MiLight lamps. :D  So now Vera is firmly in control of the lighting but Harmony doesn't speak Z-Wave or UDP so is somewhat in the dark.  ::)

A search through the forum revealed several questions about getting Vera to receive IR but no apparent solutions. Time for a bit of engineering.  ;D

The Kira standalone IR receiver, from Keene, seemed a good place to start. This device will read IR signals and transmit a coded string to a "PC" by UDP. It has a built-in web server for configuration and there is a Java application for testing. The device does exactly as claimed, but... When testing various remotes and buttons I noticed that there was significant variation in the burst times for a given code on multiple button presses and it also seemed to vary with remote-to-receiver distance. Clearly a simple look-up table was not going to work.  :o

I decided I didn't really care how many microseconds each burst took. All I really needed was to distinguish long and short bursts. After some experimentation I came up with a compact way of representing a code:

The first word is four hex characters. The first two digits are the carrier frequency in KHz and the last two are the number of burst pairs in the code. This comes directly from the Kira code string.

The second word is also four hex characters that represents a slicing value. Bursts above the slicing level are long and those below it are short. The value is determined by analyzing the code string from Kira to find the best fit.

The final part of the code is a string containing the bursts as L for long and S for short.

A typical code looks like:  241A 03C0 SSSLLSSSSLSSLSSLSSLSSLLSSSSSSSSSSSSSSSSSSSSSSSSSSSSL

I cannot claim that this technique will work with any remote control. There may well be code formats that don't lend themselves to this form of compression. Interestingly, it works with every one of my remotes and appears to be more reliable than some of the built-in decoders.  8)

OK. The result of all the playing is a plugin that will allow Vera to receive IR codes from a standalone Kira device via UDP. The plugin includes facilities for learning the codes; viewing, deleting or renaming codes; backing-up or restoring the code set (/etc/KiraRx.xml). When the plugin recognises an incoming code, the code name is made available as an event. This can be used as a trigger for scenes and PLxx plugins by testing for the KiraRx device's IR code received event with the required code name in the Code: field. It is so easy to use there must be a catch. I'm sure someone will point this out to me.  ;D

This is a beta-level plugin. It is working really reliably on my system but it may not work on yours. If you want to try it out, the files and instructions are: Here.

I have also written a plugin to transmit IR codes by name using a KIRA module. This is called KiraTx. KiraRx and KiraTx can work with the same physical KIRA module or different ones. The two plugins may be used together or own their own. The beta-level code and instructions for KiraTx are available: Here.

Update
There is now a plugin in the App Store. KiraRT combines the functionality of KiraRx and KiraTx. See this post for details.

Edit: 18/02/2014 11:17 New version of KiraTx uploaded. Allow codes to be sent multiple times. Import of Pronto codes with dummy repeat fixed.
Edit: 18/02/2014 11:55 New version of KiraRx uploaded. Import of Pronto codes with dummy repeat fixed. I_KiraRx.xml only.
Edit: 28/03/2014 19:06 New version of KiraRx uploaded. Improved resilience to corrupted IRCodes. I_KiraRx.xml only.
Edit: 28/03/2014 19:06 New version of KiraTx uploaded. Improved resilience to corrupted IRCodes. Allow import of KIRA codes with repeat extension. I_KiraTx.xml only.
Edit: 03/02/2015 11:18 KiraRT plugin released in App Store.
Edit: 17/02/2015 10:10 KiraRT V1.1 released in App Store. Added TXO option.
Edit: 12/03/2015 00:18 KiraRT V1.2 released in App Store. Fixed for firmware 7.0.5.
« Last Edit: March 11, 2015, 08:18:01 pm by RexBeckett »

Offline parkerc

  • Sr. Hero Member
  • ******
  • Posts: 2330
  • Karma: +32/-44
  • Life Moves Pretty Fast....
    • Node Central
Re: Kira IR Receiver Plugin
« Reply #1 on: April 27, 2013, 06:07:44 pm »
Hi Rex

Great stuff, I'll have a play ..

(Where were you when I needed you last year ;) - i made some device controls for it, so rather than just recieve, maybe your plugin can evolve to send codes too. -http://forum.micasaverde.com/index.php/topic,10886.0.html)

I also posted the code I got from Keane to convert Pronto IR codes to KiRA codes, having that working would open up a whole world of devices..
« Last Edit: April 27, 2013, 06:13:12 pm by parkerc »

Offline RexBeckett

  • Master Member
  • *******
  • Posts: 3888
  • Karma: +477/-10
Re: Kira IR Receiver Plugin
« Reply #2 on: April 27, 2013, 06:42:36 pm »
It seemed to me that IR transmit from Vera was pretty well covered. I did follow your thread getting a Kira to work as a transmitter and I thought you had that all up and running. I used the GC100 plugin for my iTach and just made a new device file with Pronto codes for my IR-controlled dimmer. I used the iTach utility for capturing codes and converting to Pronto and it all worked fine.

The glaring hole, for me, was that there didn't seem to be any solutions for Vera to receive IR. I didn't worry too much about having compatibility with Pronto codes - I just made it easy to learn the codes you want to use. It wouldn't be too hard to write a converter from Pronto to KiraRx if that was important to somebody. All the required information is present in Pronto so it would just need translating to the simplified format I have adopted. In practice, though, why not just learn the codes directly to Vera with KiraRx? You don't even have to fiddle around finding the right distance between the receiver and remote. You just fire the remote from the same place you would when using it normally.

What is it that you need done with the code from Keane? If you just need the java converted to Lua, try the following. I tested it with a known Pronto and Kira code on Lua for Windows and it seems to do a good job.

Code: [Select]
function ProntoToKira(pcode)
local pwords = {}
local kwords = {}
local px = 0
for i = 1, #pcode, 5 do
px = px + 1
pwords[px] = tonumber(string.match(string.sub(pcode,i,i+3),"%x+"),16)
end
local freq = math.floor(4145 / pwords[2])
local ct = math.floor(1000/freq)
local n = pwords[3]
if n == 0 then n = pwords[4] end
kwords[1] = string.format("%02X",freq)..string.format("%02X",n)
for i = 5,px do
kwords[i-3] = string.format("%04X",math.floor(pwords[i] * ct))
end
kwords[(n*2)+1] = "2000"
local s = "K"
for i = 1, (n*2)+1 do
s = s.." "..kwords[i]
end
return s
end

local pronto = "0000 006C 0000 0019 0017 0018 0017 0030 002E 0018 0017 0030 002E 0030 002E 0018 0017 0018 0017 0030 0017 0018 002E 0018 0017 0018 0017 0018 0017 0018 0017 0018 0017 0018 0017 0018 0017 0018 0017 0018 0017 0018 0017 0018 0017 0018 0017 0018 0017 0018 0017 0030 002E 0EEE"
local kira = ProntoToKira(pronto)
« Last Edit: April 27, 2013, 08:54:43 pm by RexBeckett »

Offline mda

  • Sr. Member
  • ****
  • Posts: 464
  • Karma: +9/-0
Re: Kira IR Receiver Plugin
« Reply #3 on: April 28, 2013, 12:08:44 am »
Thanks Rex! I have been looking for this solution for years (i kid you not).

Just to confirm, is this the correct Kira module to purchase? http://www.keene.co.uk/electronic/keene-electronics/keene-ir-anywhere-ir-over-ip-module-(single)/KIRAM.html

Thanks

Offline RexBeckett

  • Master Member
  • *******
  • Posts: 3888
  • Karma: +477/-10
Re: Kira IR Receiver Plugin
« Reply #4 on: April 28, 2013, 04:22:56 am »
Yes sir. That is the correct module - if you want a UK power supply. The kit with a Worldwide power supply is http://www.keene.co.uk/electronic/keene-electronics/keene-ir-anywhere-(single-worldwide)/KIRAMW.html. This includes a wall-wart PSU that has interchangeable power plugs (and costs you another tenner).

Let me know how you get on.

Quote
I have been looking for this solution for years...
Not so many years that you're running a Vera 2 on UI4, I hope.  ;)  This plugin is written for UI5 and I can only test it on my Vera Lite.
« Last Edit: April 28, 2013, 06:33:35 am by RexBeckett »

Offline RexBeckett

  • Master Member
  • *******
  • Posts: 3888
  • Karma: +477/-10
Re: Kira IR Receiver Plugin
« Reply #5 on: April 28, 2013, 03:20:39 pm »
I have added some IR code import functions to KiraRx. It can now import Pronto IR codes and standard Kira IR codes. You just paste the complete code string into the import box and then click either Pronto or Kira buttons. The converted KiraRx code can then be saved with an appropriate name.

I would still recommend learning the codes directly from the remote control, though. This gives the best chance of trouble-free recognition.


« Last Edit: April 28, 2013, 03:37:56 pm by RexBeckett »

Offline parkerc

  • Sr. Hero Member
  • ******
  • Posts: 2330
  • Karma: +32/-44
  • Life Moves Pretty Fast....
    • Node Central
Re: Kira IR Receiver Plugin
« Reply #6 on: April 28, 2013, 03:48:24 pm »
Hi Rex

If i get home early enough I'm going to have fun playing witht their new Pronot to Kira Code converter. :)

Are there plans to add 'transmit' so I can recall the codes I've added and have then sent out via the KIRA transmitter? (May e I can then retire my own KiRA plugin device and IR code xmls.?)

Offline RexBeckett

  • Master Member
  • *******
  • Posts: 3888
  • Karma: +477/-10
Re: Kira IR Receiver Plugin
« Reply #7 on: April 28, 2013, 05:59:56 pm »
Quote
If i get home early enough I'm going to have fun playing witht their new Pronot to Kira Code converter.
If you mean the lua code I posted then I hope you do have fun. You can either run it with Lua for Windows (or another Lua environment) or you could build it into your plugin. If you run it in Lua for Windows, put print (kira) after the last line and then you can copy/paste the Kira code string from the output window.

In case is isn't clear, the import function in KiraRx will convert either Pronto or Kira codes to the internal format I am using in KiraRx (which I am calling KiraRx format). It does not convert Pronto to normal Kira code.

As for adding transmit functionality to KiraRx, I have no plans to do that. What is missing from existing IR sending solutions - including your own plugin?
« Last Edit: April 28, 2013, 06:35:53 pm by RexBeckett »

Offline parkerc

  • Sr. Hero Member
  • ******
  • Posts: 2330
  • Karma: +32/-44
  • Life Moves Pretty Fast....
    • Node Central
Re: Kira IR Receiver Plugin
« Reply #8 on: April 29, 2013, 02:42:07 am »
Thanks Rex - youre right i did grab the wrong end if the stick..

Regarding "Transmit'

In my plugin (if i can call it that) I currently run 2 devices, one is the transmitter and the other is the Set Top Box I want to control. The creation of any new IR controllerabke devices requires the compilation of a new XML.

So by the potential looks of what you've built, it could learn a group of RAW commands quite quickly, place them in an XML and potentially have them recalled and transmitted via a scene etc. (making it an all in one device)

Sadly I'm not a programmer, (hence i admire all that are) and the work I did was very much influenced by @Guessed.  He talked me through it. But I always wished my plugin could do more. I never thought about the learn and trigger concept you did, which is cool. I just wanted it to control my AV kit via Vera and I could use apps (like HomeWave) to create a virtual remote etc.

You've breathed new life into my KIRA and I thank you for that :)
« Last Edit: April 29, 2013, 02:53:14 am by parkerc »

Offline RexBeckett

  • Master Member
  • *******
  • Posts: 3888
  • Karma: +477/-10
Re: Kira IR Receiver Plugin
« Reply #9 on: April 29, 2013, 03:44:17 pm »
Well that is a thought. I could create a plugin for Kira Transmitter that used the same concept of a named library of commands so you could just call them by name from a scene. They would have to be real Kira commands - not the compressed ones I use in KiraRx - but we already have the ProntoToKira converter.  :D

Now I'm wishing that I had bought the Kiras as a pair! I may have to use you as an alpha tester...
 

Offline parkerc

  • Sr. Hero Member
  • ******
  • Posts: 2330
  • Karma: +32/-44
  • Life Moves Pretty Fast....
    • Node Central
Re: Kira IR Receiver Plugin
« Reply #10 on: April 29, 2013, 06:10:02 pm »
I may have to use you as an alpha tester...
Happy to help  8)

I have my KIRA set up in Stand Alone mode, so it can both send and receive IR signals, how is yours set up?

Offline RexBeckett

  • Master Member
  • *******
  • Posts: 3888
  • Karma: +477/-10
Re: Kira IR Receiver Plugin
« Reply #11 on: April 29, 2013, 07:13:05 pm »
Mine is set up the same way. I just need to plug in the IR blaster and sit it so the IR bounces off the wall and back to the AV gear. I'll have a play.  ;D

Offline RexBeckett

  • Master Member
  • *******
  • Posts: 3888
  • Karma: +477/-10
Re: Kira IR Receiver Plugin
« Reply #12 on: April 30, 2013, 05:57:15 am »
I added a couple more buttons to allow you to step through your stored codes - so you can remind yourself what you called them. ;D The First button displays the name and code for the first entry in the list and the Next button displays the next one each time it is clicked. Note that, due to the way Lua tables work, the names will not be in any discernible order.

Offline RexBeckett

  • Master Member
  • *******
  • Posts: 3888
  • Karma: +477/-10
Re: Kira IR Receiver Plugin
« Reply #13 on: May 02, 2013, 05:21:04 pm »
I've uploaded a new version of KiraRx. The most noticable change is that you now have to confirm before you delete or overwrite your favorite stored code.  ;)  You also have to confirm before you restore an old backup over your latest, lovingly learned, fully tested and thoughfully named set of codes.  ;D

The new version also contains hooks for the currently-in-alpha KiraTx Transmitter plugin. This looks uncannily like KiraRx and is also based on the concept of a table of stored codes that can be learned or imported. KiraRx and KiraTx work as a team so that there is no unseemly squabble over who owns the UDP port. The two plugins will cheerfully use a single standalone Kira module to give you the ability to trigger scenes or PLxx logic on receipt of named codes and to also send IR codes by name from scenes or PLxx actions. Watch this space for the beta release of KiraTx.

Offline lolodomo

  • Master Member
  • *******
  • Posts: 3484
  • Karma: +74/-10
Re: Kira IR Receiver and Transmitter Plugins
« Reply #14 on: May 03, 2013, 05:43:00 am »
Vey interesting work.

Is the plugin working with the Kira IR anywhere and the kira128 ?
Considering this plugin and Vera usage, is there a reason to choose the kira128 rather than the Kira ?

Can a unique Kira be used internally as a IR relay (transmit a IR signal it receives) ? If not, I imagine that the plugin can allow to do it ? But there will be a noticeable delay between receive and transmit ?

Is the signal strength of the Kira good ? How much directive is the Kira ? Angle ?
How many devices can be controlled by the Kira when using an additional transmitter cable ? Can we use only the Keene cable or can we use cables from other brands ?

http://www.keene.co.uk/pages/iranywhere/Accessories.html
The Kira can be used used with a Powermid ? The Powermid could act as a RF relay and then send the IR signal to the Kira through a jack cable ?
« Last Edit: May 03, 2013, 06:09:52 am by lolodomo »