Announcement

Collapse
No announcement yet.

hs.getinisetting issue

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

    hs.getinisetting issue

    SOlved!

    Hi all

    i have build many scripts that contain hs.getinisetting
    but here is a problem with reading it .


    it needs to read the array from an ini file

    in the ini file it looks like this
    PHP Code:
    [XML]
    Devices={"2212"

    this is in the very beginning ,

    Const INI_FILE As String = "PIR_TEST.ini"


    dim devices as string = hs.GetINISetting("xml","Devices","", INI_FILE)
    dim array_pir() as string = devices


    THis gives this error :
    PHP Code:
    Value of type 'String' cannot be converted to '1-dimensional array of String'

    it looks like he doesnt accept devices as an array string , how can i solve it ?


    Regards
    Last edited by Malosa; August 18, 2016, 01:42 PM. Reason: Solved
    Preferred -> Jon's Plugins, Pushover, Phlocation, Easy-trigger,
    Rfxcom, Blade Plugins, Pushbullet, homekit, Malosa Scripts




    HS3Pro 4.1.14.0 on windows 10 enterprise X64 on hp quadcore laptop 8 GB.

    #2
    i did also try this Inside the sub main :
    PHP Code:
    dim devices as string hs.GetINISetting("xml","Devices",""INI_FILE)
            
    hs.speak (devices)
            
    dim array_pir() as string = {devices
    with this ini file :
    PHP Code:
    [XML]
    Devices="2212","2212","2216" 
    i get this :

    PHP Code:
    Aug-18 13:57:13         Array    ErrorConversion from string "2212","2212","2216" to type 'Integer' is not valid.
    Aug-18 13:57:08         TTS    Speak ():2212","2212","2216 
    Looks like it can't get the " from the ini file .....
    i really out of options here , dont know what to do , i know its possible
    Preferred -> Jon's Plugins, Pushover, Phlocation, Easy-trigger,
    Rfxcom, Blade Plugins, Pushbullet, homekit, Malosa Scripts




    HS3Pro 4.1.14.0 on windows 10 enterprise X64 on hp quadcore laptop 8 GB.

    Comment


      #3
      You should be able to use:

      Devices=2212,2212,2216

      Then just convert it to an array using Split:
      Dim Devices As String = hs.GetINISetting("xml","Devices","", INI_FILE)
      Dim x As Integer

      Dim ary() As String = Devices.Split(",")
      For x = 0 To ary.Length - 1
      hs.Speak(ary(x)
      Next
      HS4Pro on a Raspberry Pi4
      54 Z-Wave Nodes / 21 Zigbee Devices / 108 Events / 767 Devices
      Plugins: Z-Wave / Zigbee Plus / EasyTrigger / AK Weather / OMNI

      HSTouch Clients: 1 Android

      Comment


        #4
        thanks ,

        i still get this error

        Aug-18 15:24:16 Array Error: Object reference not set to an instance of an object.



        normal my script needs to read the array like this when u pt it manual in there :
        dim array_pir() as string = {"2623","2622","2626"}

        but i want to use a ini instead

        the hs.speak was only for testing the output


        Originally posted by rmasonjr View Post
        You should be able to use:

        Devices=2212,2212,2216

        Then just convert it to an array using Split:
        Dim Devices As String = hs.GetINISetting("xml","Devices","", INI_FILE)
        Dim x As Integer

        Dim ary() As String = Devices.Split(",")
        For x = 0 To ary.Length - 1
        hs.Speak(ary(x)
        Next
        Preferred -> Jon's Plugins, Pushover, Phlocation, Easy-trigger,
        Rfxcom, Blade Plugins, Pushbullet, homekit, Malosa Scripts




        HS3Pro 4.1.14.0 on windows 10 enterprise X64 on hp quadcore laptop 8 GB.

        Comment


          #5
          The use of the curly braces is for hard-coding the array list in the code.
          The method I posted was for a dynamic way of passing in a list of values.

          For testing purposes, you can use:
          Devices=2212,2212,2216

          Dim Devices As String = hs.GetINISetting("xml","Devices","", INI_FILE)
          Dim x As Integer

          ''Dim ary() As String = Devices.Split(",")
          dim ary() as string = {"1234","5678"}

          For x = 0 To ary.Length - 1
          hs.Speak(ary(x)
          Next
          HS4Pro on a Raspberry Pi4
          54 Z-Wave Nodes / 21 Zigbee Devices / 108 Events / 767 Devices
          Plugins: Z-Wave / Zigbee Plus / EasyTrigger / AK Weather / OMNI

          HSTouch Clients: 1 Android

          Comment


            #6
            ok , i want to use the dynamic way but it doesnt work

            i always get an error

            i show you what kind of script im using :




            PHP Code:
            Dim array_pir() As String = {"2704""2698""2517"
                
            Dim pirdisabled_count As Integer 
                Dim pirenabled_count 
            As Integer 
                Dim pir_name 
            As String "" 
                
            Dim pstr As String "" 
                
            Dim dv As Scheduler.Classes.DeviceClass Nothing 

                Sub pir
            (ByVal Parms As Object
                    Try 
                        
            pirdisabled_count 
                        pirenabled_count 

                        pir_name 
            "" 
                        
            pstr "" 
                        
            For Each devp As String In array_pir 
                            Select 
            Case hs.DeviceValue(devp
                                Case 

                                    dv 
            hs.GetDeviceByRef(devp
                                    
            pir_name dv.Name(hs
                                    
            pirenabled_count pirenabled_count 
                                    hs
            .speak(pir_name "  standby"
                                Case 

                                    hs
            .speak("person detected in the **"
                                Case 
            11 
                                    pirdisabled_count 
            pirdisabled_count 
                                
            Case 15 
                                    hs
            .speak("P I R in the ** is Enabled"
                                Case Else 
            'Optional 
                                    hs.speak("P I R in the garden has an error please check the battery") 
                            End Select 
                        Next 
                        If pirdisabled_count > 0 Then 
                            hs.speak("found some") 

                        Else 

                            hs.speak("no count") 
                        End If 

                        hs.speak(pirdisabled_count, True, "$SONOS$TTS") 
                        hs.writelog("Array", "enabled pir'
            s" & pirenabled_count) 
                        hs.writelog("
            Array", "disabled pir's: " & pirdisabled_count) 
                    Catch ex As Exception 
                        hs.WriteLog("Array", "Error: " & ex.Message) 
                    End Try 
                End Sub 


            this line :
            Dim array_pir() As String = {"2704", "2698", "2517"}

            i want that it reads from the ini file instead of hardcoding it

            it still gives me errors
            PHP Code:
            Aug-18 15:24:16    Array    ErrorObject reference not set to an instance of an object

            Originally posted by rmasonjr View Post
            The use of the curly braces is for hard-coding the array list in the code.
            The method I posted was for a dynamic way of passing in a list of values.

            For testing purposes, you can use:
            Devices=2212,2212,2216

            Dim Devices As String = hs.GetINISetting("xml","Devices","", INI_FILE)
            Dim x As Integer

            ''Dim ary() As String = Devices.Split(",")
            dim ary() as string = {"1234","5678"}

            For x = 0 To ary.Length - 1
            hs.Speak(ary(x)
            Next
            Preferred -> Jon's Plugins, Pushover, Phlocation, Easy-trigger,
            Rfxcom, Blade Plugins, Pushbullet, homekit, Malosa Scripts




            HS3Pro 4.1.14.0 on windows 10 enterprise X64 on hp quadcore laptop 8 GB.

            Comment


              #7
              Change your script to this:

              PHP Code:
              Sub pir(ByVal Parms As Object)
                      
              Dim pirdisabled_count As Integer 0
                      Dim pirenabled_count 
              As Integer 0
                      Dim pir_name 
              As String ""
                      
              Dim pstr As String ""
                      
              Dim dv As Scheduler.Classes.DeviceClass Nothing
                      Dim array_pir
              () As String hs.GetINISetting("xml""Devices"""INI_FILE).split(",")

                      Try
                          
              pirdisabled_count 0
                          pirenabled_count 
              0
                          pir_name 
              ""
                          
              pstr ""
                          
              For Each devp As String In array_pir
                              Select 
              Case hs.DeviceValue(devp)
                                  Case 
              0
                                      dv 
              hs.GetDeviceByRef(devp)
                                      
              pir_name dv.Name(hs)
                                      
              pirenabled_count pirenabled_count 1
                                      hs
              .speak(pir_name "  standby")
                                  Case 
              1
                                      hs
              .speak("person detected in the **")
                                  Case 
              11
                                      pirdisabled_count 
              pirdisabled_count 1
                                  
              Case 15
                                      hs
              .speak("P I R in the ** is Enabled")
                                  Case Else 
              'Optional 
                                      hs.speak("P I R in the garden has an error please check the battery")
                              End Select
                          Next
                          If pirdisabled_count > 0 Then
                              hs.speak("found some")

                          Else

                              hs.speak("no count")
                          End If

                          hs.speak(pirdisabled_count, True, "$SONOS$TTS")
                          hs.writelog("Array", "enabled pir'
              s" & pirenabled_count)
                          hs.writelog("
              Array", "disabled pir's: " & pirdisabled_count)
                      Catch ex As Exception
                          hs.WriteLog("Array", "Error: " & ex.Message)
                      End Try
                  End Sub 
              In your INI file, enter the value like this:
              Devices=2212,2212,2216
              HS4Pro on a Raspberry Pi4
              54 Z-Wave Nodes / 21 Zigbee Devices / 108 Events / 767 Devices
              Plugins: Z-Wave / Zigbee Plus / EasyTrigger / AK Weather / OMNI

              HSTouch Clients: 1 Android

              Comment


                #8
                very good !

                send you a pm , that one works on this script , but this script is old , i send you the correct script in a pm

                regards


                //sended right now
                Preferred -> Jon's Plugins, Pushover, Phlocation, Easy-trigger,
                Rfxcom, Blade Plugins, Pushbullet, homekit, Malosa Scripts




                HS3Pro 4.1.14.0 on windows 10 enterprise X64 on hp quadcore laptop 8 GB.

                Comment


                  #9
                  Solved

                  thanks rmasonjr!
                  Preferred -> Jon's Plugins, Pushover, Phlocation, Easy-trigger,
                  Rfxcom, Blade Plugins, Pushbullet, homekit, Malosa Scripts




                  HS3Pro 4.1.14.0 on windows 10 enterprise X64 on hp quadcore laptop 8 GB.

                  Comment


                    #10
                    No problem - anytime!
                    HS4Pro on a Raspberry Pi4
                    54 Z-Wave Nodes / 21 Zigbee Devices / 108 Events / 767 Devices
                    Plugins: Z-Wave / Zigbee Plus / EasyTrigger / AK Weather / OMNI

                    HSTouch Clients: 1 Android

                    Comment

                    Working...
                    X