Announcement

Collapse
No announcement yet.

Communication between 2 HomeSeer systems

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

    Communication between 2 HomeSeer systems

    I have 2 homeSeer systems in different locations. I'm currently setting a device value in 1 system from the other system using the script below (thank you Jon00!):

    &hs.URLAction("http://<ip_address>/JSON?user=<user name>&pass=<password>&request=controldevicebyvalue&ref=<dev_ ref_ID>&value=<dev_value>", "GET", "", "")


    This works great for sending a specific value that doesn't change. But what I would like to do now is have a device value that changes (i.e. temperature) in 1 system, set the device value in the other system.

    I suspect the answer is with changing "controldevicebyvalue&ref=<dev_ref_ID>&value=<dev_value> " but I haven't been able to find the command or syntax on how to do it. If someone can point me in the right direction it would be appreciated.


    #2
    You would use:

    Code:
    http://<ip_address>/JSON?user=<user name>&pass=<password>&request=setdevicestatus&ref=<dev_ ref_ID>&value=<dev_value>
    to set a device value.

    If you want to send/set the device value then trigger an event on device value change and use:

    Code:
    &hs.URLAction("http://<ip_address>/JSON?user=<user name>&pass=<password>&request=setdevicestatus&ref=<dev_ ref_ID>&value=" & hs.DeviceValueEx(1234), "GET", "", "")
    where 1234 is the device reference of the device you want to use.
    Jon

    Comment


      #3
      Jon00;

      It works perfect! As always, Thank You very much!!

      I learn by dissecting your script code, then use it as building blocks to make other scripts.
      With your code I can set a device value in the system 1 to a constant. And now set a device in system 1 to the value of device in the system 2.

      There is one more building block I could use. What would be the syntax for system 1 to read the value of a device in system 2 and store that in a system 1 device. Sort of the same idea as the code above, but rather system 1 would poll for a change in system 2, rather than system 2 push the change to system 1.

      Rick

      Comment


        #4
        That is more tricky. You can request the parameters of a device using JSON but the response contains most metrics about that device. You therefore have to deserialize this response to get the value etc.

        Here is a script that will do that for you. It will get/set both the value and status:

        Code:
        Imports System.Web.Script.Serialization
        
            Sub Main(ByVal Parm As Object)
        
                Try
                    Dim Data As String = ""
                    Dim MyValue As String = ""
                    Dim MyStatus As String = ""
                    Dim json As New JavaScriptSerializer
                    Dim DeviceRefToRead As String = "1234"
                    Dim DeviceRefToSet As Integer = 5678
                    Dim Username As String = ""
                    Dim Password As String = ""
                    Dim IPAddress As String = "192.168.1.10"
        
                    Data = hs.URLAction("http://" & IPAddress & "/JSON?user=" & UserName & "&pass=" & Password & "&request=getstatus&ref=" & DeviceRefToRead, "GET", "", "")
        
                    Dim dataObj As Object = json.Deserialize(Of Object)(Data)
                    MyValue = dataObj("Devices")("0")("value")
                    MyStatus = dataObj("Devices")("0")("status")
        
                    If hs.DeviceExistsRef(DeviceRefToSet) Then
                        hs.SetDeviceValueByRef(DeviceRefToSet, MyValue, True)
                        hs.SetDeviceString(DeviceRefToSet, MyStatus, True)
                    End If
                Catch Ex As Exception
                    hs.writelog("SetDevice", "Error: " & Ex.ToString)
                End Try
        
        
            End Sub
        You would set the IPAddress entry to your System 2 IP Address and the DeviceRefToRead to the reference number you wish to poll on system 2.


        Note: Before this will work, you need to shut down Homeseer and open up settings.ini (Config folder) in a text editor.

        Search for:

        ScriptingReferences

        If this is NOT found, add the following directly under [Settings]

        ( Copy and paste the following: )

        ScriptingReferences= System.Web.Script.Serialization;System.Web.Extensions.dll

        If it is found, check to see if the above text is already entered as part of the line, if not this needs to be added to the end of the line:

        (Copy and paste the following including the comma: )

        ,System.Web.Script.Serialization;System.Web.Extensions.dll

        There should be no spaces in the ScriptingReferences entry.

        Save and then restart HomeSeer.
        Jon

        Comment


          #5
          WOW....definitely not as straightforward as the short scripts!

          This will take a little time for me to digest and understand.

          Again, Thank You for all your help!

          Rick

          Comment


            #6
            Jon00;

            I made the changes to the .ini file as instructed.

            Made the following changes to the script:

            Dim DeviceRefToRead As String = "303"
            Dim DeviceRefToSet As Integer = "1885"
            Dim Username As String = "xxxxxxx"
            Dim Password As String = "xxxxxxx"
            Dim IPAddress As String = "connected2.homeseer.com"

            Then tried running the script, but got this error message:

            Click image for larger version

