more G-Labs products

Author Topic: Inadvertently created a HomeGenie black-hole. Sorry.  (Read 381 times)

November 28, 2016, 07:52:22 PM
Read 381 times

sc_kyle

  • *
  • Information
  • Newbie
  • Posts: 1
Ok, admittedly this is a weird scenario...  I have two HomeGenie servers using Raspberri Pi hardware. 

HG #1 is at the end of my driveway and I use it to open my gate, monitor the status of the gate (open/closed), monitor the mailbox (once opened I know the mail has arrived), and a few other sensors such as PIR, etc.  All of this through GPIO w/ wired magnetic switches, wired PIR sensors, and a relay board is used to trigger the gate opener if I need to open the gate via the HG app.

HG #2 is inside my house.  It has a Z-Wave module and is used for more traditional home automation stuff.  Lights mostly.  I also use the GPIO (with a relay board) to interface with my alarm system so I can open/close a relay wired to a contact on the alarm system.

I am using Sensor.* events forwarding and Status.Level events forwarding from HG #1 to HG #2.  BUT, ideally I'd like to be able to send these events in both directions.  Here's the use case.  Someone pulls into the gate and opens it.  HG #1 sends the open contact sensor event to HG #2, which then opens a relay on HG #2 connected to my alarm system.  Then I'm notified by the alarm system (via a chime, voice, whatever) that the gate has been opened.  I have all of this working today.  The issue is with sending an event BACK to HG #1 from HG #2 via the events forwarding program.  I'd love to be able to control lights, etc. at the end of my driveway via  HG #2 since I use it as my home automation server.  If I enable events forwarding on both HG servers, the forwarded events get forwarded back to the other HG server, creating an infinite loop of events, and creating hundreds of 'sensors'.  Eventually both HG servers crash.  I found it hilarious when I figured this out...  I don't know what I expected to happen.   :D

TL:DR, is there a way to forward events (both directions) between multiple HG servers without creating an infinite loop?

November 29, 2016, 04:08:50 PM
Reply #1

bkenobi

  • *****
  • Information
  • Global Moderator
  • Posts: 1525
I don't have a solution to your specific situation as I don't forward events.  But, is it possible to use an MQTT approach instead?  In doing so, you would have a single MQTT broker on some system and the other systems would connect as clients to see the same data at the same time thus no rebroadcasting of the same message.  I'm not sure how this would be implemented as I don't use the built-in MQTT stuff, but I know some people here have/do and might offer additional help.

November 29, 2016, 10:01:37 PM
Reply #2

nolio

  • *****
  • Information
  • Global Moderator
  • Posts: 544
Another idea is to edit "Sensor.* events forwarding" program to only forward an event if the device exist on the device list on local configuration.
You can try something like this (but i just compile succeed but i can't test, i don't have 2 HG for now) :
Code: [Select]
// We want to do further processing whenever a module changes
When.ModuleParameterChanged( (module, property) => {
  bool localdevice = true;
  var celladdress  = Program.Option("CellAddress").Value;
  var cellusername = Program.Option("CellUsername").Value;
  var cellpassword = Program.Option("CellPassword").Value;
  // ROUTE METERING EVENT TO REMOTE HG CELL
  if (!celladdress.Contains("?") && property.Name.StartsWith("Sensor."))
  {
    try { Modules.WithName(module.Instance.Name).Get(); //////
        } catch { //////
      localdevice = false; //////
    } //////
    if ( localdevice ) { //////
      Net
        .WithCredentials(cellusername, cellpassword)
        .SignalModuleEvent(celladdress, module, property);
    } //////
  }
  // returning true, will route event to other listeners
  return true;
});
Program.GoBackground();
« Last Edit: November 29, 2016, 10:03:51 PM by nolio »