Announcement

Collapse
No announcement yet.

Script to copy Status Value and Status Graphics Pairs from one device to another

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

    Script to copy Status Value and Status Graphics Pairs from one device to another

    Have you ever modified an existing device's Status Value and Status Graphics pairs and then want to do the same for other devices? It can be a lot of work, so I wrote this script to make that easier. Just create an event to run the script and then pass the reference IDs of the source and target devices to it:

    Click image for larger version  Name:	Capture.PNG Views:	1 Size:	73.2 KB ID:	1298845

    The script will find all Status Value pairs (only those that are Status or Both, not Control only) and copy them to another device. The corresponding Status Graphics pairs are also copied with some caveats (see the notes in the beginning of the script). Note that any existing Status Value and Status Graphics pairs on the target device are first removed. IF you don't want that to happen, then put an apostrophe (') in front of these two lines in the script:

    Code:
            hs.DeviceVSP_ClearAll(targetDev, True)
            hs.DeviceVGP_ClearAll(targetDev, True)
    The script has only been tested under Windows. If it does not work under linux for some reason, please let me know and provide the error messages you get in the log.

    NOTE: I wrote this script to update some virtual devices that I had created. It is not intended to be used to update devices owned by plugins. Although it may work for some plugins, it may also "break" some plugin-owned target devices. If you do want to try it for a device owned by a plugin, it is at your own risk. Ensure you have a good backup prior to attempting that.

    Code:
    'This script copies Status Value and Status Graphics Pairs from one device to another
    '
    'Version 1.1
    'by sparkman @ homeseer forum
    'https://forums.homeseer.com/forum/developer-support/scripts-plug-ins-development-and-libraries/script-plug-in-library/1298844-script-to-copy-status-value-and-status-graphics-pairs-from-one-device-to-another
    '
    'Call the script from and event with method Main and the reference ID of the source device and the reference ID of the target device separated by a comma
    'This only copies pairs that are "Status" or "Both", not "Control" and only copies graphics that match a status or an exact range
    'Therefore, if you have a Status Graphics pair for which there is no corresponding Status Value pair, it won't get copied
    'Also, if you have a Status Value range, but have split that range into a number of Status Graphics ranges, only the one where the range start matches, will get copied
    'The following VS class members are not dealt with by the script.  If you use them in the source device, then their settings will not be copied over
                'Public Shared Function AddDataReplace(ByVal Index As Integer) As String
                'Public Property StringList As String()
                'Public WriteOnly Property StringListAdd As String
                'Public Const ScaleReplace As String = "@S@"
    
    Sub Main(ByVal Parms As String)
        Dim Debug As Boolean = False
        Dim logName As String = "VSVG Copy"
        Dim ParmArray() As String
        ParmArray = Parms.ToString.Split(",")
        Dim sourceDev As Integer = CInt(ParmArray(0))        'reference ID of the source device to use for existing valuess
        Dim targetDev As Integer = CInt(ParmArray(1))        'reference ID of the target device to change
        hs.writelog(logName,"<font color='#000080'>" & CStr(hs.DeviceVSP_CountStatus(sourceDev)) & "<Font Color='#000000'> Status Value Pairs to be copied from ref id: <font color='#008000'>" & CStr(sourceDev) & "<Font Color='#000000'> to ref id: <font color='#008000'>" & CStr(targetDev) & "</font>")
    
        Try
    
            'Clear existing Status Value / Status Graphic pairs on the target Dev
            hs.DeviceVSP_ClearAll(targetDev, True)
            hs.DeviceVGP_ClearAll(targetDev, True)
    
            Dim ControlCount As Integer = hs.DeviceVSP_CountControl(sourceDev)
            Dim StatusCount As Integer = hs.DeviceVSP_CountStatus(sourceDev)
            Dim ControlOnlyCount As Integer = StatusCount - ControlCount
            If Math.Abs(ControlOnlyCount) > 0 Then hs.WriteLogEx(logName,"Not Copying " & CStr(Math.Abs(ControlOnlyCount)) & " control only Value Pairs","#FF0000")
    
            'Get a listing of all Status Value pairs
            Dim ValueStatusPairStatusListing As HomeSeerAPI.VSVGPairs.VSPair() = hs.DeviceVSP_GetAllStatus(sourceDev)
            Dim ValueStatusPairs As HomeSeerAPI.VSPair
            Dim SPair As HomeSeerAPI.VSPair
            Dim newGPair As HomeSeerAPI.VGPair
            Dim oldGPair As HomeSeerAPI.VGPair
            Dim AddVSPairSuccess As Boolean = False
            Dim AddVGPairSuccess As Boolean = False
            Dim TempValue As Double = 0
    
            For Each ValueStatusPairs In ValueStatusPairStatusListing
    
                AddVSPairSuccess = False
                AddVGPairSuccess = False
    
                If ValueStatusPairs.ControlStatus = 1 Then
                    SPair = New VSPair (HomeSeerAPI.ePairStatusControl.Status)
                ElseIf ValueStatusPairs.ControlStatus = 3 Then
                    SPair = New VSPair (HomeSeerAPI.ePairStatusControl.Both)
                End If
    
                Spair.Render_Location.Row = ValueStatusPairs.Render_Location.Row
                Spair.Render_Location.Column = ValueStatusPairs.Render_Location.Column
                Spair.Render_Location.ColumnSpan = ValueStatusPairs.Render_Location.ColumnSpan
                Spair.Render = ValueStatusPairs.Render
                Spair.PairButtonImageType = ValueStatusPairs.PairButtonImageType
                Spair.PairButtonImage = ValueStatusPairs.PairButtonImage
                Spair.ControlUse = ValueStatusPairs.ControlUse
    
                If ValueStatusPairs.PairType = 1 Then
                    SPair.PairType = VSVGPairType.SingleValue
                    TempValue = ValueStatusPairs.Value
                    Spair.Value = TempValue
                    Spair.Status = hs.DeviceVSP_GetStatus(sourceDev,ValueStatusPairs.Value,HomeSeerAPI.ePairStatusControl.Status)
                    If Debug Then hs.writelog(logName,"Value/Status: " & CStr(TempValue) & " / " & hs.DeviceVSP_GetStatus(sourceDev,TempValue,HomeSeerAPI.ePairStatusControl.Status))
    
                    oldGPair = hs.DeviceVGP_Get(sourceDev, TempValue)
                    If Not oldGPair Is Nothing Then
                        newGPair = New VGPair
                        newGPair.PairType = VSVGPairType.SingleValue
                        newGPair.Set_Value = TempValue
                        newGPair.Graphic = hs.DeviceVGP_GetGraphic(sourceDev, TempValue)
                        If Debug Then hs.writelog(logName,"&nbsp;&nbsp;Value/Graphics: " & CStr(TempValue) & " " & Chr(34) & hs.DeviceVGP_GetGraphic(sourceDev, TempValue) & Chr(34))
                        AddVGPairSuccess = hs.DeviceVGP_AddPair(targetDev, newGPair)
                        If Not AddVGPairSuccess Then hs.writelogEx(logName, "Addition of Status/Graphics " & TempValue & " not successful" ,"#FF0000")
                    End If
    
                ElseIf ValueStatusPairs.PairType = 2 Then
                    SPair.PairType = VSVGPairType.Range
                    TempValue = ValueStatusPairs.RangeStart
                    SPair.RangeStart = TempValue
                    SPair.RangeEnd = ValueStatusPairs.RangeEnd
                    SPair.RangeStatusPrefix = ValueStatusPairs.RangeStatusPrefix
                    SPair.RangeStatusSuffix = ValueStatusPairs.RangeStatusSuffix
                    SPair.RangeStatusDecimals = ValueStatusPairs.RangeStatusDecimals
                    SPair.RangeStatusDivisor = ValueStatusPairs.RangeStatusDivisor
                    SPair.IncludeValues = ValueStatusPairs.IncludeValues
                    SPair.ValueOffset = ValueStatusPairs.ValueOffset
                    SPair.HasAdditionalData = ValueStatusPairs.HasAdditionalData
                    SPair.HasScale = ValueStatusPairs.HasScale
                    SPair.ZeroPadding = ValueStatusPairs.ZeroPadding
                    If Debug Then hs.writelog(logName,"Value/Status: " & CStr(TempValue) & " To " & CStr(ValueStatusPairs.RangeEnd))
    
                    oldGPair = hs.DeviceVGP_Get(sourceDev, TempValue)
                    If Not oldGPair Is Nothing Then
                        newGPair = New VGPair
                        newGPair.PairType = VSVGPairType.Range
                        newGPair.RangeStart = oldGPair.RangeStart
                        newGPair.RangeEnd = oldGPair.RangeEnd
                        newGPair.Graphic = hs.DeviceVGP_GetGraphic(sourceDev, oldGPair.RangeStart)
                        If Debug Then hs.writelog(logName,"&nbsp;&nbsp;Value/Graphics: " & CStr(oldGPair.RangeStart) & " To "  & CStr(oldGPair.RangeEnd) & " " & Chr(34) & hs.DeviceVGP_GetGraphic(sourceDev, oldGPair.RangeStart) & Chr(34))
                        AddVGPairSuccess = hs.DeviceVGP_AddPair(targetDev, newGPair)
                        If Not AddVGPairSuccess Then hs.writelogEx(logName, "Addition of Status/Graphics " & TempValue & " not successful" ,"#FF0000")
                    End If
    
                End If
    
                AddVSPairSuccess = hs.DeviceVSP_AddPair(targetDev, SPair)
                If Not AddVSPairSuccess Then hs.writelogEx(logName, "Addition of Status/Value " & TempValue & " not successful" ,"#FF0000")
    
            Next
            ValueStatusPairStatusListing = Nothing
            ValueStatusPairs = Nothing
            SPair = Nothing
            newGPair = Nothing
            oldGPair = Nothing
            AddVSPairSuccess = Nothing
            AddVGPairSuccess = Nothing
            TempValue = Nothing
            ControlCount = Nothing
            StatusCount = Nothing
            ControlOnlyCount = Nothing
    
            hs.writelogEx(logName, "Completed @ " & CStr(Now),"#008000")
    
        Catch ex As Exception
            hs.writelogEx(logName, ex.Message.ToString,"#FF0000")
        End Try
    
        Debug = Nothing
        logName = Nothing
        ParmArray = Nothing
        sourceDev = Nothing
        targetDev = Nothing
    
    End Sub
    HS 4.2.8.0: 2134 Devices 1252 Events
    Z-Wave 3.0.10.0: 133 Nodes on one Z-Net

    #2
    Oh, so many times I've wished for this functionality. Thanks, can't wait to give it a try!
    -Wade

    Comment


      #3
      Just tested, perfect result. Brilliant! Thanks again!
      -Wade

      Comment


        #4
        Originally posted by cc4005 View Post
        Just tested, perfect result. Brilliant! Thanks again!
        Great, glad it worked for you!
        HS 4.2.8.0: 2134 Devices 1252 Events
        Z-Wave 3.0.10.0: 133 Nodes on one Z-Net

        Comment


          #5
          Made some minor changes to the script to put a warning in the log about "Control Only" VS pairs not getting copied if the source device has those.
          HS 4.2.8.0: 2134 Devices 1252 Events
          Z-Wave 3.0.10.0: 133 Nodes on one Z-Net

          Comment


            #6
            Sorry to ask...but how are you using this script in home automation? Always looking to learn something new!
            Thanks!


            Sent from my iPhone using Tapatalk
            HS4 4.2.6.0 &HSTouch Designer 3.0.80
            Plugin's:
            BLBackup, BLOccupied, BLShutdown, EasyTrigger, Ecobee, Nest, AK Bond
            EnvisaLink DSC, PHLocation, Pushover, SONOS, Blue Iris, UltraRachio3,
            weatherXML, Jon00 Alexa Helper, Network Monitor, MyQ, Z-Wave

            Comment


              #7
              Originally posted by The Profit View Post
              Sorry to ask...but how are you using this script in home automation? Always looking to learn something new!
              Thanks!
              The script is not an "automation" script. I've created virtual devices in the past an not really happy with the icons I had used, etc. So rather than manually changing each device to how I know want them, I change one device and then use the script to copy those changes to similar devices. As an example, I have 7 devices that track daily rainfall over the last week and I used the script to copy the changes on one to the other 6.
              HS 4.2.8.0: 2134 Devices 1252 Events
              Z-Wave 3.0.10.0: 133 Nodes on one Z-Net

              Comment


                #8
                To take this script concept a bit further, I'm curious whether the following is of interest to you to add. I certainly don't have the scripting chops to do it.

                1. Allow for mass copying. I.e., pass a series of device numbers wherein the first is the source and following are destination devices.
                2. Allow for mass copying of device thumbnail image.

                On second thought, the thumbnail image would need to be separate--either by setting an option or separate script entirely. I'd like to use the thumbnail for quick visual identification of categories of virtual devices but it would take so long to individually change them I've never taken it on.

                Thanks.
                -Wade

                Comment


                  #9
                  Wade

                  Hi Wade, I'll take a look at item 1. For item 2, there's a plugin called DTSDeviceImages that allows the bulk setting of device images/thumbnails: https://forums.homeseer.com/forum/ho...images-at-once

                  Cheers
                  Al
                  HS 4.2.8.0: 2134 Devices 1252 Events
                  Z-Wave 3.0.10.0: 133 Nodes on one Z-Net

                  Comment


                    #10
                    Originally posted by sparkman View Post
                    Wade

                    Hi Wade, I'll take a look at item 1. For item 2, there's a plugin called DTSDeviceImages that allows the bulk setting of device images/thumbnails: https://forums.homeseer.com/forum/ho...images-at-once

                    Cheers
                    Al
                    Thanks for both!
                    -Wade

                    Comment


                      #11
                      Thanks for sharing this. But please advise.
                      I am using this to copy the std thermostat status set up to a new virtual temp setpoint.
                      It copied the status text, but not status graphics data.
                      What am I doing wrong?

                      Tried from several source devices.

                      Comment


                        #12
                        Originally posted by Stubborn View Post
                        Thanks for sharing this. But please advise.
                        I am using this to copy the std thermostat status set up to a new virtual temp setpoint.
                        It copied the status text, but not status graphics data.
                        What am I doing wrong?

                        Tried from several source devices.
                        Can you post screenshots of the Advanced and Status Graphics tabs of both the source device and the device that you are copying to? Any errors or warnings in the log when you run it? What HS version are you running?
                        HS 4.2.8.0: 2134 Devices 1252 Events
                        Z-Wave 3.0.10.0: 133 Nodes on one Z-Net

                        Comment


                          #13
                          Thanks, works great.
                          At first I thought that it copied the Status Value and Graphic from one device to another but I can do that with Easy Trigger so I am all set.
                          DSteiNeuro

                          HS3Pro

                          MSI Cubi Intel(R) Core(TM) i5-5200U CPU @ 2.20GHz, 2201 Mhz, 2 Core(s), 4 Logical Processor(s) 16GB DDRl RAM

                          Enabled Plug-Ins
                          BLRussound, BLSpeech, HSTouch Server, JowiHue, MyQ, Nest, Rain8, Squeezebox, Ultra1Wire3, UltraGCIR3, Vista Alarm, X10,Z-Wave

                          Comment


                            #14
                            Jul-06 01:19:56 VSVG Copy Completed @ 7/6/2020 1:19:56 AM
                            Jul-06 01:19:56 VSVG Copy 1 Status Value Pairs to be copied from ref id: 1092 to ref id: 1222
                            Jul-06 01:19:56 Event Running script in background: C:/Program Files (x86)/HomeSeer HS3/scripts/DeviceStatusGraphichsCopy.vb("Main","1092,1222")


                            Attached Files

                            Comment


                              #15
                              Advanced config:
                              Scratching my head on what I am doing that is different from others, it is a fairly simple case.
                              Attached Files

                              Comment

                              Working...
                              X