Announcement

Collapse
No announcement yet.

Sample SDK plugin help

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

    Sample SDK plugin help

    I am running into several problems with the CreateGenericBinarySensor, I am able to create devices. however,​


    1) It seems it creates 2 identical devices, both with different device refs. This my loop for door sensor create,

    public void InitializeDevices()
    {
    foreach (sDoor door in doors)

    {
    var df = DeviceFactory.CreateDevice(Id);
    df = df.WithName(Name).WithLocation(door.Name).WithLocation2(door .Type);
    var ff = FeatureFactory.CreateGenericBinarySensor(Id, $"Status", "Open", "Closed", 1, 0)
    .WithLocation(door.Name).WithLocation2(door.Type);
    df.WithFeature(ff);
    var ddf = df.PrepareForHs();
    door.DeviceRef = HomeSeerSystem.CreateDevice(ddf);
    }
    }


    2) I can't seem to figure out how to update the Status. This my loop to update the sensor status.

    UInt64 doorChanged = newPortStatus ^ portStatus;
    foreach (sDoor door in doors)
    {
    string temp = door.Name;
    var device = plugin.HomeSeerSystem.GetDeviceByRef(door.DeviceRef);
    if ((door.BitMask & doorChanged) != 0)
    {
    if ((newPortStatus & door.BitMask) != 0)
    {// door open
    door.State = STATE.OPEN;
    temp += " Open";
    speechSynthesizer.SpeakTextAsync(temp);
    device.Changes[EProperty.Value] = 1;
    device.Changes[EProperty.Status] = "Open";
    }
    else
    {// door close.
    door.State = STATE.CLOSED;
    temp += " Closed";
    door.OpenTimeSeconds = 0;
    device.Changes[EProperty.Value] = 0;
    device.Changes[EProperty.Status] = "Closed";
    }
    }
    plugin.HomeSeerSystem.UpdateDeviceByRef(door.DeviceRef, device.Changes);
    }


    3) Everytime i update the device status, it creates a new bunch.​ of devices.

    #2
    Figured out 1 and 2, i was using device reference instead of feature reference.
    This fixed it,
    var devRef = HomeSeerSystem.CreateDevice(ddf);
    HashSet<int> t = (HashSet<int>)HomeSeerSystem.GetPropertyByRef(devRef, EProperty.AssociatedDevices);
    door.DeviceRef = t.First();


    For 3, it is creating new devices every time it starts up. How do i remedy this?

    Comment


      #3
      Originally posted by iQb View Post
      Figured out 1 and 2, i was using device reference instead of feature reference.
      This fixed it,
      var devRef = HomeSeerSystem.CreateDevice(ddf);
      HashSet<int> t = (HashSet<int>)HomeSeerSystem.GetPropertyByRef(devRef, EProperty.AssociatedDevices);
      door.DeviceRef = t.First();


      For 3, it is creating new devices every time it starts up. How do i remedy this?
      When your plugin starts up, you'll need to check all of your plugin-owned devices and only create if they don't already exist.
      HS4Pro Running on a Raspberry Pi4
      67 Z-Wave Nodes, 111 Events, 422 Devices
      Z-Wave, UPB, WiFi
      Plugins: EasyTrigger, weatherXML, OMNI, Z-Wave, Tuya, Device History
      HSTouch Clients: 3 Android, 1 Joggler

      Comment


        #4
        Thanks. that worked.
        One more thing, when the sensor changes the state, the web page does not show a refreshed view. I have to manually refresh it. Is there way to force it from the plugin.

        Comment


          #5
          You can't force it from a plugin but when you update the feature value or string, the page should refresh automatically.
          HS4Pro Running on a Raspberry Pi4
          67 Z-Wave Nodes, 111 Events, 422 Devices
          Z-Wave, UPB, WiFi
          Plugins: EasyTrigger, weatherXML, OMNI, Z-Wave, Tuya, Device History
          HSTouch Clients: 3 Android, 1 Joggler

          Comment


            #6
            Originally posted by iQb View Post
            Thanks. that worked.
            One more thing, when the sensor changes the state, the web page does not show a refreshed view. I have to manually refresh it. Is there way to force it from the plugin.
            To update the feature value use UpdateFeatureValueByRef instead of UpdateDeviceByRef, https://homeseer.github.io/Plugin-SD...System_Double_

            Comment


              #7
              Yes i used the UpdateDeviceByRef.

              New question,
              How does one get all features associated with a device.

              I have a device with some sensors and controls attached to a device as features. How do i iterate over the features contained in a device.

              Comment


                #8
                Originally posted by iQb View Post
                How do i iterate over the features contained in a device.
                A set of unique IDs that represent the devices/features that are associated with this device/feature
                EProperty.AssociatedDevices (HomeSeer.PluginSdk.Devices.AbstractHsDevice.AssociatedDevic es)

                Comment


                  #9
                  Originally posted by alexbk66 View Post


                  EProperty.AssociatedDevices (HomeSeer.PluginSdk.Devices.AbstractHsDevice.AssociatedDevic es)
                  or call GetDeviceWithFeaturesByRef, which return a HsDevice with the HsDevice.Features property populated with all its features
                  https://homeseer.github.io/Plugin-SD..._System_Int32_

                  Comment

                  Working...
                  X