Announcement

Collapse
No announcement yet.

Easytrigger Global Variables Scripting Help

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

    Easytrigger Global Variables Scripting Help

    I am looking for some help developing a script that can leverage the Easytrigger global variables to perform an action on a grouped device that changes. Here is the example I am working on. In this case, if a network device goes offline (such as the wireless adapter on a Z-Net), Easytrigger can act on the trigger, and reboot the Z-Net using the LAN adapter (which always results in the WLAN reconnecting). I have done this in the past with an individual script for each Z-Net (I have 9 total), but I am looking to combine into one event / script.

    I know very little about VB (I have much more experience with Powershell), but I was thinking a switch statement would do what I want. Here is what I do already to send an e-mail notification leveraging the EasyTrigger variable:

    Click image for larger version

Name:	image.png
Views:	350
Size:	149.0 KB
ID:	1568687

    This works quite well, and results in the message telling me which connection has failed, etc.

    What I want to do next is to use the $GlobalVar to actually reboot the offending device (using the LAN connection) with one script, instead of one script per device as I do now. I though that using the SWITCH command would be a logical start:

    Click image for larger version

Name:	image.png
Views:	210
Size:	109.3 KB
ID:	1568689
    In my script, The first element of the Switch function is the Device Name string in Homeseer, and the second element is the IP address of the LAN connection of that Z-Net. As a single event for each Z-Net, I have used this for years to force a reboot if the network connection dropped:

    Dim IP As String = "192.168.1.66:80"
    Dim URLStr As String = ""
    Dim ReplyStr As String = ""

    Sub Main(ByVal Parms As Object)

    'Garage Z-Net: this will reboot Z-Net Garage using the LAN connection

    URLStr = "http://" & IP & "/Main/Reboot.php"

    ReplyStr = hs.urlaction(URLStr,"GET","","")

    End Sub



    Unfortunately, this is where I hit the wall. I don't know how to take the $$GLOBALVAR:ETDeviceName: variable from the trigger (as a parameter?), switch the data to get the IP address, and then run the reboot script. I just cannot wrap my mind around it.

    I am hoping someone who is a real programmer on here can help me put it all together. If I can make this work, I can use ET to consolidate a LOT of my events just like I do with e-mail notifications now.

    I would also like to write out something to the Homeseer log when this happens. I have experimented with something like this, but it just returns a error even as an immediate script command:



    &nhs.writelog "Error", "$$GLOBALVAR:ETDeviceName: is offline and will be rebooted."



    Any help would be greatly appreciated!!

    Attached Files

    #2
    Try this
    Code:
    Sub Main(p As Object)
    
        Dim ZNet, IP As String
        ZNet = hs.GetVar("ETDeviceName")
        IP = Switch(
            ZNet = "Z-Net Name 1", "192.168.1.100",
            ZNet = "Z-Net Name 2", "192.168.1.101"
        )
    
    
        If IP <> "" Then
            hs.WriteLogEx("Z-Net Reboot", "Sending reboot command to " & IP", "#ff0000")
            hs.GetURL(IP, "/Main/Reboot.php", False, 80)
        Else
            hs.WriteLogEx("Z-Net Reboot", "No IP address match for " & ZNet, "#ff0000")
        End If
    
    End Sub​
    Note there is no comma after the final entry of the name to IP match list.

    Comment


      #3
      Thanks! So to make sure I understand the logic behind this, what does (p as Object) represent? I think I understand that the Dim statement is defining the elements of the Device Name and the IP address (like an array?). Then the next part is saying If IP address in not empty, then write out the log and call for the URL that reboots the device. The port is 80, but what is False? Finally, if IP is empty, it just error traps and writes out a statement to the log.


      So let me ask another question. If instead of calling a URL, I want to do something in Homeseer like turning a device on or off instead, what would be the command? The trigger would be the same (If any device in group xxxxx changes and becomes), then (do something). Instead of hs.getURL, what would be the command to turn the device on or off? hs.setdevicevalue?

      Comment


        #4
        Originally posted by bebaldin View Post
        what does (p as Object) represent?
        HS passes one 'Object' parameter to a script. Not used in this case.

        The port is 80, but what is False?
        https://help.homeseer.com/help/HS3/s...nternet_geturl

        GetURL function takes four parameters: host, page, strip_tags, port. Since the result isn't used, the strip_tags parameter is a don't care.

        So let me ask another question. If instead of calling a URL, I want to do something in Homeseer like turning a device on or off instead, what would be the command? The trigger would be the same (If any device in group xxxxx changes and becomes), then (do something). Instead of hs.getURL, what would be the command to turn the device on or off? hs.setdevicevalue?
        Depends on if the device you want to set is a virtual device or a physical device.

        If it's a virtual device, you can use
        hs.SetDeviceValue
        hs.SetDeviceValueByRef
        hs.SetDeviceValueByName


        If it's a physical device, you'll need to use the CAPI interface. I don't have any examples of that at hand, but there are examples on the forum if that's what you want.

        Comment


          #5
          Thanks again! You have given me much to experiment with, and a little better understanding of VB scripting. I am looking forward to seeing what I can do with this in my setup!!!

          Comment


            #6
            Great! And turns out I have one example where I used the CAPI interface, from before I realized I could do it simpler with EasyTrigger. So If you decide you can use that let me know.

            Comment


              #7
              The script for the reboot works perfectly. I haven't had a chance to play around with modifying it for on/off functions yet. I do use a lot of variable devices but I would also be interested in learning about the CAPI interface for groups of physical devices. Again, thanks for taking the time to teach me something about this; it makes my HS much more efficient!

              Comment

              Working...
              X