more G-Labs products

Author Topic: Trying to get RFX433 Devices working  (Read 10718 times)

August 09, 2014, 01:33:27 PM
Read 10718 times

baptist

  • **
  • Information
  • Jr. Member
  • Posts: 27
For me HG does everything with the slight exception of RFX433. (I have a whole load of various LightwaveRF switches)

First of all I managed to adapt the 'Serial Port I/O Test' program and managed to send the correct byte data to turn on some light switches on / off. Since then, for the last few days I've been trying to adapt different programs to create modules. However with my limited C# skills, really struggling..

This is where I got to, but still getting errors
Code: [Select]
var moduleDomain = "HomeGenie.RFX";
var portname = "/dev/ttyUSB0";

SerialPort
  .WithName( portname )
  .Connect( 38400 ); // change baud rate if needed

while (Program.IsEnabled)
 
//

   
    When.WebServiceCallReceived("HomeGenie.RFX", ( args ) =>
    {
        string[] reqs = ((string)args).Split('/');
        var res = "{ 'ResponseValue' : 'ERROR' }";
   
        try
        {
            string command = reqs[2];
            var module = Modules.InDomain("HomeGenie.RFX").WithAddress("1").Get();
    switch(command)
    {
         
         
              case "Control.On":
              byte[] message = { 0x0A, 0x14, 0x00, 0x02, 0xF4, 0x5F, 0x59, 0x01, 0x01, 0x00, 0x00 };
                Program.RaiseEvent(module, "Status.Level", "1", "RFX");
                res = "{ 'ResponseValue' : 'OK' }";
                break;
                           
              case "Control.Off":
              byte[] message2 = { 0x0A, 0x14, 0x00, 0x02, 0xF4, 0x5F, 0x59, 0x00, 0x01, 0x00, 0x00 };
                Program.RaiseEvent(module, "Status.Level", "0", "RFX");
                res = "{ 'ResponseValue' : 'OK' }";
                break;
         
      }
}
catch (Exception ex)
{
    res = ex.Message + " " + ex.StackTrace;
}
// unable to process request
return res;
});
//
Program.GoBackground();

Any advice would be much appreciated
« Last Edit: August 25, 2014, 07:44:49 PM by baptist »

August 09, 2014, 02:26:01 PM
Reply #1

Gene

  • *****
  • Information
  • Administrator
  • Posts: 1472
  • Tangible is the future!
    • Yet Another Programmer
Hi baptist,

to access virtual modules from your program you've to create them first. See this:

http://www.homegenie.it/docs/automation_advanced.php

read the paragraph about virtual modules.

Anyway I was in the will of porting this https://github.com/opensourceautomation/Open-Source-Automation/blob/master/Plugins/OSAE.RFXCOM/OSAE.RFXCOM.cs to a MIG Interface class.
HG r408 was refactored to facilitate the process of adding interfaces to mig/homegenie, so it might be the right moment of doing this since you have hardware to test.
Still I'm looking for some users with Insteon hardware... do you know any? =)

Cheers,
g.

August 09, 2014, 03:06:30 PM
Reply #2

baptist

  • **
  • Information
  • Jr. Member
  • Posts: 27
Thanks Gene, I'll try to create a Virtual module.
Sorry I don't have access to INSTEON  devices.
I only have several LightwaveRF wall dimmers / mains sockets and a Lightwave PIR.
Also hard wired PIR's door contacts to MCP23017's > HG

August 09, 2014, 08:44:53 PM
Reply #3

baptist

  • **
  • Information
  • Jr. Member
  • Posts: 27
Hi Gene .. Sorry but I'm still getting errors. Can you let me know where I.m going wrong, Many Thanks

Code: [Select]
Program.AddVirtualModules("Components.RFX", "Switch", "homegenie/generic/RFX", 1, 1);

