Announcement

Collapse
No announcement yet.

Virtual Device String Formatting

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

    Virtual Device String Formatting

    Does anyone know how I can make a replacement value which provides a timer value that is separated with colons (example 1) into a more readable format preceded with Days, Hours, Minutes (example 2)? I've provided an event example (example 3) any help would be greatly appreciated. Mike
    Attached Files
    Computer: CUK Intel NUC7i7BNH
    Op System: Windows10 Pro - Work Station
    HS Version: HS4 Pro Edition 4.2.19.0

    Plug-Ins: AK Weather 4.0.5.25,APCUPSD 3.3.2.3,BLBackup 2.0.63.0,BLEditor 2.0.11.0,BLGData 3.0.55.0,BLOccupied 2.0.28.0,BLShutdown 1.0.6.0,Blue-Iris 3.1.3.33206,Device History 3.2.0.2,EasyTrigger 3.0.0.76,Harmony Hub 4.0.14.0,iRobot 5.22.41.1,JowiHue 4.0.8.7,Nest 3.0.0.34,NetCam Plugin 1.0.0.5,PHLocation2 3.0.0.64,Pushover 4.0.10.0,Random 3.0.0.2,Restart 1.0.0.7,Ring 1.0.0.9,SDJ-Health 3.1.1.3,Sonos 3.1.0.59,Sonos4 4.0.1.12,UltraCID3 3.0.6681.34300,UltraMon3 3.0.6554.33094,UltraNetCam3 3.0.6413.20219,Unifi 4.0.32.0,Zigbee 4.0.11.0,Z-Wave 4.0.3.0, and Jon00 scripts.

    #2
    I'm not aware of any replacement variable that will do that. It's deceptively difficult. This script may do what you want. Replace 1092 with the Ref ID of your timer device and 1388 with the Ref ID of your target device.
    Code:
        Public Sub Main(ByVal Parms As Object)
    
    
            Dim strTimer As String = hs.DeviceString(1092)
            Dim strFriendly As String = ""
            Dim strD As String = ""
            Dim strH As String = ""
            Dim strM As String = ""
            Dim strS As String = ""
            Dim I As Integer
            Dim strValues As String()
            Dim strSeparators() As String = {":"}
    
        strValues = strTimer.Split(strSeparators, StringSplitOptions.None)
        I = strValues.GetUpperBound(0)
    
        If I > 2 Then strD = strValues(I-3) & " days "
        If I > 1 Then strH = strValues(I-2) & " hrs " 
        If I > 0 Then strM = strValues(I-1) & " mins " 
        strS = strValues(I) & " secs"
    
        strFriendly = strD & strH & strM & strS
    
        hs.SetDeviceString(1388, strFriendly, True)
    
    
        End Sub
    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


      #3
      Originally posted by Uncle Michael View Post
      I'm not aware of any replacement variable that will do that. It's deceptively difficult. This script may do what you want. Replace 1092 with the Ref ID of your timer device and 1388 with the Ref ID of your target device.
      Code:
          Public Sub Main(ByVal Parms As Object)
      
      
              Dim strTimer As String = hs.DeviceString(1092)
              Dim strFriendly As String = ""
              Dim strD As String = ""
              Dim strH As String = ""
              Dim strM As String = ""
              Dim strS As String = ""
              Dim I As Integer
              Dim strValues As String()
              Dim strSeparators() As String = {":"}
      
          strValues = strTimer.Split(strSeparators, StringSplitOptions.None)
          I = strValues.GetUpperBound(0)
      
          If I > 2 Then strD = strValues(I-3) & " days "
          If I > 1 Then strH = strValues(I-2) & " hrs " 
          If I > 0 Then strM = strValues(I-1) & " mins " 
          strS = strValues(I) & " secs"
      
          strFriendly = strD & strH & strM & strS
      
          hs.SetDeviceString(1388, strFriendly, True)
      
      
          End Sub
      @Michael, thanxs for the comeback. I was thinking the same that I would end up with a script which is OK, but one would think it didn't have to be so "deceptively difficult". Thank-you for the code snip-it. Mike
      Computer: CUK Intel NUC7i7BNH
      Op System: Windows10 Pro - Work Station
      HS Version: HS4 Pro Edition 4.2.19.0

      Plug-Ins: AK Weather 4.0.5.25,APCUPSD 3.3.2.3,BLBackup 2.0.63.0,BLEditor 2.0.11.0,BLGData 3.0.55.0,BLOccupied 2.0.28.0,BLShutdown 1.0.6.0,Blue-Iris 3.1.3.33206,Device History 3.2.0.2,EasyTrigger 3.0.0.76,Harmony Hub 4.0.14.0,iRobot 5.22.41.1,JowiHue 4.0.8.7,Nest 3.0.0.34,NetCam Plugin 1.0.0.5,PHLocation2 3.0.0.64,Pushover 4.0.10.0,Random 3.0.0.2,Restart 1.0.0.7,Ring 1.0.0.9,SDJ-Health 3.1.1.3,Sonos 3.1.0.59,Sonos4 4.0.1.12,UltraCID3 3.0.6681.34300,UltraMon3 3.0.6554.33094,UltraNetCam3 3.0.6413.20219,Unifi 4.0.32.0,Zigbee 4.0.11.0,Z-Wave 4.0.3.0, and Jon00 scripts.

      Comment


        #4
        @Michael, the script snip-it worked great and now does what I wanted Thanxs for the support. Mike
        Computer: CUK Intel NUC7i7BNH
        Op System: Windows10 Pro - Work Station
        HS Version: HS4 Pro Edition 4.2.19.0

        Plug-Ins: AK Weather 4.0.5.25,APCUPSD 3.3.2.3,BLBackup 2.0.63.0,BLEditor 2.0.11.0,BLGData 3.0.55.0,BLOccupied 2.0.28.0,BLShutdown 1.0.6.0,Blue-Iris 3.1.3.33206,Device History 3.2.0.2,EasyTrigger 3.0.0.76,Harmony Hub 4.0.14.0,iRobot 5.22.41.1,JowiHue 4.0.8.7,Nest 3.0.0.34,NetCam Plugin 1.0.0.5,PHLocation2 3.0.0.64,Pushover 4.0.10.0,Random 3.0.0.2,Restart 1.0.0.7,Ring 1.0.0.9,SDJ-Health 3.1.1.3,Sonos 3.1.0.59,Sonos4 4.0.1.12,UltraCID3 3.0.6681.34300,UltraMon3 3.0.6554.33094,UltraNetCam3 3.0.6413.20219,Unifi 4.0.32.0,Zigbee 4.0.11.0,Z-Wave 4.0.3.0, and Jon00 scripts.

        Comment


          #5
          @Michael, I thought I would be clever and make the script snip-it as a universal script where I could enter both the timer and virtual device IDs within the Event parameter field but I seem to not fully grasp scripting, per chance could review and advise what I'm doing wrong? Mike

          Sub Main(ByVal Parms As Object)
          Dim ParmArray() as String
          ParmArray = Parms.tostring.split(",")
          Dim tTimer = ParmArray(0)
          Dim tDevice = ParmArray(1))

          Dim strTimer As String = hs.DeviceString(tTimer) 'Ref ID of Timer
          Dim strFriendly As String = ""
          Dim strD As String = ""
          Dim strH As String = ""
          Dim strM As String = ""
          Dim strS As String = ""
          Dim I As Integer
          Dim strValues As String()
          Dim strSeparators() As String = {":"}

          strValues = strTimer.Split(strSeparators, StringSplitOptions.None)
          I = strValues.GetUpperBound(0)

          If I > 2 Then strD = strValues(I-3) & " days "
          If I > 1 Then strH = strValues(I-2) & " hrs "
          If I > 0 Then strM = strValues(I-1) & " mins "
          strS = strValues(I) & " secs"

          strFriendly = strD & strH & strM

          hs.SetDeviceString(tDevice, strFriendly, True) 'Ref ID of Target Virtual Device


          End Sub
          Last edited by MNB; March 18, 2018, 01:10 PM.
          Computer: CUK Intel NUC7i7BNH
          Op System: Windows10 Pro - Work Station
          HS Version: HS4 Pro Edition 4.2.19.0

          Plug-Ins: AK Weather 4.0.5.25,APCUPSD 3.3.2.3,BLBackup 2.0.63.0,BLEditor 2.0.11.0,BLGData 3.0.55.0,BLOccupied 2.0.28.0,BLShutdown 1.0.6.0,Blue-Iris 3.1.3.33206,Device History 3.2.0.2,EasyTrigger 3.0.0.76,Harmony Hub 4.0.14.0,iRobot 5.22.41.1,JowiHue 4.0.8.7,Nest 3.0.0.34,NetCam Plugin 1.0.0.5,PHLocation2 3.0.0.64,Pushover 4.0.10.0,Random 3.0.0.2,Restart 1.0.0.7,Ring 1.0.0.9,SDJ-Health 3.1.1.3,Sonos 3.1.0.59,Sonos4 4.0.1.12,UltraCID3 3.0.6681.34300,UltraMon3 3.0.6554.33094,UltraNetCam3 3.0.6413.20219,Unifi 4.0.32.0,Zigbee 4.0.11.0,Z-Wave 4.0.3.0, and Jon00 scripts.

          Comment


            #6
            OK this is getting dangerous - and inelegant.
            Here's an attempt, but I have not tested it very thoroughly. It uses the same separator for both the reference ID input and the timer contents, so it assumes you separate the two Device IDs with a colon [:].

            I'm sure there are better and more compact ways to do this, but I'm only a hack at writing scripts.

            Code:
            Sub Main(ByVal Params As String)
            
                Dim strTimer As String
                Dim strFriendly As String
                Dim strD As String = ""
                Dim strH As String = ""
                Dim strM As String = ""
                Dim strS As String = ""
            
                Dim tTimer As Integer
                Dim tDevice As Integer
                Dim I As Integer
            
                Dim strSeparators() As String = {":"}
                Dim strValues As String()
                Dim strIDs As String()
            
                strIds = Params.Split(strSeparators, StringSplitOptions.None)
            
                tTimer = CInt(strIDs(0))
                tDevice = CInt(strIDs(1))
            
                strTimer = hs.DeviceString(tTimer)
            
                strValues = strTimer.Split(strSeparators, StringSplitOptions.None)
                I = strValues.GetUpperBound(0)
            
                If I > 2 Then strD = strValues(I-3) & " days "
                If I > 1 Then strH = strValues(I-2) & " hrs " 
                If I > 0 Then strM = strValues(I-1) & " mins " 
                strS = strValues(I) & " secs"
            
                strFriendly = strD & strH & strM & strS
            
                hs.SetDeviceString(tDevice, strFriendly, True)
            
             End Sub
            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


              #7
              Originally posted by Uncle Michael View Post
              OK this is getting dangerous - and inelegant.
              Here's an attempt, but I have not tested it very thoroughly. It uses the same separator for both the reference ID input and the timer contents, so it assumes you separate the two Device IDs with a colon [:].

              I'm sure there are better and more compact ways to do this, but I'm only a hack at writing scripts.

              Code:
              Sub Main(ByVal Params As String)
              
                  Dim strTimer As String
                  Dim strFriendly As String
                  Dim strD As String = ""
                  Dim strH As String = ""
                  Dim strM As String = ""
                  Dim strS As String = ""
              
                  Dim tTimer As Integer
                  Dim tDevice As Integer
                  Dim I As Integer
              
                  Dim strSeparators() As String = {":"}
                  Dim strValues As String()
                  Dim strIDs As String()
              
                  strIds = Params.Split(strSeparators, StringSplitOptions.None)
              
                  tTimer = CInt(strIDs(0))
                  tDevice = CInt(strIDs(1))
              
                  strTimer = hs.DeviceString(tTimer)
              
                  strValues = strTimer.Split(strSeparators, StringSplitOptions.None)
                  I = strValues.GetUpperBound(0)
              
                  If I > 2 Then strD = strValues(I-3) & " days "
                  If I > 1 Then strH = strValues(I-2) & " hrs " 
                  If I > 0 Then strM = strValues(I-1) & " mins " 
                  strS = strValues(I) & " secs"
              
                  strFriendly = strD & strH & strM & strS
              
                  hs.SetDeviceString(tDevice, strFriendly, True)
              
               End Sub
              @Michael, many thank-you for the update, I will try it later this evening and confirm. Out of curiosity why did you use ":" vs "," as the parameter separator? Mike
              Computer: CUK Intel NUC7i7BNH
              Op System: Windows10 Pro - Work Station
              HS Version: HS4 Pro Edition 4.2.19.0

              Plug-Ins: AK Weather 4.0.5.25,APCUPSD 3.3.2.3,BLBackup 2.0.63.0,BLEditor 2.0.11.0,BLGData 3.0.55.0,BLOccupied 2.0.28.0,BLShutdown 1.0.6.0,Blue-Iris 3.1.3.33206,Device History 3.2.0.2,EasyTrigger 3.0.0.76,Harmony Hub 4.0.14.0,iRobot 5.22.41.1,JowiHue 4.0.8.7,Nest 3.0.0.34,NetCam Plugin 1.0.0.5,PHLocation2 3.0.0.64,Pushover 4.0.10.0,Random 3.0.0.2,Restart 1.0.0.7,Ring 1.0.0.9,SDJ-Health 3.1.1.3,Sonos 3.1.0.59,Sonos4 4.0.1.12,UltraCID3 3.0.6681.34300,UltraMon3 3.0.6554.33094,UltraNetCam3 3.0.6413.20219,Unifi 4.0.32.0,Zigbee 4.0.11.0,Z-Wave 4.0.3.0, and Jon00 scripts.

              Comment


                #8
                Originally posted by MNB View Post
                Out of curiosity why did you use ":" vs "," as the parameter separator? Mike
                Laziness. It was already set up as the separator in the device string. You can try to use the pattern to define a comma as "a learning exercise".
                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


                  #9
                  Originally posted by MNB View Post
                  @Michael, many thank-you for the update, I will try it later this evening and confirm. Out of curiosity why did you use ":" vs "," as the parameter separator? Mike
                  @Michael, tried the updated script, something is amidst, I'm not getting the formatted timer value but instead the state text, will have to investigate and resolve. Thanxs though it gotten me further. Mike
                  Computer: CUK Intel NUC7i7BNH
                  Op System: Windows10 Pro - Work Station
                  HS Version: HS4 Pro Edition 4.2.19.0

                  Plug-Ins: AK Weather 4.0.5.25,APCUPSD 3.3.2.3,BLBackup 2.0.63.0,BLEditor 2.0.11.0,BLGData 3.0.55.0,BLOccupied 2.0.28.0,BLShutdown 1.0.6.0,Blue-Iris 3.1.3.33206,Device History 3.2.0.2,EasyTrigger 3.0.0.76,Harmony Hub 4.0.14.0,iRobot 5.22.41.1,JowiHue 4.0.8.7,Nest 3.0.0.34,NetCam Plugin 1.0.0.5,PHLocation2 3.0.0.64,Pushover 4.0.10.0,Random 3.0.0.2,Restart 1.0.0.7,Ring 1.0.0.9,SDJ-Health 3.1.1.3,Sonos 3.1.0.59,Sonos4 4.0.1.12,UltraCID3 3.0.6681.34300,UltraMon3 3.0.6554.33094,UltraNetCam3 3.0.6413.20219,Unifi 4.0.32.0,Zigbee 4.0.11.0,Z-Wave 4.0.3.0, and Jon00 scripts.

                  Comment


                    #10
                    Originally posted by MNB View Post
                    I'm not getting the formatted timer value but instead the state text,
                    What do you mean by "state text"?

                    How are you entering the Ref IDs in the event? Does it look like this?
                    Attached Files
                    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


                      #11
                      Originally posted by Uncle Michael View Post
                      What do you mean by "state text"?

                      How are you entering the Ref IDs in the event? Does it look like this?
                      @Michael, what ever the ON/OFF switch state and yes I entered the timer ID followed by Virtual Device ID, also had "Main" in the first field. Mike
                      Computer: CUK Intel NUC7i7BNH
                      Op System: Windows10 Pro - Work Station
                      HS Version: HS4 Pro Edition 4.2.19.0

                      Plug-Ins: AK Weather 4.0.5.25,APCUPSD 3.3.2.3,BLBackup 2.0.63.0,BLEditor 2.0.11.0,BLGData 3.0.55.0,BLOccupied 2.0.28.0,BLShutdown 1.0.6.0,Blue-Iris 3.1.3.33206,Device History 3.2.0.2,EasyTrigger 3.0.0.76,Harmony Hub 4.0.14.0,iRobot 5.22.41.1,JowiHue 4.0.8.7,Nest 3.0.0.34,NetCam Plugin 1.0.0.5,PHLocation2 3.0.0.64,Pushover 4.0.10.0,Random 3.0.0.2,Restart 1.0.0.7,Ring 1.0.0.9,SDJ-Health 3.1.1.3,Sonos 3.1.0.59,Sonos4 4.0.1.12,UltraCID3 3.0.6681.34300,UltraMon3 3.0.6554.33094,UltraNetCam3 3.0.6413.20219,Unifi 4.0.32.0,Zigbee 4.0.11.0,Z-Wave 4.0.3.0, and Jon00 scripts.

                      Comment


                        #12
                        Is there anything in the String area of the virtual device? Are you sure the Ref ID you entered is correct? Are there any errors in the log when you try to run the script?
                        Attached Files
                        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


                          #13
                          @Michael, thanxs for the comeback.. I was able to look at what had I pasted from your post into the .vb file and found some space characters within the text (something I did), after removing them I was able to get my Virtual Devices to properly display the correct formatted time values.

                          I normally use a LUA editor (Zerobrane) when developing/modifying scripts as it does basic code format & content checks to avoid any issues which I did not initially, hence the space characters. Needless to say, problem fixed and am now running as anticipated, and traded three separate scripts for a single script. Many thanxs Mike
                          Last edited by MNB; March 19, 2018, 10:01 AM.
                          Computer: CUK Intel NUC7i7BNH
                          Op System: Windows10 Pro - Work Station
                          HS Version: HS4 Pro Edition 4.2.19.0

                          Plug-Ins: AK Weather 4.0.5.25,APCUPSD 3.3.2.3,BLBackup 2.0.63.0,BLEditor 2.0.11.0,BLGData 3.0.55.0,BLOccupied 2.0.28.0,BLShutdown 1.0.6.0,Blue-Iris 3.1.3.33206,Device History 3.2.0.2,EasyTrigger 3.0.0.76,Harmony Hub 4.0.14.0,iRobot 5.22.41.1,JowiHue 4.0.8.7,Nest 3.0.0.34,NetCam Plugin 1.0.0.5,PHLocation2 3.0.0.64,Pushover 4.0.10.0,Random 3.0.0.2,Restart 1.0.0.7,Ring 1.0.0.9,SDJ-Health 3.1.1.3,Sonos 3.1.0.59,Sonos4 4.0.1.12,UltraCID3 3.0.6681.34300,UltraMon3 3.0.6554.33094,UltraNetCam3 3.0.6413.20219,Unifi 4.0.32.0,Zigbee 4.0.11.0,Z-Wave 4.0.3.0, and Jon00 scripts.

                          Comment

                          Working...
                          X