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:

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:
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.
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)
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," 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," 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
Comment