Announcement

Collapse
No announcement yet.

Creating HS device

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

  • Creating HS device

    Hi All,

    Apologies if this has been asked, I have been looking through manuals trying to understand how I can get my plugin to create the status devices it needs, and then reinitialize them each time.

    How do I go about doing this in HS3 through a plugin as I am just lost, I understand the concept of what I want to do, which is to determine if the device exists, and if not to create it, but if it does exist then don't bother but what I don't understand is how to create the device through the plugin, and then how to reference the device the plugin created.

    When other plugin creators are for example writing a string to their device, how are they doing it, are you creating a device at the start that you know will have a specific technology address and then writing to that, or is there a better way of doing it?

    Many Thanks!
    HS3 PRO, Win10, WeatherXML, HSTouch, Pushover, UltraGCIR, Heaps of Jon00 Plugins, Just sold and about to move so very slim system.

    Facebook | Twitter | Flickr | Google+ | Website | YouTube

  • #2
    You can do it any number of ways...I personally do it by creating them the same as you do in the script (the HSPI_SAMPLE_BASIC has a set of devices it also creates), then in the PlugExtraData object I include a unique number in the device that simplifies how I refer to it. The device now both has the .Interface property set to the plugin name, an address and this object which will link it back to the plugin.

    So at the start of the plugin I loop through the enumerator, then I get anything that matches the interface name. Then I take the named key from the PlugExtraData object to populate arrays of integers of the device references based on this object key value. Then in the plugin I just pick the device reference out of this array to set the value/string etc.
    My Plugins:

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

    Comment


    • #3
      Thanks for the tip, I only have one or two devices I want to create, so will take a look at your suggestion!

      You mentioned a unique ID, how did you end up storing that as extra info, as that sounds like a good way to do it.

      How do you handle if a device does not exist (but should), does it just loop through looking for the device and if it is not found it creates it on startup, or does it check more often?
      HS3 PRO, Win10, WeatherXML, HSTouch, Pushover, UltraGCIR, Heaps of Jon00 Plugins, Just sold and about to move so very slim system.

      Facebook | Twitter | Flickr | Google+ | Website | YouTube

      Comment


      • #4
        Originally posted by travisdh View Post
        Thanks for the tip, I only have one or two devices I want to create, so will take a look at your suggestion!

        You mentioned a unique ID, how did you end up storing that as extra info, as that sounds like a good way to do it.

        How do you handle if a device does not exist (but should), does it just loop through looking for the device and if it is not found it creates it on startup, or does it check more often?
        If you only have a handful of devices and you never saw the figure growing then you could just as easy store the reference in an INI file (if your plugin uses one already). Because the current cost plugin (for example) had a variable number of devices (anything from 5-95 devices depending) I stored extra info inside the devices to make my life easier when I try and discover devices belonging to the plugin at start up. I did not want to keep a track of 90 odd devices in an ini file.

        What I add to the PlugExtraData object is that in my case I add a sensor number and then a number between 1-10 depending on the device (0 is root device, 1 is total wattage, 2-3-4 are channel numbers and so on) to every device the plugin creates so I can look through these and find out what to update.

        In theory the address (albeit I don't have a great understanding of this address-code business) could very well be used for this purpose but I felt that I would use a format for the address to make it semi understandable and running through the address and picking bits out of it I did not really want to do.

        I don't periodically check whether the device exists or not but I check it at start-up and then when I come to update it with data.
        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