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:
Here's my code:
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:
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; } }
Comment