No announcement yet.

How To Create A Basic Plugin

  • Filter
  • Time
  • Show
Clear All
new posts

    How To Create A Basic Plugin

    I've spent hours on this can't figure out how to create a very basic plugin.
    I simply want it to display the inside temperature. This will be done by reading a text file on the server. For now I just set it to a random number.

    What am I doing wrong? So far to see the value I am setting I have to go into the device, click on features , edit 'TestDevice', click on Status/Graphics then I can see 'value' in there.
    I just want it to display the temperature on the devices page, instead I get this:

    Click image for larger version

Name:	image.png
Views:	220
Size:	5.6 KB
ID:	1584672

    Here's my code:
            protected override void Initialize()
                // timer is changing the fake temperature to random values every 30 seconds
                timer = new System.Timers.Timer(30000.0);
                timer.Elapsed += Timer_Elapsed;
                random = new Random();
                if (HomeSeerSystem.GetRefsByInterface(Id).Count == 0)
                    DeviceFactory deviceFactory = DeviceFactory.CreateDevice(Id).WithName("TestDevice");
                    // Identification.EApiType
                    deviceFactory.AsType(HomeSeer.PluginSdk.Devices.Identification.EDeviceType.Generic, 0);
                    EMiscFlag[] flags = new EMiscFlag[] { EMiscFlag.NoLog, EMiscFlag.ShowValues };
                    NewDeviceData newDeviceData = deviceFactory.PrepareForHs();
                    deviceId = HomeSeerSystem.CreateDevice(newDeviceData);
                    WriteLog(ELogType.Debug, "Creating feature");
                    FeatureFactory ff = FeatureFactory.CreateFeature(Id, deviceId);
                    ff.WithName("Test Feature");
                    ff.AsType(EFeatureType.Generic, 0);
                    //ff.AddGraphic(new StatusGraphic("", -100, 120));
                    PlugExtraData extraData = new PlugExtraData();
                    extraData.AddNamed("temperature", -1.0);
                    WriteLog(ELogType.Debug, "Preparing feature for HsDevice");
                    NewFeatureData newFeatureData = ff.PrepareForHsDevice(deviceId);
                    WriteLog(ELogType.Debug, "Created device with id: " + deviceId);
                    deviceId = HomeSeerSystem.GetRefsByInterface(Id)[0];
                    WriteLog(ELogType.Debug, "Found existing device, id: " + deviceId);
                WriteLog(ELogType.Info, "Done with initialization");
                Status = PluginStatus.Ok();
            private void Timer_Elapsed(object sender, System.Timers.ElapsedEventArgs e)
                HsFeature feature = HomeSeerSystem.GetFeatureByRef(deviceId);
                if (feature != null)
                    double randomValue = random.Next(5, 100);
                    bool result = HomeSeerSystem.UpdateFeatureValueByRef(feature.Ref, randomValue);
                    WriteLog(ELogType.Debug, $"setting value to {randomValue}, result: {result}");
                    feature.Value = randomValue;

    For something that simple, you might just want a script to run every 'x' minutes and update a virtual device.
    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


      Or use the hello world plugin as a startand tweak to suit
      HS3 Pro Edition (Windows 10 vmware)
      BLOccupied:,UltraNetCam3:,weatherXML:,RFXCOM:,Current Cost 3P:,UltraGCIR3: