more G-Labs products

Author Topic: Setting up custom hardware help  (Read 2435 times)

April 16, 2014, 07:01:48 PM
Read 2435 times

betgear

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

I'm very new to HomeGenie, and a little frustrated in trying to get to grips with getting the system up and running and looking for some pointers.

I have no zwave or X10 hardware, and initially I am trying to control some relays controlled over http to an arduino with network shield.

I've programmed the arduino to switch relays on and off controlled by a post request, I've also coded a getStatus request into the arduino to return a string indicating the current status of the relays. I can control the relays just fine using a webbrowser, but would like to move this functionality to HomeGenie.

Ideally I want the switched ON/OFF confirmation to be verified by the arduino, do I get the arduino to send it's status to a specific HG url, or does HG poll the arduino for its status.

I can tailor the code in the arduino to a format that is acceptable to HG (presumably json).

Currently I can send a request to the arduino IP xxx.xxx.xxx.xxx?relay{relay number 0-F){X-on|O-off} and I can request a status xxx.xxx.xxx.xxx?status which returns a string of 1's and 0 indicating the relay switched status for every relay I have.

How would I approach adding this functionality into HG?

I appreciate this is a bit of a big ask, but I don't mind documenting the whole process and supplying the code and circuit diagrams once I've got things working to help others out.

Arduino control is very cheap with arduino clone, Network shield and 8 relay board costing less than £15 in total.

Any help most appreciated.

Forgot to mention I do know c#

Cheers

Glen.

« Last Edit: April 17, 2014, 10:15:21 PM by betgear »

April 16, 2014, 07:34:32 PM
Reply #1

Gene

  • *****
  • Information
  • Administrator
  • Posts: 1472
  • Tangible is the future!
    • Yet Another Programmer
You can just adapt the "Arduino Switches" program that you will find in Configure->Automation->RaspberrySharp section.

Modify both the Trigger Code and the Code to Run.
In the Trigger Code you tell how many relays in your setup, by changing the following line accordingly:

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

change the last number (3) to match your setup.

In the code to run you'll have to add webservice calls to the arduino box in place of the lines marked with // TODO: Send command by serial port.
A webserice call is made by using the command:

Code: [Select]
Net.WebService("http://my_arduino_address/my_api_call").Call();

After updating this program you will get new switches modules in the system. You can add these modules to a group for controlling them or use them in other automation programs and macros just as standard switch modules.

To get better understanding about how things work in HG have a look at:

http://www.homegenie.it/docs_api/overview.html
http://www.homegenie.it/docs_api/advanced.html

If you're going to control Arduino via serial I/O, you can have a look at this Instructable post:

http://www.instructables.com/id/Home-Automation-with-HomeGenie/

Hope this helps.

Cheers,
g.

April 17, 2014, 12:25:01 PM
Reply #2

betgear

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

Thanks for that.

How would I go about triggering a module event externally? Is this a case of getting the arduino to send a request to the specific modules web url?

Cheers

Glen.
« Last Edit: April 17, 2014, 10:15:40 PM by betgear »

April 17, 2014, 02:52:27 PM
Reply #3

Gene

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

April 17, 2014, 08:28:29 PM
Reply #4

betgear

  • *
  • Information
  • Newbie
  • Posts: 5
Next dum questions  ;D

Say I have a few of the above interfaces, and I want to clone the ardunio switches program, can I do this from the web ui, or do I need to copy and rename the program within the relevant directory.

I notice on the web interface a system status fade in and out very quickly in the top left corner, it's too fast to really read, is this intended, it appears in both chrome and internet explorer.

The export program appears to keep the => encoding rather than the => symbols is this a bug.

After exporting a program, can they be imported again (after editing), if they can, do I need to change the html character encoding with the correct text, example above => to =>

I love the work you've done on this, and I'm slowly getting to grips with it.

Cheers

Glen.

« Last Edit: April 17, 2014, 10:15:53 PM by betgear »

April 17, 2014, 09:00:28 PM
Reply #5

Gene

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

when you export a program, this is not meant to be read/edited with a text editor. It is meant to be later imported using the "Import Program" functionality that you'll find in the "Actions" menu of any automation group page.
You don't need to change > nor any other encoded character... these encoded characters are decoded when importing.

If you want to duplicate a program, simply export and then import it. You can then rename it if you need to.

So, if you want to use the Arduino Switches program with other interfaces, after importing it, you have also to change all "Arduino.Switches" strings you'll find both in the Code to Run and the Trigger Code.
This is because the "Arduino.Switches" string defines the "domain" of your program's modules, so each program should have its own, otherwise will conflict with the other one.

See also this topic about a similar question:
http://www.homegenie.it/forum/index.php?topic=145.msg780#new

The event popup shows up for about 5 seconds. You can however read the logs if you missed something.

Please change the topic of this thread, because it's not indicative at all for other users that may be looking for similar questions/answers.

Cheers,
g.

April 17, 2014, 09:58:50 PM
Reply #6

betgear

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

Thanks for all the help, I've changed the title :)

I really liking this application, it deserves to do well.

Cheers

Glen.


April 17, 2014, 11:44:16 PM
Reply #7

betgear

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

I've got my relays working now thanks, but I occasionally get an errors notification when going into the code

Errors:

1. []

Program disabled, fix errors first.


Obviously there is no error message to help track the issue down, any pointers?

Cheers

Glen.


April 17, 2014, 11:56:23 PM
Reply #8

Gene

  • *****
  • Information
  • Administrator
  • Posts: 1472
  • Tangible is the future!
    • Yet Another Programmer
It's a UI bug. Just ignore it. It has been fixed in r365.
Thanks for reporting.

g.