var portname = "/dev/ttyUSB0";
SerialPort
  .WithName( portname )
  .Connect( 38400 );   
    When.WebServiceCallReceived("HomeGenie.RFX", ( args ) =>
    {
        string[] reqs = ((string)args).Split('/');
        var res = "{ 'ResponseValue' : 'ERROR' }";
   
        try
        {
            string command = reqs[2];
            var module = Modules.InDomain("HomeGenie.RFX").WithAddress("1").Get();
    switch(command)
    {
         
         
              case "Control.On":
              byte[] message = { 0x0A, 0x14, 0x00, 0x02, 0xF4, 0x5F, 0x59, 0x01, 0x01, 0x00, 0x00 };
                SerialPort.SendMessage(message);
               Program.RaiseEvent(module, "Status.Level", "1", "RFX");
                res = "{ 'ResponseValue' : 'OK' }";
                break;
                           
              case "Control.Off":
              byte[] message2 = { 0x0A, 0x14, 0x00, 0x02, 0xF4, 0x5F, 0x59, 0x00, 0x01, 0x00, 0x00 };
                 SerialPort.SendMessage(message2);
                Program.RaiseEvent(module, "Status.Level", "0", "RFX");
                res = "{ 'ResponseValue' : 'OK' }";
                break;
         
      }
}
catch (Exception ex)
{
    res = ex.Message + " " + ex.StackTrace;
}
// unable to process request
return res;
});
//
Program.GoBackground();


The program saves without errors, (shows a green symbol )however when I tried to add the switch into the group, I get the question mark error icon.. Any advice much appreciated.
« Last Edit: August 09, 2014, 10:26:39 PM by baptist »

August 10, 2014, 02:49:01 PM
Reply #4

Gene

  • *****
  • Information
  • Administrator
  • Posts: 1472
  • Tangible is the future!
    • Yet Another Programmer
Hi baptist,

I suppose the widget specified is wrong.
Try changing "homegenie/generic/RFX" with "homegenie/generic/switch", for a list of existing widgets see:

http://www.homegenie.it/docs/automation_widgets.php

cheers,
g.

August 10, 2014, 05:30:42 PM
Reply #5

baptist

  • **
  • Information
  • Jr. Member
  • Posts: 27
