Announcement

Collapse
No announcement yet.

Script create device

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

  • Script create device

    Hi,

    How do Ic reate a device by a script and set device type and clear or set the unit code?

    Creation can be done by create deviceref if im correct.

    I am teying to accomplish this by use of vb.

    Regards

    Bart
    Last edited by bartbakels; February 12th, 2014, 12:23 PM.
    Regards Bart
    ------------------------------------------
    Win7 64Bit on Intel NUCI7 with SSD
    HSPRO 3.
    Devices; 1370 Events; 691

    Jon00 Scripts, JowHue, HSTouch, Plugwise, Z-wave, Ultranetatmo, Ultracam, PHlocation, BLUSBUIRT, MeiHarmony, Buienradar, MEiUnifi Pushover 3P, Random, Nest HSPhone and Blueiris

    Visonic Powermax Alarm System (HS3) Interface: http://www.domoticaforum.eu/viewtopic.php?f=68&t=11129

  • #2
    Nobody,

    Im still trying to create a device via VBscript, which succeeds, but i also want to change location, devicecode, device type etc. tried this;

    Code:
    Sub Main(params As Object)
     
    dim dv
    dv = hs.NewDeviceRef("Toon Test apparaat")
       
    If dv IsNot Nothing Then
    dv.Device_Type_String(hs) = "Joe Bazooka Bubble Gum"
    End If
    
    hs.WriteLog("apparaat referentie", dv)
    
    End Sub
    but this does not work...
    Regards Bart
    ------------------------------------------
    Win7 64Bit on Intel NUCI7 with SSD
    HSPRO 3.
    Devices; 1370 Events; 691

    Jon00 Scripts, JowHue, HSTouch, Plugwise, Z-wave, Ultranetatmo, Ultracam, PHlocation, BLUSBUIRT, MeiHarmony, Buienradar, MEiUnifi Pushover 3P, Random, Nest HSPhone and Blueiris

    Visonic Powermax Alarm System (HS3) Interface: http://www.domoticaforum.eu/viewtopic.php?f=68&t=11129

    Comment


    • #3
      Originally posted by bartbakels View Post
      Nobody,

      Im still trying to create a device via VBscript, which succeeds, but i also want to change location, devicecode, device type etc. tried this;

      Code:
      Sub Main(params As Object)
       
      dim dv
      dv = hs.NewDeviceRef("Toon Test apparaat")
         
      If dv IsNot Nothing Then
      dv.Device_Type_String(hs) = "Joe Bazooka Bubble Gum"
      End If
      
      hs.WriteLog("apparaat referentie", dv)
      
      End Sub
      but this does not work...
      Try this as a start

      Code:
      Sub Main(params As Object)
       
      Dim dv As Scheduler.Classes.DeviceClass = Nothing
      
      dv = hs.NewDeviceRef("Toon Test apparaat")
         
      If dv IsNot Nothing Then
      
      dv.Device_Type_String(hs) = "Joe Bazooka Bubble Gum"
      hs.WriteLog("apparaat referentie", dv.ref(hs))
      
      End If
      
      End Sub
      My Plugins:

      Pushover 3P | DoorBird 3P | Current Cost 3P | Velleman K8055 3P | LAMetric 3P | Garadget 3P | Hive 3P |
      Yeelight 3P | Nanoleaf 3P

      Comment


      • #4
        Mrhappy,

        Thanks, Stupid me

        I got it all working in my script however I have 2 additional questions;

        now I create a device if needed and change values and devicestring by

        Code:
        Dim dv As Scheduler.Classes.DeviceClass = Nothing
        Dim Value
        Dim DevExists
        Dim Ref
        
        'Current temperature
        '-------------------------
        
        Value = currenttemp
        DevExists = hs.DeviceExistsCode("Toon-PV")
        
        If DevExists = -1 Then 
           dv = hs.NewDeviceEx("Toon Temperatuur")
           dv.Location(hs) = "Toon"
           dv.Location2(hs) = "Status"
           dv.Code(hs) = "Toon-PV"
           dv.Device_Type_String(hs) = "Toon Thermostaat"
           dv.Image(hs) = "/images/toon/toon.png"
        End If
        
        Ref = hs.GetDeviceRef("Toon-PV")
        hs.SetDeviceValueByRef(Ref, Value , False)
        hs.SetDeviceString(Ref, Value & " Graden", True)

        However When i open the device settings of this devic,e the device code is getting cleared and the device will be recreated on the next script call. Did i forgot something?


        In addition how do i remove the little dimming lightbulb in front of the device?


        thanks in advance

        Bart
        Regards Bart
        ------------------------------------------
        Win7 64Bit on Intel NUCI7 with SSD
        HSPRO 3.
        Devices; 1370 Events; 691

        Jon00 Scripts, JowHue, HSTouch, Plugwise, Z-wave, Ultranetatmo, Ultracam, PHlocation, BLUSBUIRT, MeiHarmony, Buienradar, MEiUnifi Pushover 3P, Random, Nest HSPhone and Blueiris

        Visonic Powermax Alarm System (HS3) Interface: http://www.domoticaforum.eu/viewtopic.php?f=68&t=11129

        Comment


        • #5
          hi,

          I already found my mistake, I needed to check on device address instead of code and instead of the code I now written the address.

          Regarding the devicevalues i used this which worked fine;

          GPair = New VGPair
          GPair.PairType = VSVGPairType.Range
          GPair.RangeStart = 0
          GPair.RangeEnd = 100
          GPair.Graphic = "/images/toon/TemperatureSP.png"
          hs.DeviceVGP_AddPair(ref, GPair)

          OR

          GPair = New VGPair
          GPair.PairType = VSVGPairType.SingleValue
          GPair.Set_Value = 0
          GPair.Graphic = "/images/toon/Idle.png"

          Regards

          Bart
          Regards Bart
          ------------------------------------------
          Win7 64Bit on Intel NUCI7 with SSD
          HSPRO 3.
          Devices; 1370 Events; 691

          Jon00 Scripts, JowHue, HSTouch, Plugwise, Z-wave, Ultranetatmo, Ultracam, PHlocation, BLUSBUIRT, MeiHarmony, Buienradar, MEiUnifi Pushover 3P, Random, Nest HSPhone and Blueiris

          Visonic Powermax Alarm System (HS3) Interface: http://www.domoticaforum.eu/viewtopic.php?f=68&t=11129

          Comment


          • #6
            Hey guys - is there a way to not show the default light bulb images when creating a device via scripts? I know I can define images via VGPair but I don't want an image. Even though no VGPairs are defined it keeps showing default lightbulb on/off/dim images in the status field.

            Comment


            • #7
              Originally posted by robilium View Post
              Hey guys - is there a way to not show the default light bulb images when creating a device via scripts? I know I can define images via VGPair but I don't want an image. Even though no VGPairs are defined it keeps showing default lightbulb on/off/dim images in the status field.
              Try setting the image property,

              Public Property Image(ByVal hs As IHSApplication) As String

              The Image property holds a path string to an image file to represent the device on the status views pages. The image path should be referenced from the root of the HTML folder under the main HomeSeer folder.
              My Plugins:

              Pushover 3P | DoorBird 3P | Current Cost 3P | Velleman K8055 3P | LAMetric 3P | Garadget 3P | Hive 3P |
              Yeelight 3P | Nanoleaf 3P

              Comment


              • #8
                thnaks for responding! I tried it and that sets the image itself for the device. However under STATUS it still defaults to show a lightbulb state next to the custom textual value settings.

                Comment


                • #9
                  bump for ideas

                  Comment


                  • #10
                    Try

                    Code:
                    hs.DeviceVGP_ClearAll(ref, True)
                    Wade

                    sigpic

                    website | products | support | youtube
                    I know nothing...., nothing!!!

                    Comment


                    • #11
                      Originally posted by Sgt. Shultz View Post
                      Try

                      Code:
                      hs.DeviceVGP_ClearAll(ref, True)
                      Good luck with that Wade, have only been complaining about that for last 2 years with counterargument about backward compatibility w/ HS2.

                      I set the device string to something like single blank or underscore to get rid of it.

                      Dirk

                      Comment


                      • #12
                        I am driving myself mad with this light bulb issue, I create four devices in a script with this routine;

                        Code:
                        Sub CreateDevices()
                        
                            Dim CurrRef As Integer = 0
                            Dim BaseRef As Integer = 0
                            Dim dv As Scheduler.Classes.DeviceClass = Nothing
                            Dim root_dv As Scheduler.Classes.DeviceClass = Nothing
                        
                            Try
                                Log("Devices Do Not Exist - Creating - Data Will Update On Next Run")
                                'four devices need to be created, root, current location, current time, am I at home
                                For i As Byte = 0 To 3 'needs to be four new devices
                                    Select Case i
                                        Case 0
                                            dv = hs.GetDeviceByRef(hs.NewDeviceRef(DAddS & " Root Device"))
                                            dv.Address(hs) = DAddS & "-Root"
                                            BaseRef = dv.Ref(hs)
                                        Case 1
                                            dv = hs.GetDeviceByRef(hs.NewDeviceRef(DAddS & " Current Location Data"))
                                            dv.Address(hs) = DAddS & "-CurrLoc"
                                        Case 2
                                            dv = hs.GetDeviceByRef(hs.NewDeviceRef(DAddS & " Current Location Time"))
                                            dv.Address(hs) = DAddS & "-CurrTime"
                                        Case 3
                                            dv = hs.GetDeviceByRef(hs.NewDeviceRef(DAddS & " Am I At Home"))
                                            dv.Address(hs) = DAddS & "-AmIAtHome"
                                    End Select
                        
                                    dv.Location(hs) = "FollowMee"
                                    dv.Last_Change(hs) = Now
                                    dv.Device_Type_String(hs) = DAddS & " Device"
                        
                                    Log("VGP Count: " & hs.DeviceVGP_Count(dv.Ref(hs)))
                        
                                    hs.DeviceVGP_ClearAll(dv.Ref(hs), True)
                                    hs.DeviceVGP_Clear(dv.Ref(hs), 0)
                                    hs.DeviceVGP_Clear(dv.Ref(hs), 1)
                        
                                    hs.saveeventsdevices()
                        
                                    Log("VGP Count: " & hs.DeviceVGP_Count(dv.Ref(hs)))
                        
                                    If i = 0 Then 'on the base device do this, set up the relationships between the devices
                                        root_dv = dv
                                        dv.Relationship(hs) = Enums.eRelationship.Parent_Root
                                    Else
                                        If root_dv IsNot Nothing Then root_dv.AssociatedDevice_Add(hs, dv.Ref(hs))
                                        dv.Relationship(hs) = Enums.eRelationship.Child
                                        dv.AssociatedDevice_Add(hs, BaseRef)
                                    End If
                        
                                    'VSPairs? I think only the Am I At Home will need a VSPair
                        
                                    Select Case i
                        
                                        Case 0
                                            hs.setdevicestring(dv.Ref(hs), "Root Device", True)
                                        Case 1
                                            hs.setdevicestring(dv.Ref(hs), "Awaiting Data", True)
                                        Case 2
                                            hs.setdevicestring(dv.Ref(hs), "Awaiting Data", True)
                                        Case 3
                                            Dim Pair As VSPair
                        
                                            Pair = New VSPair(HomeSeerAPI.ePairStatusControl.Status)
                                            Pair.PairType = VSVGPairType.SingleValue
                                            Pair.Value = 1
                                            Pair.Status = "I Am At Home"
                                            hs.DeviceVSP_AddPair(dv.Ref(hs), Pair)
                        
                                            Pair = New VSPair(HomeSeerAPI.ePairStatusControl.Status)
                                            Pair.PairType = VSVGPairType.SingleValue
                                            Pair.Value = 0
                                            Pair.Status = "I Am Not At Home"
                                            hs.DeviceVSP_AddPair(dv.Ref(hs), Pair)
                        
                                    End Select
                        
                                Next
                        
                                Log("End Of Create Devices Routine")
                            Catch ex As Exception
                                Log("Create Devices Exception: " & ex.message.tostring)
                            End Try
                        
                        End Sub
                        No matter what I do I cannot get rid of the light bulb icon, I have tried all sorts. Removing the VGPairs with _ClearAll and removing specific pairs by specifying a value, as a test I put in a count before and after removing and it always reports 0 so I am very confused, it seems not to have a VGPair to clear even though the graphics update suggesting that it has?

                        Dec-24 02:51:06 FollowMee End Of Create Devices Routine
                        Dec-24 02:51:06 FollowMee VGP Count: 0
                        Dec-24 02:51:06 FollowMee VGP Count: 0
                        Dec-24 02:51:06 FollowMee VGP Count: 0
                        Dec-24 02:51:06 FollowMee VGP Count: 0
                        Dec-24 02:51:06 FollowMee VGP Count: 0
                        Dec-24 02:51:06 FollowMee VGP Count: 0
                        Dec-24 02:51:06 FollowMee VGP Count: 0
                        Dec-24 02:51:06 FollowMee VGP Count: 0
                        Dec-24 02:51:06 FollowMee Devices Do Not Exist - Creating - Data Will Update On Next Run
                        Dec-24 02:51:06 FollowMee Am I At Home: True
                        As you can see on the image by default they all have the off light bulb indicator (why), then the last device when set to the value of one has the dim bulb indicator even though there are no VGPair's set up in the device property. On the bottom of the image you can see that 'Status' appears to be still in the realms of a normal virtual device with the value of one being dim. I have also tested whether any VSPair's exist that are not represented in the UI and it also returns a count of zero for these.

                        This appears to be something specific to creating them from scripts from what I can see, I have done it in plugins countless times and never had this issue.

                        It would be great if someone could put me out of my misery on this one...
                        Last edited by mrhappy; January 31st, 2015, 05:31 PM.
                        My Plugins:

                        Pushover 3P | DoorBird 3P | Current Cost 3P | Velleman K8055 3P | LAMetric 3P | Garadget 3P | Hive 3P |
                        Yeelight 3P | Nanoleaf 3P

                        Comment


                        • #13
                          Hi Adam,

                          I believe the light bulbs are default if there are no status graphics added. Once you add specific status graphics, the light bulbs are gone. Manually created devices have the same issue.

                          Cheers
                          Al
                          HS 3.0.0.548: 1976 Devices 1156 Events
                          Z-Wave 3.0.1.262: 123 Nodes on one Z-Net

                          Comment


                          • #14
                            Adam,

                            Try setting dv.Interface(hs) to something other than blank i.e.

                            PHP Code:
                            dv.Interface(hs)="FollowMee" 
                            Otherwise set the devicestring for the device which contains a blank image i.e.

                            PHP Code:
                            hs.SetDeviceString(dvRef"<img src=""/images/Homeseer/ui/5-x-5_trans_spacer.gif"">"True
                            Jon

                            Comment


                            • #15
                              Thanks guys, it was setting the interface property that sorted it, I am still a bit confused as to why when the help file says

                              Public Property Interface(ByVal hs As IHSApplication) As String

                              This property holds the name of the plug-in that owns/manages this device. If the property is null or an empty string, the device is not managed by a plug-in.
                              So if the device is not managed by a plugin (which in this case it isn't) I thought that you could leave the interface empty or pass nothing but it appears you can't without the bulb icons staying (everything else works fine) - is this a bug or just me not understanding it right? I know that setting the interface property has other implications like blocking the address and I think protecting the VSPair's from being edited which is not a bad thing but neither what I was expecting creating the device from a script.
                              My Plugins:

                              Pushover 3P | DoorBird 3P | Current Cost 3P | Velleman K8055 3P | LAMetric 3P | Garadget 3P | Hive 3P |
                              Yeelight 3P | Nanoleaf 3P

                              Comment

                              Working...
                              X