Announcement

Collapse
No announcement yet.

How To Create A Basic Plugin

Collapse
X
 
  • 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:
    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();
                timer.Start();
    
                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 };
                    deviceFactory.WithMiscFlags(flags);
    
                    NewDeviceData newDeviceData = deviceFactory.PrepareForHs();
    
                    deviceId = HomeSeerSystem.CreateDevice(newDeviceData);
    
                    WriteLog(ELogType.Debug, "Creating feature");
                    FeatureFactory ff = FeatureFactory.CreateFeature(Id, deviceId);
                    ff.WithName("Test Feature");
                    ff.WithDefaultValue(-1.5);
                    ff.WithMiscFlags(flags);
                    ff.AsType(EFeatureType.Generic, 0);
                    //ff.AddGraphic(new StatusGraphic("", -100, 120));
    
                    PlugExtraData extraData = new PlugExtraData();
                    extraData.AddNamed("temperature", -1.0);
                    ff.WithExtraData(extraData);
    
                    WriteLog(ELogType.Debug, "Preparing feature for HsDevice");
                    NewFeatureData newFeatureData = ff.PrepareForHsDevice(deviceId);
    
                    WriteLog(ELogType.Debug, "Created device with id: " + deviceId);
                }
                else
                {
                    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;
                }
            }​
    ​

    #2
    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

    Comment


      #3
      Or use the hello world plugin as a startand tweak to suit
      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

      Working...
      X