Thanks Gene, I now have the widget. But when I operate Control.On I don't see any activity on the RFX device. (When I modify the program 'Serial Port I/O Test' with the correct byte information it works) :'(


Code: [Select]
Program.AddVirtualModules("Components.RFX", "Switch", "homegenie/generic/switch", 1, 1);

var portname = "/dev/ttyUSB0";
SerialPort
  .WithName( portname )
  .Connect( 38400 );   
    When.WebServiceCallReceived("HomeGenie.RFX", ( args ) =>
    {
        string[] reqs = ((string)args).Split('/');
        var res = "{ 'ResponseValue' : 'ERROR' }";
   
        try
        {
            string command = reqs[2];
            var module = Modules.InDomain("HomeGenie.RFX").WithAddress("1").Get();
    switch(command)
    {
         
         
              case "Control.On":
              byte[] message = { 0x0A, 0x14, 0x00, 0x02, 0xF4, 0x5F, 0x59, 0x01, 0x01, 0x00, 0x00 };
                SerialPort.SendMessage(message);
               Program.RaiseEvent(module, "Status.Level", "1", "RFX");
                res = "{ 'ResponseValue' : 'OK' }";
                break;
                           
              case "Control.Off":
              byte[] message2 = { 0x0A, 0x14, 0x00, 0x02, 0xF4, 0x5F, 0x59, 0x00, 0x01, 0x00, 0x00 };
                 SerialPort.SendMessage(message2);
                Program.RaiseEvent(module, "Status.Level", "0", "RFX");
                res = "{ 'ResponseValue' : 'OK' }";
                break;
         
      }
}
catch (Exception ex)
{
    res = ex.Message + " " + ex.StackTrace;
}
// unable to process request
return res;
});
//
Program.GoBackground();

August 10, 2014, 06:19:43 PM
Reply #6

Gene

  • *****
  • Information
  • Administrator
  • Posts: 1472
  • Tangible is the future!
    • Yet Another Programmer
Hi baptist,

when you click on the ON/OFF button the widget will be calling this url:

http://192.168.0.2/api/Components.RFX/1/Control.On/

so

Code: [Select]
When.WebServiceCallReceived("HomeGenie.RFX", ( args ) =>

must be changed in order to handle api calls starting with "Components.RFX" rather than "HomeGenie.RFX"

Code: [Select]
When.WebServiceCallReceived("Components.RFX", ( args ) =>

to see if your program is responding to commands try opening the api url in your browser. It should respond with "{ResponseValue: OK}".

Cheers,
g.

August 10, 2014, 07:39:46 PM
Reply #7

baptist

  • **
  • Information
  • Jr. Member
  • Posts: 27
Many Thanks Gene..
That worked..  :)

Also the Widget turns the light on / off however the animation of the switch doesn't.. ?

For anyone else who hac RFXCOM 433 + LightwaveRF Switches
Code: [Select]
Program.AddVirtualModules("Components.RFX", "Switch", "homegenie/generic/switch", 1, 1);

var portname = "/dev/ttyUSB0";
SerialPort
  .WithName( portname )
  .Connect( 38400 );   
    When.WebServiceCallReceived("Components.RFX", ( args ) =>
    {
        string[] reqs = ((string)args).Split('/');
        var res = "{ 'ResponseValue' : 'ERROR' }";
   
        try
        {
            string command = reqs[2];
            var module = Modules.InDomain("HomeGenie.RFX").WithAddress("1").Get();
    switch(command)
    {
         
         
              case "Control.On":
              byte[] message = { 0x0A, 0x14, 0x00, 0x02, 0xF4, 0x5F, 0x59, 0x01, 0x01, 0x00, 0x00 };
                SerialPort.SendMessage(message);
               Program.RaiseEvent(module, "Status.Level", "1", "RFX");
                res = "{ 'ResponseValue' : 'OK' }";
                break;
                           
              case "Control.Off":
              byte[] message2 = { 0x0A, 0x14, 0x00, 0x02, 0xF4, 0x5F, 0x59, 0x01, 0x00, 0x00, 0x00 };
                 SerialPort.SendMessage(message2);
                Program.RaiseEvent(module, "Status.Level", "0", "RFX");
                res = "{ 'ResponseValue' : 'OK' }";
                break;
         
      }
}
catch (Exception ex)
{
    res = ex.Message + " " + ex.StackTrace;
}
// unable to process request
return res;
});
//
Program.GoBackground();

Control On
Lighting5 command:0A 14 00 02 F4 5F 59 01 01 00 00


Control Off
Lighting5 command:0A 14 00 03 F4 5F 59 01 00 00 00

August 10, 2014, 07:45:31 PM
Reply #8

Gene

  • *****
  • Information
  • Administrator
  • Posts: 1472
  • Tangible is the future!
    • Yet Another Programmer
Hi baptist... this was a very interactive session =)
Also the module domain specified in your code is wrong. Should be **"Components.RFX"** as well.

Code: [Select]
var module = Modules.InDomain("Components.RFX").WithAddress("1").Get();

so how are you using this piece of code?

Cheers,
g.

August 10, 2014, 08:44:02 PM
Reply #9

baptist

  • **
  • Information
  • Jr. Member
  • Posts: 27
Thanks Again Gene, that fixed the animation on the Widget :)
Brilliant !

I used the RFXmngr software which I downloaded from http://www.rfxcom.com/downloads.htm
to work out the correct byte's to transmit

I also had to upgrade the firmware on the RFXtrx to v77 to get it work correctly with LightwaveRF.

I,ve just got work out have to add multiple switches..


August 14, 2014, 01:13:57 AM
Reply #10

baptist

  • **
  • Information
  • Jr. Member
  • Posts: 27
Thanks for the fantastic support, however I'm afraid my lack of knowledge of C# is letting me down.
I managed to get a single switch to work fine, in fact the code below allows one switch to work correctly, also using the api I can get all 3 to operate but no matter how I try I can't get more than one to  oporate from the GUI.. Can anyone advise, much appreciated.

Code: [Select]
Program.AddVirtualModules("Components.RFX433A", "Switch", "homegenie/generic/switch", 1, 3);

