Announcement

Collapse
No announcement yet.

How to convert HS3 devices to HS4

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

    #31
    Originally posted by dmurphy View Post
    I will need to update mine....But I don't want to keep updating them, just a one time deal.

    I could create a PED but everybody doing this update their own 'special' way seems less than ideal. spud any suggestions?
    In all my plugins I store the version number of the plugin that created or updated the device/feature in the PED, so I can use that to decide if I need to migrate a device or not.
    But I agree that having access to the version property through the PluginSdk may be good so I created a feature request for that (PSDK-211)

    Comment


      #32
      Originally posted by spud View Post

      In all my plugins I store the version number of the plugin that created or updated the device/feature in the PED, so I can use that to decide if I need to migrate a device or not.
      But I agree that having access to the version property through the PluginSdk may be good so I created a feature request for that (PSDK-211)
      spud Can we get some official position of HST on how to handle HS3 devices in HS4?
      Should we convert them or leave them as-is?
      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


        #33
        Originally posted by dcorsus View Post

        I cleaned out my code to make it more generic. I haven't tested it so hope I didn't make typos so test it first

        Code:
         Private Function DoHS3Migration(rootDeviceRef as Integer) As Integer
        ' Start with Root devive which needs to turn from a single device (potentially with children) into a device and a feature. In order not to break the references,
        ' I would first create a New device And then link the old to the New which would mimic a feature
        
        If rootDeviceRef = -1 Then
        Return -1
        End If
        ' create the new master device, note the parameters you use here should be in line with what you did in HS3 or what you want it to be going forward. You can move setting type, location etc out of this
        ' function and do it in the calling function after this function return the new DEVICE reference
        Dim df As DeviceFactory = HomeSeer.PluginSdk.Devices.DeviceFactory.CreateDevice(Id) ' this actually only creates a local class
        ' NOTE you would update this section to what you want this new device to be named
        df.WithName("Sonos Master Control")
        df.AsType(HomeSeer.PluginSdk.Devices.Identification.EDeviceT ype.Generic, 0)
        df.WithLocation2("") ' set this to what you want it to be
        df.WithLocation("Master") ' set this to what you want it to be
        '
        Dim NDD As Devices.NewDeviceData
        NDD = df.PrepareForHs()
        newDeviceRef = myHomeSeerSystem.CreateDevice(NDD)
        If newDeviceRef = -1 Then ' checks if valid ref
        Return -1
        End If
        Dim adList As HashSet(Of Integer) = Nothing ' this will be the list of children
        ' copy the children which used to be on the old master root device (rootDeviceRef) now to the new DEVICE (newDeviceRef) and subsequently turn the old root into a feature
        Try
        Dim associatedDevicesList As New HashSet(Of Integer)
        associatedDevicesList.Add(rootDeviceRef) ' first add the old root and subsequent copy all children
        Dim assList As String = rootDeviceRef.ToString & ", "
        adList = myHomeSeerSystem.GetDeviceByRef(rootDeviceRef).AssociatedDev ices ' this is the old list of associated devices
        Dim dv As HsDevice = myHomeSeerSystem.GetDeviceByRef(rootDeviceRef)
        For Each ad As Integer In adList ' add all the children
        associatedDevicesList.Add(ad)
        assList &= ad.ToString & ", "
        Next
        myHomeSeerSystem.UpdatePropertyByRef(newDeviceRef, EProperty.AssociatedDevices, associatedDevicesList)
        Catch ex As Exception
        ' you probably want to log some error because we just created a new device but can't update it
        Return -1
        End Try
        
        ' now do all children, link them to the new parent (ie DEVICE) and change the children into features
        
        Try
        For Each devRef As Integer In adList
        If Not (myHomeSeerSystem.IsRefDevice(devRef)) Then
        Try
        ' this would be features in HS4 or Children in HS3
        Dim associatedDevicesList As HashSet(Of Integer) = New HashSet(Of Integer)
        associatedDevicesList.Add(newDeviceRef)
        myHomeSeerSystem.UpdatePropertyByRef(devRef, EProperty.AssociatedDevices, associatedDevicesList) ' link the feature to its parent
        Catch ex As Exception
        'Log("Error in DoHS3Migration updating an existing feature with ref = " & devRef & " and Error = " & ex.Message, LogType.LOG_TYPE_ERROR)
        End Try
        End If
        Next
        Catch ex As Exception
        'Log("Error in DoHS3Migration with error = " & ex.Message, LogType.LOG_TYPE_ERROR)
        End Try
        '
        return newDeviceRef
        End Function
        Thanks for posting this code it was very useful.

        One important line is missing from this sample setting the ERelationship to ERelationship.Feature

        myHomeSeerSystem.UpdatePropertyByRef(devRef, EProperty.Relationship, ERelationship.Feature);
        HS3 Pro Edition 3.0.0.435 (Windows 10 vmware)
        BLOccupied:,UltraNetCam3:,weatherXML:,RFXCOM:,Current Cost 3P:,UltraGCIR3:
        DMMQTT:,Kodi:,Z-Wave:,BLRadar:,EasyTrigger:,MySensors:,BLBackup:

        Comment


          #34
          Originally posted by dmurphy View Post

          Thanks for posting this code it was very useful.

          One important line is missing from this sample setting the ERelationship to ERelationship.Feature

          myHomeSeerSystem.UpdatePropertyByRef(devRef, EProperty.Relationship, ERelationship.Feature);
          Indeed very important, probably deleted it by mistake from my original code, which had a bit more changes involved.

          Comment


            #35
            Dirk
            I see the following line of code in the above

            Code:
            myHomeSeerSystem.UpdatePropertyByRef(newDeviceRef, EProperty.AssociatedDevices, associatedDevicesList)
            i was using but it doesn't seem to be working anymore

            Code:
            dv.associateddevices.add(newdevref)
            did that break in hs 4.2.5.0?

            Mark

            HS3 Pro 4.2.19.5
            Hardware: Insteon Serial PLM | AD2USB for Vista Alarm | HAI Omnistat2 | 1-Wire HA7E | RFXrec433 | Dahua Cameras | LiftMaster Internet Gateway | Tuya Smart Plugs
            Plugins: Insteon (mine) | Vista Alarm (mine) | Omnistat 3 | Ultra1Wire3 | RFXCOM | HS MyQ | BLRadar | BLDenon | Tuya | Jon00 Charting | Jon00 Links
            Platform: Windows Server 2022 Standard, i5-12600K/3.7GHz/10 core, 16GB RAM, 500GB SSD

            Comment


              #36
              Originally posted by mnsandler View Post
              Dirk
              I see the following line of code in the above

              Code:
              myHomeSeerSystem.UpdatePropertyByRef(newDeviceRef, EProperty.AssociatedDevices, associatedDevicesList)
              i was using but it doesn't seem to be working anymore

              Code:
              dv.associateddevices.add(newdevref)
              did that break in hs 4.2.5.0?
              Just did quick test with 4.2.5 and don't see any issue

              Comment


                #37
                Dirk,
                maybe I'm not saving the Changes properly. Given the same dv object from the above code, I use the following to save the changes

                Code:
                Dim ChangesCopy = dv.Changes
                hs4.UpdateDeviceByRef(dv.Ref, ChangesCopy)
                again, this was all working in prev hs 4.1.x versions

                fwiw, UpdateDeviceByRef is supposed to return the updated dv. I noticed the associateddevices aren't saved to the return dv object.

                Mark

                HS3 Pro 4.2.19.5
                Hardware: Insteon Serial PLM | AD2USB for Vista Alarm | HAI Omnistat2 | 1-Wire HA7E | RFXrec433 | Dahua Cameras | LiftMaster Internet Gateway | Tuya Smart Plugs
                Plugins: Insteon (mine) | Vista Alarm (mine) | Omnistat 3 | Ultra1Wire3 | RFXCOM | HS MyQ | BLRadar | BLDenon | Tuya | Jon00 Charting | Jon00 Links
                Platform: Windows Server 2022 Standard, i5-12600K/3.7GHz/10 core, 16GB RAM, 500GB SSD

                Comment


                  #38
                  Are you using the latest SDK? If you step through the code or add some log entries, does dv.changes.count (for example) show it all is Ok and not a bug somewhere?

                  Comment


                    #39
                    Originally posted by dcorsus View Post
                    Are you using the latest SDK? If you step through the code or add some log entries, does dv.changes.count (for example) show it all is Ok and not a bug somewhere?
                    Dirk, thanks for the reply. I do have SDK v 1.3.1 installed

                    I do not see the associated devices 'changes' in the dv.Changes collection, but i do see that dv.Changes.count > 0 (and my values )

                    I will try adding the following to see if that will save the associated devices. seems to me that the associateddevices.add method should take care of all this...guess something changed in the sdk.

                    myHomeSeerSystem.UpdatePropertyByRef(newDeviceRef, EProperty.AssociatedDevices, associatedDevicesList)

                    i just dont understand why this isn't working anymore
                    Mark

                    HS3 Pro 4.2.19.5
                    Hardware: Insteon Serial PLM | AD2USB for Vista Alarm | HAI Omnistat2 | 1-Wire HA7E | RFXrec433 | Dahua Cameras | LiftMaster Internet Gateway | Tuya Smart Plugs
                    Plugins: Insteon (mine) | Vista Alarm (mine) | Omnistat 3 | Ultra1Wire3 | RFXCOM | HS MyQ | BLRadar | BLDenon | Tuya | Jon00 Charting | Jon00 Links
                    Platform: Windows Server 2022 Standard, i5-12600K/3.7GHz/10 core, 16GB RAM, 500GB SSD

                    Comment


                      #40
                      Adding the following fixed the issue.

                      Code:
                      hs4.UpdatePropertyByRef(dv.Ref, EProperty.AssociatedDevices, dv.AssociatedDevices)
                      Just seems unnecessary to me since we can use the following that method should automatically be adding the change to the Changed collection

                      Code:
                      dv.AssociatedDevices.add(ref)
                      Mark

                      HS3 Pro 4.2.19.5
                      Hardware: Insteon Serial PLM | AD2USB for Vista Alarm | HAI Omnistat2 | 1-Wire HA7E | RFXrec433 | Dahua Cameras | LiftMaster Internet Gateway | Tuya Smart Plugs
                      Plugins: Insteon (mine) | Vista Alarm (mine) | Omnistat 3 | Ultra1Wire3 | RFXCOM | HS MyQ | BLRadar | BLDenon | Tuya | Jon00 Charting | Jon00 Links
                      Platform: Windows Server 2022 Standard, i5-12600K/3.7GHz/10 core, 16GB RAM, 500GB SSD

                      Comment


                        #41
                        Originally posted by mnsandler View Post
                        Code:
                        hs4.UpdatePropertyByRef(dv.Ref, EProperty.AssociatedDevices, dv.AssociatedDevices)
                        Just seems unnecessary to me since we can use the following that method should automatically be adding the change to the Changed collection

                        Code:
                        dv.AssociatedDevices.add(ref)
                        The Changed collection is only used to avoid multiple calls to hs4 - so they collect all changes locally and then send to HS in one call. I think it's over-complicated and unnecessary - given you don't often change any device settings, except for value.

                        AbstractHsDevice is only used for this purpose, it doesn't provide any other useful functionality, i.e. communication with HS. So I find AbstractHsDevice pretty useless "API"

                        Comment

                        Working...
                        X