Announcement

Collapse
No announcement yet.

Capture triggering device in Event

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    Capture triggering device in Event

    I want a single Event with several possible trigger devices (OR) that launches a generic script.
    In that script, I would need to know which device triggered the Event to perform specific actions.

    Until now I have used one (cloned) Event for every device (5-10) and used "hs.GetLastEvent" in my generic script to indirectly identify the device. This is a bit clumsy.

    What is the easiest way to get the triggering device?

    Is really "RegisterStatusChangeCB" the smartest way? It seems like a long way to go to make the callback save a value in a global variable that I read in my generic script. Would just like to seize it directly.

    Thanks,

    Bob
    Last edited by Bobone; August 27, 2018, 05:35 AM.

    #2
    This is one of those things that I put in the requested enhancements, knowing why/where an event trigger has come from I think would be of real value.

    Your best bet (I wouldn't user .getlastevent in case an event managed to sneak in that was nothing to do with it) would probably be to compare the device last change times in your script of the devices of interest and then determine that the last one to have changed is the one that has triggered the event.

    This is part of a script where I do something similar and may give you a head start;

    Code:
    Dim FirstDate As DateTime = DateTime.Now.AddMonths(-6)
    Dim LastDeviceChanged As Integer = -1
    Dim ArrOfDevices() As Integer = {298, 150, 158, 37, 140, 1759, 447, 2386, 2796}
    Dim SetDevice as boolean = false
    
    For Each SingleDevice As Integer In ArrOfDevices
    'hs.writelog("OccChec", "(Ref: " & SingleDevice & ") " & hs.devicename(SingleDevice) & " - Device Last Change: " & hs.devicelastchangeref(SingleDevice))
    If FirstDate < hs.devicelastchangeref(SingleDevice) Then
    FirstDate = hs.devicelastchangeref(SingleDevice)
    LastDeviceChanged = SingleDevice
    End If
    
    Next
    
    hs.writelog("OccCheck", "** ---> Last Device Changed: " & hs.devicename(LastDeviceChanged) & " **")

    Comment


      #3
      hello!

      That was an interesting approach, I'll give it a try!

      The drawback is that I need to keep a list of devices. I would have liked to keep the device list a bit dynamic (with a naming convention).
      Can you run through the list of devices in a "room" or "floor"?

      My "problem" with RegisterStatusChangeCB was also that I have a few timers running that generate lots of change events... I needed to filter them out first.

      As many times, it feels like some responsibility to be CPU efficient...

      Thx,

      Bob

      Comment


        #4
        Originally posted by Bobone View Post
        hello!
        The drawback is that I need to keep a list of devices. I would have liked to keep the device list a bit dynamic (with a naming convention).
        Can you run through the list of devices in a "room" or "floor"?
        My scripting ability is limited to the occasional short immediate script so pardon me for speaking out of school, but might Spud's Easytrigger device group help here? Could it be referenced from a script?
        -Wade

        Comment


          #5
          I do this with multiple events, one for each device. The events all run the same script and pass it the ID of the device that triggered it. (I know. . .multiple events isn't what you asked about. But, it's simple and it works. Just copy the event and edit the name, trigger, and passed parameter to add another device.)
          Mike____________________________________________________________ __________________
          HS3 Pro Edition 3.0.0.548, NUC i3

          HW: Stargate | NX8e | CAV6.6 | Squeezebox | PCS | WGL 800RF | RFXCOM | Vantage Pro | Green-Eye | Edgeport/8 | Way2Call | Ecobee3 | EtherRain | Ubiquiti

          Comment


            #6
            Well, I had multiple events and am trying to clean things up for potentially quite a few sites.


            I suppose I could run through all the devices at start-up and create an array (global variable) of device ids that match a naming criteria...

            Comment


              #7
              Originally posted by Bobone View Post
              Well, I had multiple events and am trying to clean things up for potentially quite a few sites.
              I'm not sure what you mean by clean things up. The way you ID a device in the event for use in the script can be any convention you choose. The unique events can all be in the same event group and be named so they sort together easily.
              Mike____________________________________________________________ __________________
              HS3 Pro Edition 3.0.0.548, NUC i3

              HW: Stargate | NX8e | CAV6.6 | Squeezebox | PCS | WGL 800RF | RFXCOM | Vantage Pro | Green-Eye | Edgeport/8 | Way2Call | Ecobee3 | EtherRain | Ubiquiti

              Comment

              Working...
              X