Announcement

Collapse
No announcement yet.

Help Converting HS2 to HS3 script

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

    Help Converting HS2 to HS3 script

    I downloaded the following script from this forum some time back and was using it to track power failures on my laptop during the HS2 days.

    Recently the laptop shutdown due to a power failure in the middle of a storm and damaged the HS3 database. Thankfully I was able to recover by having a backup.

    While trying to avoid a further occurrence I went back to my old HS2 system and tried to resurrect the old script, however it through up more errors than I have the expertise to deal with under HS3 and Win7.


    ----------------------------------------------------------
    Public Sub Main(ByVal parm As Object)
    Dim strPower As String
    Dim power As Type = GetType(System.Windows.Forms.PowerStatus)
    Dim pi As System.Reflection.PropertyInfo() = power.GetProperties()
    Dim objPropval As Object = pi(0).GetValue(System.Windows.Forms.SystemInformation.PowerS tatus, Nothing)
    strPower = objPropval.ToString
    hs.SetDeviceString("1989", strPower)
    If strPower = "Online" Then
    hs.SetDeviceValue("1989", 100)
    Else
    hs.SetDeviceValue("1989", 0)
    End If
    objPropval = Nothing
    pi = Nothing
    power = Nothing
    End Sub
    ----------------------------------------------------------

    The only thing changed is the device number eg "B1" to my device number 1989.

    Appreciate if anyone can help convert this script to HS3, its a little gem and I'm sure it will be useful to others.

    #2
    As a start remove the SetDeviceString line, HS3 does not use device strings in the same way that HS2 did and for this you don't need to set it. Replace the SetDeviceValue lines with

    hs.SetDeviceValueByRef(1989, 100, True) and hs.SetDeviceValueByRef(1989, 0, True) for on and off respectively.

    And see how far you get...

    Comment


      #3
      Hi thanks for the advice, I made the changes as advised but still get the following errors.

      May-26 9:34:55 AM Error Compiling script C:\Program Files\HomeSeer HS3\scripts\Laptop Power.vb: 'SystemInformation' is not a member of 'Forms'. May-26 9:34:55 AM Error Compiling script C:\Program Files\HomeSeer HS3\scripts\Laptop Power.vb: Type 'System.Windows.Forms.PowerStatus' is not defined. May-26 9:34:55 AM Error Compiling script C:\Program Files\HomeSeer HS3\scripts\Laptop Power.vb: Namespace or type specified in the Imports 'System.Core' doesn't contain any public member or cannot be found. Make sure the namespace or the type is defined and contains at least one public member. Make sure the imported element name doesn't use any aliases.

      Comment


        #4
        What do you have as ScriptingReferences in your HS2 settings.ini file? You may need to add them to the HS3 settings.ini file as well.

        Cheers
        Al
        HS 3.0.0.548: 1990 Devices 1172 Events
        Z-Wave 3.0.1.262: 126 Nodes on one Z-Net

        Comment


          #5
          Hi Al

          Thanks, that was a good point and I thought you had nailed it. But unfortunately it didn't work. I did however find the original thread where I copied the script from, there are no references to doing anything else to make it work under HS2.

          see

          board.homeseer.com/showthread.php?t=176866

          Regards

          Brian

          Comment


            #6
            Add a reference to System.Windows.Forms.dll in your ScriptingReferences line and it should work for you.

            Edit: Also if that does not work alone add a Imports System.Forms line at the top of the script also.

            Comment


              #7
              Hi Brian,

              ok, give the following a try. This works for me (with System.Windows.Forms.dll in my ScriptingReferences).

              Code:
              Sub Main(ByVal parm As Object)
              Dim strPower As String
              Dim power As Type = GetType(System.Windows.Forms.PowerStatus)
              Dim pi As System.Reflection.PropertyInfo() = power.GetProperties()
              Dim objPropval As Object = pi(0).GetValue(System.Windows.Forms.SystemInformation.PowerStatus, Nothing)
              strPower = objPropval.ToString
              hs.WriteLog("Power Status", strPower)
              objPropval = Nothing
              pi = Nothing
              power = Nothing
              End Sub
              If it doesn't work, what operating system are you on?

              Cheers
              Al
              HS 3.0.0.548: 1990 Devices 1172 Events
              Z-Wave 3.0.1.262: 126 Nodes on one Z-Net

              Comment


                #8
                Gents, thank you both for your combined assistance.

                Today I tried both configurations, as stand alone scripts with the additional inclusions in the scripting references as advised, and also some combinations of the scripts. However they are still throwing up similar errors which looks more related to the windows part of the script.

                Al, I am running Win 7 32bit.

                Comment


                  #9
                  One more idea.
                  Try changing this line:
                  Dim objPropval As Object = pi(0).GetValue(System.Windows.Forms.SystemInformation.PowerS tatus, Nothing)
                  to this:
                  Dim objPropval As Object = pi(0).GetValue(SystemInformation.PowerStatus, Nothing)
                  Mike____________________________________________________________ __________________
                  HS3 Pro Edition 3.0.0.548, NUC i3

                  HW: Stargate | NX8e | CAV6.6 | Squeezebox | PCS | WGL 800RF | RFXCOM | Vantage Pro | Green-Eye | X10: XTB-232, -IIR | Edgeport/8 | Way2Call | Ecobee3 | EtherRain | Ubiquiti

                  Comment


                    #10
                    It's odd because I can get the script to work - I did have to reference the Forms namespace though otherwise I got the same errors. Are you confident that you have that line in the correct syntax and in the correct place in your settings file?

                    Comment


                      #11
                      This is what I have under [Settings] in my settings.ini file

                      ScriptingReferences=System.Drawing;System.Drawing.dll;System .Windows.Forms.dll

                      The other entries are for a Jon00 plugin.

                      Comment


                        #12
                        Originally posted by BeePee View Post
                        This is what I have under [Settings] in my settings.ini file

                        ScriptingReferences=System.Drawing;System.Drawing.dll;System .Windows.Forms.dll

                        The other entries are for a Jon00 plugin.
                        There's something wrong with your syntax. You need System.Windows.Forms;System.Windows.Forms.dll and this entry needs to separated by commas from the other entries.

                        Cheers
                        Al
                        HS 3.0.0.548: 1990 Devices 1172 Events
                        Z-Wave 3.0.1.262: 126 Nodes on one Z-Net

                        Comment


                          #13
                          I followed suggestions into this thread to get "strPower" value extracted and written into the log. If I can get this I will try assigning the value to a virual device but this is later.

                          I tried adding the "ScriptingReferences=System.Windows.Forms;System.Windows.For ms.dll" line to the "settings.ini" file but it did not change anything (maybe syntax is incorrect) and I also played with two versions of one line of code in the middle of the script (as it was suggested above) but it did not make any difference.
                          I am on HS3, W7-64bit.

                          Here is the the script I tried to run:

                          Sub Main(ByVal parm As Object)
                          Dim strPower As String
                          Dim power As Type = GetType(System.Windows.Forms.PowerStatus)
                          Dim pi As System.Reflection.PropertyInfo() = power.GetProperties()
                          Dim objPropval As Object = pi(0).GetValue(SystemInformation.PowerStatus, Nothing)
                          strPower = objPropval.ToString
                          hs.WriteLog("Power Status", strPower)
                          objPropval = Nothing
                          pi = Nothing
                          power = Nothing
                          End Sub


                          And here is the errors I get into my log:

                          Dec-18 8:50:27 PM Error Compiling script C:\Program Files (x86)\HomeSeer HS3\scripts\test laptop power status script 01.vb: 'SystemInformation' is not declared. It may be inaccessible due to its protection level.
                          Dec-18 8:50:27 PM Error Compiling script C:\Program Files (x86)\HomeSeer HS3\scripts\test laptop power status script 01.vb: Type 'System.Windows.Forms.PowerStatus' is not defined.
                          Dec-18 8:50:27 PM Error Compiling script C:\Program Files (x86)\HomeSeer HS3\scripts\test laptop power status script 01.vb: Namespace or type specified in the Imports 'System.Core' doesn't contain any public member or cannot be found. Make sure the namespace or the type is defined and contains at least one public member. Make sure the imported element name doesn't use any aliases.


                          I think I have enough knowlege to copy a script to my HS3 but that is about it.
                          I would appreciate you help with checking the script. My goal is to initiate an email notification if my laptop looses power and switches to battery.
                          Thank you
                          Last edited by Alexey; December 18, 2017, 09:29 PM.

                          Comment

                          Working...
                          X