Name:	Error.png
Views:	226
Size:	29.1 KB
ID:	1559164


            any suggestions?



            Comment


              #7
              I would try to change your file extension from .cs to .vb

              Comment


                #8
                Changed the extension to .vb New error message:

                Click image for larger version

Name:	Error 2.png
Views:	209
Size:	16.3 KB
ID:	1559175

                error seems to be in this section:

                Dim Data As String = ""
                Dim MyValue As String = ""
                Dim MyStatus As String = ""
                Dim json As New JavaScriptSerializer
                Dim DeviceRefToRead As String = "303"
                Dim DeviceRefToSet As Integer = "1885"
                Dim Username As String = "xxxxxxx"
                Dim Password As String = "xxxxxxx"
                Dim IPAddress As String = "connected2.homeseer.com"

                Am I missing something after the "JavaScriptSerializer"?

                Comment


                  #9
                  the following should still be valid in HS4
                  http://help.homeseer.com/help/HS3/static/#.scripting
                  Mark

                  HS3 Pro 4.2.19.5
                  Hardware: Insteon Serial PLM | AD2USB for Vista Alarm | HAI Omnistat2 | 1-Wire HA7E | RFXrec433 | Dahua Cameras | LiftMaster Internet Gateway | Tuya Smart Plugs
                  Plugins: Insteon (mine) | Vista Alarm (mine) | Omnistat 3 | Ultra1Wire3 | RFXCOM | HS MyQ | BLRadar | BLDenon | Tuya | Jon00 Charting | Jon00 Links
                  Platform: Windows Server 2022 Standard, i5-12600K/3.7GHz/10 core, 16GB RAM, 500GB SSD

                  Comment


                    #10
                    FYI I'm still running HS3.

                    Thanks for the pointer.....I'll dig in.

                    Comment


                      #11
                      Originally posted by Rmasci64 View Post
                      Changed the extension to .vb New error message:

                      Click image for larger version

Name:	Error 2.png
Views:	209
Size:	16.3 KB
ID:	1559175

                      error seems to be in this section:

                      Dim Data As String = ""
                      Dim MyValue As String = ""
                      Dim MyStatus As String = ""
                      Dim json As New JavaScriptSerializer
                      Dim DeviceRefToRead As String = "303"
                      Dim DeviceRefToSet As Integer = "1885"
                      Dim Username As String = "xxxxxxx"
                      Dim Password As String = "xxxxxxx"
                      Dim IPAddress As String = "connected2.homeseer.com"

                      Am I missing something after the "JavaScriptSerializer"?
                      Did you follow my instruction about the ScriptingReferences entry with HomeSeer shut down?
                      Jon

                      Comment


                        #12
                        I believe I followed the modifications to the .ini file.



                        Click image for larger version

Name:	Capture.png
Views:	189
Size:	10.3 KB
ID:	1559183

                        Comment


                          #13
                          Just check this please. Shut down HomeSeer and then restart it. Then open up settings.ini again to see if the entry is there.
                          Jon

                          Comment


                            #14
                            Also, did you place:

                            Imports System.Web.Script.Serialization

                            ..at the very top of the script?
                            Jon

                            Comment


                              #15
                              I did the Homeseer shutdown and restart, then confirmed that the setting.ini file is as above. The error remains.

                              Comment

                              Working...
                              X