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:
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:
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!!
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:
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:
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!!
Comment