- Posts: 108
- Thank you received: 7
Cross Communication between Allonis and HS
- aa6vh
- Topic Author
- Offline
- User
-
Less
More
1 year 3 months ago - 1 year 3 months ago #4242
by aa6vh
Cross Communication between Allonis and HS was created by aa6vh
David Li (
allonis.com/forum/how-to-automate/462-al...integration?start=12
) asked me to document how I cross communicate between Homeseer (HS) and Allonis. Note that I am still on HS3 but I have the license for HS4 and will migrate soon. The following should be the same, however.
There are several ways to cross communicate, but the method I prefer is to use simple HTTP Get Requests. I also prefer to use Macros when sending commands to Allonis, and Events when sending commands to HS.
This Allonis Macro will send a command to HS to trigger an event:
Macro "hs-run-event"
GetUrl|http://192.168.0.99/JSON?request=runevent&groupname=<p1>&name=<p2>
I call that macro like: ("<p1>" and "<p2>" are parameters to the macro)
Macro|hs-run-event|ControlOutside~PorchOn
I also have an Allonis macro for turning on/off an individual light:
Macro "toggle-light"
GetUrl|http://192.168.0.99/JSON?request=controldevicebylabel&ref=<p1>&label=<p2>
Again, that macro is called by: (285 is the HS device number for the light to be turned on/off)
Macro|toggle-light|285~on
(This forum does not seem to like less than or greater than characters, so I substituted the HTML equivalent).
To send a command to Allonis from Homeseer, I use the following Visual Basic script:
Imports System.Net
Imports System.IO
Private Function TouchParseStr(ByVal parms As Object, ByVal sSep As String, Optional sDef As String = "") As String()
' Takes the input parameter, and returns an array of strings.
' If called from event, parms is a single string, so does a split on the specified delimiter.
' If called from HS Touch, just returns the string array.
' Usage: Sub Main(parms As Obect)
' Dim p() As String = TouchParseStr(parms, ",") ' p(0) now contains first, p(1) second, etc
Dim buff() As String
If parms Is Nothing Then parms = ""
If parms.GetType().ToString = "System.String" Then
If parms = "" Then parms = sDef
parms = Trim(parms.ToString())
buff = parms.Split(sSep)
Else
buff = parms
End If
Return buff
End Function
Public Sub AllonisMacro(parms As Object)
Dim p() As String = TouchParseStr(parms, ",")
Dim sMacro = p(0)
Dim request As WebRequest, response As WebResponse, ds As Stream, reader As StreamReader, sUrlResponse As String
Dim url As String = "http://192.168.0.95/"
Dim uid As String = "api/docommand?command=" + sMacro
url = url + uid
Try
request = WebRequest.Create(url)
request.Method = "GET"
response = request.GetResponse()
ds = response.GetResponseStream()
reader = New StreamReader(ds)
sUrlResponse = reader.ReadToEnd()
reader.Close()
response.Close()
Catch ex As Exception
hs.writelog(ex.ToString,"Allonis Err")
End Try
End Sub
THe "TouchParseStr" is just a handy function to parse input parameters if called either from an event (single string) or from an HS Touch tablet (string array). To send to Allonis, use the Event action "Run a script file", File "Allonis.vb", Sub or Function "AllonisMacro", and the parameter field that contains the Allonis macro name.
Hope this helps someone.
There are several ways to cross communicate, but the method I prefer is to use simple HTTP Get Requests. I also prefer to use Macros when sending commands to Allonis, and Events when sending commands to HS.
This Allonis Macro will send a command to HS to trigger an event:
Macro "hs-run-event"
GetUrl|http://192.168.0.99/JSON?request=runevent&groupname=<p1>&name=<p2>
I call that macro like: ("<p1>" and "<p2>" are parameters to the macro)
Macro|hs-run-event|ControlOutside~PorchOn
I also have an Allonis macro for turning on/off an individual light:
Macro "toggle-light"
GetUrl|http://192.168.0.99/JSON?request=controldevicebylabel&ref=<p1>&label=<p2>
Again, that macro is called by: (285 is the HS device number for the light to be turned on/off)
Macro|toggle-light|285~on
(This forum does not seem to like less than or greater than characters, so I substituted the HTML equivalent).
To send a command to Allonis from Homeseer, I use the following Visual Basic script:
Imports System.Net
Imports System.IO
Private Function TouchParseStr(ByVal parms As Object, ByVal sSep As String, Optional sDef As String = "") As String()
' Takes the input parameter, and returns an array of strings.
' If called from event, parms is a single string, so does a split on the specified delimiter.
' If called from HS Touch, just returns the string array.
' Usage: Sub Main(parms As Obect)
' Dim p() As String = TouchParseStr(parms, ",") ' p(0) now contains first, p(1) second, etc
Dim buff() As String
If parms Is Nothing Then parms = ""
If parms.GetType().ToString = "System.String" Then
If parms = "" Then parms = sDef
parms = Trim(parms.ToString())
buff = parms.Split(sSep)
Else
buff = parms
End If
Return buff
End Function
Public Sub AllonisMacro(parms As Object)
Dim p() As String = TouchParseStr(parms, ",")
Dim sMacro = p(0)
Dim request As WebRequest, response As WebResponse, ds As Stream, reader As StreamReader, sUrlResponse As String
Dim url As String = "http://192.168.0.95/"
Dim uid As String = "api/docommand?command=" + sMacro
url = url + uid
Try
request = WebRequest.Create(url)
request.Method = "GET"
response = request.GetResponse()
ds = response.GetResponseStream()
reader = New StreamReader(ds)
sUrlResponse = reader.ReadToEnd()
reader.Close()
response.Close()
Catch ex As Exception
hs.writelog(ex.ToString,"Allonis Err")
End Try
End Sub
THe "TouchParseStr" is just a handy function to parse input parameters if called either from an event (single string) or from an HS Touch tablet (string array). To send to Allonis, use the Event action "Run a script file", File "Allonis.vb", Sub or Function "AllonisMacro", and the parameter field that contains the Allonis macro name.
Hope this helps someone.
Last edit: 1 year 3 months ago by aa6vh.
Please Log in to join the conversation.
Time to create page: 0.160 seconds