Announcement

Collapse
No announcement yet.

tenScripting Now Available for HS3

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

    Will tenScripting work (or be updated) for HS4?

    Comment


      Ideally, tenScripting for HS3 should work just fine with HS4...
      HSPro 3.0.0.458, Z-NET with Z-wave plugin 3.0.1.190, RFXCOM + 2x RFXtrx433E, HSTouch, Squeezebox plugin, iTach IP/WF2IR & GC-100-6 with UltraGCIR, BLDenon, NetcamStudio, Jon00s Webpage builder, Harmony Hub plugin, SCSIP (with FreePBX), Arduino plugin, IFTTT, Pushalot plugin, Device History plugin.
      Running on Windows 10 (64) virtualized
      on ESXi (Fujitsu Primergy TX150 S8).
      WinSeer (for Win10) - TextSeer - FitbitSeer - HSPI_MoskusSample

      Are you Norwegian (or Scandinavian) and getting started with HomeSeer? Read the "HomeSeer School"!

      Comment


        Originally posted by randman View Post
        Will tenScripting work (or be updated) for HS4?
        Once I have access to HS4, I will make sure it is compatible.
        tenholde

        Comment


          Originally posted by tenholde View Post

          Once I have access to HS4, I will make sure it is compatible.
          Awesome!!!

          Comment


            How can we reuse a common function or class?
            So far, all the vb scripts that I've created with tenScripting are "standalone" scripts that don't rely on classes or functions defined in other scripts. I recently wrote a function that I'd like to make available to most of my other vb scripts. What's the best way to reuse a function or class in HomeSeer and for developing with tenScripting?

            I've read others use #include, which I've tested successfully with a simple script in HomeSeer (although for some reason using the #include method doesn't work with my HomeSeer Shutdown script when it does a #include). Also, not sure if #include is the most efficient way (performance/compilation wise) of reusing code.

            There's also the HomeSeer RunScriptFunc function, I suppose.

            Any suggestions for best way to reuse classes/functions in terms of developing in tenScripting and running in HomeSeer?

            Comment


              See post #4 in this thread.
              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


                There is a simple and effective way to reuse code functionality using HS scripts, and is directly supported by tenScripting. I do this quite extensively.

                You can define a single script with more than one entry point, and invoke the script/entry point from an event. You can also define many private functions and subroutines that one or more of these entry points (methods) can reference.

                tenScripting is distributed with an example of doing this. See: File=ComplexSamples.vb Script=TwoMethods

                Let me know if I can help with this.
                tenholde

                Comment


                  Yeah, I tried the #include approach, and it works fine for me except when done from the Startup and Shutdown scripts. However, I did get the hs.RunScriptFunc() function to do what I need (as I discussed in further detail at the bottom of the thread mentioned by Uncle Michael.

                  Comment


                    I have installed Tenscripting, and the other two helper apps and all seems to work great until I try to use MySql.Data.MySqlClient. I have added it to the references, and the items like MySqlConnection show up as green, but when I try to compile the tenScripting program, it says it si not defined. I am at a loss as to why.
                    Code:
                    Imports MySql.Data.MySqlClient
                    
                    Public Class LogThermostatValues
                    
                        Public Sub Main(ByVal Parms As Object)
                    
                            Dim ParmArray(10) As String
                            '' Extract script parameters into ParmArray()
                            ParmArray(0) = ""
                            If Parms.ToString.Contains("|") Then
                                ParmArray = Parms.ToString.Split(Convert.ToChar("|"))
                            Else
                                ParmArray(0) = Parms.ToString
                            End If
                    
                            '' Logs Thermostat Values.  This will log all Thermostat values
                            '' and can be called when any thermostat values changes.  But it logs all values
                            '' regardless of which one changes.
                    
                            '' Get values
                    
                            Dim Status = hs.DeviceVSP_GetStatus(hs.GetDeviceRefByName("Thermostat Thermostat Status"), hs.DeviceValue(hs.GetDeviceRefByName("Thermostat Thermostat Status")), ePairStatusControl.Status)
                            Dim SystemMode = hs.DeviceVSP_GetStatus(hs.GetDeviceRefByName("Thermostat Thermostat System Mode"), hs.DeviceValue(hs.GetDeviceRefByName("Thermostat Thermostat System Mode")), ePairStatusControl.Status)
                            Dim SetPointStatus = hs.DeviceVSP_GetStatus(hs.GetDeviceRefByName("Thermostat Thermostat Setpoint"), hs.DeviceValue(hs.GetDeviceRefByName("Thermostat Thermostat Setpoint")), ePairStatusControl.Status)
                            Dim Setpoint = hs.DeviceValueEx(hs.GetDeviceRefByName("Thermostat Thermostat Setpoint"))
                            Dim SysModeStatus = hs.DeviceVSP_GetStatus(hs.GetDeviceRefByName("Thermostat Thermostat System Mode"), hs.DeviceValue(hs.GetDeviceRefByName("Thermostat Thermostat System Mode")), ePairStatusControl.Status)
                            Dim OpStatus = hs.DeviceVSP_GetStatus(hs.GetDeviceRefByName("Thermostat Thermostat Operating Status"), hs.DeviceValue(hs.GetDeviceRefByName("Thermostat Thermostat Operating Status")), ePairStatusControl.Status)
                            Dim OpMode = hs.DeviceVSP_GetStatus(hs.GetDeviceRefByName("Thermostat Thermostat Operating Mode"), hs.DeviceValue(hs.GetDeviceRefByName("Thermostat Thermostat Operating Mode")), ePairStatusControl.Status)
                            Dim FanMode = hs.DeviceVSP_GetStatus(hs.GetDeviceRefByName("Thermostat Thermostat Fan Mode"), hs.DeviceValue(hs.GetDeviceRefByName("Thermostat Thermostat Fan Mode")), ePairStatusControl.Status)
                            Dim FanStatus = hs.DeviceVSP_GetStatus(hs.GetDeviceRefByName("Thermostat Thermostat Fan Status"), hs.DeviceValue(hs.GetDeviceRefByName("Thermostat Thermostat Fan Status")), ePairStatusControl.Status)
                            Dim HoldType = hs.DeviceVSP_GetStatus(hs.GetDeviceRefByName("Thermostat Thermostat Hold Type"), hs.DeviceValue(hs.GetDeviceRefByName("Thermostat Thermostat Hold Type")), ePairStatusControl.Status)
                            Dim IndoorTemp = hs.DeviceValueEx(hs.GetDeviceRefByName("Thermostat Thermostat Indoor Temp"))
                            Dim IndoorHumity = hs.DeviceValueEx(hs.GetDeviceRefByName("Thermostat Thermostat Indoor Humidity"))
                    
                            Dim Debug = 0 ' set to zero for additional logging
                            Dim conn As MySqlConnection
                            Dim myCommand As New MySqlCommand
                            conn = New MySqlConnection()
                            conn.ConnectionString = "Server=localhost; user id=Me; password=********; database=homeseerdb;"
                            myCommand.CommandText = "INSERT into thermostat (HomeStatus, StatusStatus, SetpointStatus, SetPointValue, SystemModeStatus, OperatingStatusStatus, OperatingModeStatus,FanModeStatus,FanStatusStatus,IndoorTempStatus,IndoorHumidityStatus,HoldTypeStatus) 
                                                    VALUES (@HomeStatus,@StatusStatus,@SetpointStatus,@SetPointValue,@SystemModeStatus,@OperatingStatusStatus,@OperatingModeStatus,@FanModeStatus,@FanStatusStatus,@IndoorTempStatus,@IndoorHumidityStatus,@HoldTypeStatus)"
                            myCommand.Parameters.AddWithValue("@HomeStatus", Status)
                            myCommand.Parameters.AddWithValue("@StatusStatus", SystemMode)
                            myCommand.Parameters.AddWithValue("@SetpointStatus", SetPointStatus)
                            myCommand.Parameters.AddWithValue("@SetPointValue", Setpoint)
                            myCommand.Parameters.AddWithValue("@SystemModeStatus", SysModeStatus)
                            myCommand.Parameters.AddWithValue("@OperatingStatusStatus", OpStatus)
                            myCommand.Parameters.AddWithValue("@OperatingModeStatus", OpMode)
                            myCommand.Parameters.AddWithValue("@FanModeStatus", FanMode)
                            myCommand.Parameters.AddWithValue("@FanStatusStatus", FanStatus)
                            myCommand.Parameters.AddWithValue("@IndoorTempStatus", IndoorTemp)
                            myCommand.Parameters.AddWithValue("@IndoorHumidityStatus", IndoorHumity)
                            myCommand.Parameters.AddWithValue("@HoldTypeStatus", HoldType)
                    
                    
                    
                            myCommand.Connection = conn
                            Try
                                conn.Open()
                                If Debug = 0 Then
                                    hs.WriteLog("MySQL", "Connection Opened Successfully!")
                                End If
                                Dim result = myCommand.ExecuteNonQuery()
                    
                                If Debug = 0 Then
                                    hs.WriteLog("MySQL", "Logged in to database: OK ")
                                End If
                                If Debug = 0 Then
                                    hs.WriteLog("MySQL", "executed statement:" + myCommand.CommandText)
                                End If
                                conn.Close()
                    
                            Catch myerror As MySql.Data.MySqlClient.MySqlException
                                hs.WriteLog("mySQL", "Error Connecting to Database: " & myerror.Message)
                            End Try
                    
                        End Sub
                    End Class
                    Here is the error:
                    Severity Code Description Project File Line Suppression State
                    Error BC30002 Type 'MySql.Data.MySqlClient.MySqlException' is not defined. tenScripting3 C:\Program Files (x86,26)\HomeSeer HS3\Tenware\tenScripting_3_31\tenScripting3\tenScripting3\SD DScripts.vb 1 Active
                    Error BC30002 Type 'MySql.Data.MySqlClient.MySqlConnection' is not defined. tenScripting3 C:\Program Files (x86,21)\HomeSeer HS3\Tenware\tenScripting_3_31\tenScripting3\tenScripting3\SD DScripts.vb 1 Active
                    Error BC30002 Type 'MySql.Data.MySqlClient.MySqlCommand' is not defined. tenScripting3 C:\Program Files (x86,30)\HomeSeer HS3\Tenware\tenScripting_3_31\tenScripting3\tenScripting3\SD DScripts.vb 1 Active
                    Under references, I added the reference to the "MySql.Data" dll that is in the Homeseer HS3 directory.

                    I am really not sure why this does not compile.


                    Thanks for any help.
                    A computer's attention span is as long
                    as it's powercord.

                    Comment


                      I copied your script you posted into my tenScripting project. I could not find MySql.Data.dll in my HS3 installation, but curiously, I did have a MySql.Data.dll.temp in my HS3 directory. I'm assuming must be from old installation or something. I copied it to a temporary folder on my development computer that I run tenScripting, renamed it to MySql.Data.dll and added a reference to my project and your script compiled with no problems. I did not try actually running it as I don't know what it might do.

                      tenholde

                      Comment


                        Are you running tenScripting on the same computer as HS3? Is there anything running on HS3 that uses MySql? If you place your script into the HS3 script folder (export it from tenScripting) does it run/compile okay if you run it from an HS3 Event?
                        tenholde

                        Comment


                          Originally posted by tenholde View Post
                          There is a simple and effective way to reuse code functionality using HS scripts, and is directly supported by tenScripting. I do this quite extensively.

                          You can define a single script with more than one entry point, and invoke the script/entry point from an event. You can also define many private functions and subroutines that one or more of these entry points (methods) can reference.

                          tenScripting is distributed with an example of doing this. See: File=ComplexSamples.vb Script=TwoMethods

                          Let me know if I can help with this.
                          Hi Ed; I'm trying to implement your suggestion. I can find the file ComplexSamples.vb but lost looking for Script=TwoMethods. Could you elaborate a bit on how this is consctructed?

                          Thanks; Don
                          Don

                          Comment


                            Originally posted by donstephens View Post

                            Hi Ed; I'm trying to implement your suggestion. I can find the file ComplexSamples.vb but lost looking for Script=TwoMethods. Could you elaborate a bit on how this is consctructed?

                            Thanks; Don
                            The file ComplexSamples.vb contains 4 script definitions. Each of these scripts are defined by wrapping them in CLASS and END CLASS statements. The last of the four scripts is TwoMethods. The definition of this script starts with PUBLIC CLASS TwoMethods. When you export the script TwoMethods to the HS script folder, it will be contained in a file TwoMethods.vb.

                            TwoMethods does not have the typical SUB Main method defined. Instead it has two methods or entrypoints defined: ToggleFrontPorch and ToggleBackPorch. You can reference each of these methods from separate Events by specifying in the event that you want to run the script TwoMethods.vb and instead of the typical Main Function, you want to run ToggleFrontPorch (or, ToggleBackPorch).

                            Click image for larger version  Name:	TwoMethods.png Views:	0 Size:	346.0 KB ID:	1385982

                            Each of these methods are very simple. They just call the private function ToggleDevice that is also defined in the TwoMethods script. You could, instead, define two separate scripts called ToggleFrontPorch.vb and ToggleBackPorch.vb, each with an entry point of Main, that both duplicate all of the code in ToggleDevice. This is a really simple example of code reuse.
                            tenholde

                            Comment


                              I get it. I'll play with it a bit.

                              Don

                              Comment


                                Originally posted by tenholde View Post
                                Are you running tenScripting on the same computer as HS3? Is there anything running on HS3 that uses MySql? If you place your script into the HS3 script folder (export it from tenScripting) does it run/compile okay if you run it from an HS3 Event?
                                Thanks for the help. So first, basically what I have done is installed MySql 8 (it's free) on my HS computer. This is what I am going to be logging data for history and graphs and such. I have a working copy of a test that writes some data to the MySql db. It works great so I included it in TenScripting VS Project. Since it worked in the HS environment, I basically just copied the text into a script using the Homeseer event editor. And It works correctly under Homeseer, but I can't debug it in TenSCripting, which is what I was hoping to be able to do. I am not sure why. It just won't compile. I can use the same code in VS and make it work, but not when integrated with HomeSeer. However it does help me build the event, I just can't get it to run under Visual Studio. I am not sure why. Maybe there is some problem when it integrates with Homeseer. Maybe there is a setting in Homeseer that is not right, I just don't know. Anyway, since it is running, I will work on it and let you know if I figure it out.

                                I have a Honeywell internet-based thermostat (Wifi 9000 color screen thermostat) and am using skhill's plugin to talk to the thermostat. Anytime this event runs it will get ALL the thermostat settings and log them to the MySql database. I then set up events using the built-in "if-then" statements to check and if one of the settings (devices) changes state, I call this event and it goes and logs all the device values for the thermostat. Later I can create charts and things. So that is what the event does. In another event, I also check for a low temperature less than 66 and if the Mode is not HEAT, then I change it to HEAT. If it gets to a high temperature of 80 and it is not COOL, I change it to COOL. That way I am not consisting changing the Mode setting. I will be integrating it with the M1 Elk Alarm to not change the mode (Heat/Cool) if any of the doors are currently open (Just make announcements). But since I just moved, I need to run some wires in the attic and set up speakers throughout the house, etc.

                                Thanks for making the TenScriptingAid and the TenHsEvents, it really does help.
                                A computer's attention span is as long
                                as it's powercord.

                                Comment

                                Working...
                                X