more G-Labs products

Author Topic: Global Cache IR support  (Read 2626 times)

June 15, 2015, 07:27:51 PM
Read 2626 times

WarStreet

  • *
  • Information
  • Newbie
  • Posts: 5
This automation program module support Global Cache IP2IR and WF2IR. Might work with Global Cache itach flex too if it is using the same TCP API. I only have IP2IR for now.

These devices can send signals to control any infra red devices. Currently I use it for tv, projector, amplifier, HDMI 4x 2x matrix switch, dreambox, android box and air-conditioner. A number of interesting stuff can be achieved by controlling infra-red devices :) Program has been used for a number of months and it works well.

Only Major problem I have encountered so far is when the module is accessed while the global cache device is not in the network, after which the global cache and/or HomeGenie devices might need rebooting. So I access the Global Cache device only when it is on the network. (Note: It takes a few seconds for the global cache device to be in the network after switching it's power on)

The module can support multiple global cache devices, but an extra line for every device is needed to be added. Comments in the Trigger code should help achieving this.  Keep in mind I did this program with nearly no experience on C and HomeGenie, so there could be possibility of improvements to make it better and easier to use. So, hopefully others will improve it and maybe also eventually added in HomeGenie.

I have added an example of a TV module, to show how it can be used. I have uploaded this since it is the easiest example I have.

Once the module is installed, the Global Cache IP input field need to be inserted.

Then any other module can access the Global Cache module like the following:

Code: [Select]
var globalCacheModuleNumber = "1"; // Setting the Global Cache module number to use in case there is more than one Global Cache device.
var globalCacheModules = Modules.InDomain("HomeAutomation.GlobalCache");
var globalCacheModule = globalCacheModules.WithAddress(globalCacheModuleNumber).Get();

string tvRemoteOn = "sendir,1:3,1,38343,1,1,170,172,21,65,21,65,21,65,21,22,21,22,21,22,............, 21,22"; // Change this to the IR command needed
globalCacheModule.Command("Control.Send").Set(tvRemoteOn); // Will simply execute the required IR code on the Global Cache device


NOTE: seems the newer versions of HomeGenie has deprecated the Program.AddInputField to a newer command with different number of arguments. I didn't find any documentation or anything about it on the forum, and don't have time to search it up. The module still works well, but it will be great if someone update the code with the newer command.

Hope you like it.
Horace


« Last Edit: June 15, 2015, 09:39:09 PM by WarStreet »

June 15, 2015, 08:47:01 PM
Reply #1

Gene

  • *****
  • Information
  • Administrator
  • Posts: 1472
  • Tangible is the future!
    • Yet Another Programmer
Instead of the deprecated Program.AddInputField you can use:

Code: [Select]
Program.AddOption("<name>", "<default_value>", "<description>", "text");

"text" is the field type of the option. In the future values like "checkbox", "number" will be also possible, like it is already working for program feature fields.

Instead of Program.InputField use Program.Option.

Cheers,
g.

June 15, 2015, 09:26:36 PM
Reply #2

WarStreet

  • *
  • Information
  • Newbie
  • Posts: 5
Thanks Gene, I will have access to the code on the weekend and will change it to the newer function name.

Horace

January 03, 2016, 06:13:56 PM
Reply #3

ejr1283

  • *
  • Information
  • Newbie
  • Posts: 1
I know this is an old topic, but rather than starting a new post I figured it would be easier to ask here.  I am using your global cache program with a Global Cache iTach WF2IP.  It works well to turn on and off devices.  I would like to use it to change tv channels, etc.  Can you please tell me how I could add additional commands, such as "Digit 1", etc.  Any help would be greatly appreciated.

Thanks

January 09, 2016, 05:13:58 PM
Reply #4

WarStreet

  • *
  • Information
  • Newbie
  • Posts: 5
Hi ejr1283,

you have pieces of code like the one below in the tv example. You can add as many as you wish by copying this code and create a new command name. Instead of "Control.On" you can add yours, for example "Control.Channel.1". You will need to create a new variable holding the infra red command. The example below is using tvRemoteOn variable which is defined at the top of the program.

All the commands can be accessed by a web service and the comments in the code show how it can be accessed. So for the example below you can access it with
http://<hg_address>/api/HomeAutomation.TV/<module_number>/Control.On

If your new command will be Control.Channel.1, it will be accessed  by
http://<hg_address>/api/HomeAutomation.TV/<module_number>/Control.Channel.1

Code: [Select]
// eg. http://<hg_address>/api/HomeAutomation.TV/<module_number>/Control.On
case "Control.On":
    Program.RaiseEvent(tvModule, "Status.Level", "1", "TV");
    // Send command to Global Cache device to send the required IR code.
    globalCacheModule.Command("Control.Send").Set(tvRemoteOn);
break;

Via these web service you can control all your commands from devices such as mobile.

Unfortunately, if you want an interface on homegenie with multiple buttons, I didn't checked on how to do that, so I am not able to help. but for sure it can be done and others will help out.

A neater example of creating a single command for changing all the channels is the following which support parameters. This is an HDMI matrix device command example which has 2 input channels and 4 output channels:

Here is an array with 2 elements representing the input and output channel, defined at the top of the program.

Code: [Select]
// Define the Global Cache sendir HDMI output/input channel command here. Example hdmiRemoteChannel[1,2] represents HDMI output 1 and HDMI Input 2.
hdmiRemoteChannel[1,1] = "sendir,1:1,1,37650,1,1,341,170,21,22,2....etc";
hdmiRemoteChannel[1,2] = "sendir,1:1,1,37537,1,1,341,170,21,22,2....etc";
hdmiRemoteChannel[2,1] = "sendir,1:1,1,37650,1,1,341,170,21,22,2... etc";

And here is the command to change the channels accepting 2 parameters, the input channel and the output one. In your case you will need only 1 parameter if you want to change tv channels, and this piece of code will need to be modified.
Code: [Select]
// eg. http://<hg_address>/api/HomeAutomation.HDMImatrix/<module_number>/Control.Remote/<hdmi output channel>,<hdmi input channel>
case "Control.Remote":
     string[] values = parameter.Split(',');
     int hdmiOutput = int.Parse(values[0]);
     int hdmiInput = int.Parse(values[1]);
                 
     if ((hdmiOutput == 1 || hdmiOutput == 2) && (hdmiInput >= 1 && hdmiInput <= 4))
     {                                                                                                                                          
          globalCacheModule.Command("Control.Send").Set(hdmiRemoteChannel[hdmiOutput, hdmiInput]);

          Program.Parameter("HDMImatrix.Output" + hdmiOutput.ToString()).Value = hdmiInput.ToString(); // Sets the selected HDMI output to the selected HDMI input number .
          Program.RaiseEvent(hdmiMatrixModule, "Status.Level", Program.Parameter("HDMImatrix.Output1").Value + Program.Parameter("HDMImatrix.Output2").Value, "HDMImatrix");
     }
break;
« Last Edit: January 09, 2016, 05:17:52 PM by WarStreet »

January 24, 2016, 06:02:19 AM
Reply #5

cplBlutch

  • *
  • Information
  • Newbie
  • Posts: 17
Hi Horice,

I got stuck, the modules are running, the IP is set. But I have no idea how to setup a virtual button to send a IR code to the IP2IR

Very frustrating, can you give me a hint?

February 28, 2016, 02:02:20 AM
Reply #6

cplBlutch

  • *
  • Information
  • Newbie
  • Posts: 17

March 18, 2016, 01:40:10 PM
Reply #7

cplBlutch

  • *
  • Information
  • Newbie
  • Posts: 17
I bought a HDHOMERUN 4DC so I can watch TV in KODI now and don't need the global cache IP2IR anymore to switch my HDMI signals .. Expensive but great workaround ;-)