var portname = "/dev/ttyUSB0";
SerialPort
  .WithName( portname )
  .Connect( 38400 );   
    When.WebServiceCallReceived("Components.RFX433A", ( args ) =>
    {
        string[] reqs = ((string)args).Split('/');
        var res = "{ 'ResponseValue' : 'ERROR' }";
   
        try
        {
            string command = reqs[2];
            var module1 = Modules.InDomain("Components.RFX433A").WithAddress("1").Get();
            var module2 = Modules.InDomain("Components.RFX433A").WithAddress("2").Get();
            var module3 = Modules.InDomain("Components.RFX433A").WithAddress("3").Get();
          switch(command)
    {
         
         
              case "Control.On":
              byte[] message = { 0x0A, 0x14, 0x00, 0x02, 0xF4, 0x5F, 0x59, 0x01, 0x01, 0x00, 0x00 };
                SerialPort.SendMessage(message);
               Program.RaiseEvent(module1, "Status.Level", "1", "RFX433A");
                res = "{ 'ResponseValue' : 'OK' }";
                break;
                           
              case "Control.Off":
              byte[] message2 = { 0x0A, 0x14, 0x00, 0x02, 0xF4, 0x5F, 0x59, 0x01, 0x00, 0x00, 0x00 };
                 SerialPort.SendMessage(message2);
                Program.RaiseEvent(module1, "Status.Level", "0", "RFX433A");
                res = "{ 'ResponseValue' : 'OK' }";
                break;
       
              case "Control2.On":
              byte[] message3 = { 0x0A, 0x14, 0x00, 0x02, 0xF3, 0x17, 0xE0, 0x08, 0x01, 0x00, 0x00 };
                SerialPort.SendMessage(message3);
               Program.RaiseEvent(module2, "Status.Level", "1", "RFX433A");
                res = "{ 'ResponseValue' : 'OK' }";
                break;
                           
              case "Control2.Off":
              byte[] message4 = { 0x0A, 0x14, 0x00, 0x02, 0xF3, 0x17, 0xE0, 0x08, 0x00, 0x00, 0x00 };
                 SerialPort.SendMessage(message4);
                Program.RaiseEvent(module2, "Status.Level", "0", "RFX433A");
                res = "{ 'ResponseValue' : 'OK' }";
                break;
           
                          case "Control3.On":
              byte[] message5 = { 0x0A, 0x14, 0x00, 0x02, 0xF3, 0x17, 0xE0, 0x0D, 0x01, 0x00, 0x00 };
                SerialPort.SendMessage(message5);
               Program.RaiseEvent(module3, "Status.Level", "1", "RFX433A");
                res = "{ 'ResponseValue' : 'OK' }";
                break;
                           
              case "Control3.Off":
              byte[] message6 = { 0x0A, 0x14, 0x00, 0x02, 0xF3, 0x17, 0xE0, 0x0D, 0x00, 0x00, 0x00 };
                 SerialPort.SendMessage(message6);
                Program.RaiseEvent(module3, "Status.Level", "0", "RFX433A");
                res = "{ 'ResponseValue' : 'OK' }";
                break;
         
      }
}
catch (Exception ex)
{
    res = ex.Message + " " + ex.StackTrace;
}
// unable to process request
return res;
});
//
Program.GoBackground();
« Last Edit: August 14, 2014, 01:17:45 AM by baptist »

August 14, 2014, 02:02:49 AM
Reply #11

Gene

  • *****
  • Information
  • Administrator
  • Posts: 1472
  • Tangible is the future!
    • Yet Another Programmer
Hi baptist,

have a look at the source code of Philips hue. I think it will help.

Cheers,
g.

August 14, 2014, 02:32:28 AM
Reply #12

Gene

  • *****
  • Information
  • Administrator
  • Posts: 1472
  • Tangible is the future!
    • Yet Another Programmer
See attachment, let me know if this works.

g.
« Last Edit: August 14, 2014, 02:34:43 AM by Gene »

August 14, 2014, 08:38:49 AM
Reply #13

baptist

  • **
  • Information
  • Jr. Member
  • Posts: 27
Thanks Gene, But the attached hgx file would not install :(
I editted the file ang changed

Code: [Select]
    When.WebServiceCallReceived("Components.RFX433A", ( args ) =>
to

Code: [Select]
    When.WebServiceCallReceived("Components.RFX433A", ( args ) =>
and it Worked .. Brilliant !!!

Attached working copy :)

Thanks Again you are the best !



August 19, 2014, 10:45:44 PM
Reply #14

jjr

  • *
  • Information
  • Newbie
  • Posts: 15
Hi
Would it be possible to make a homebrew 433MHz RF Transceiver work with RFX433 software? Or do we need to purchase the usb dongle?