How to read/write values to Plugin Settings

I have a plugin with a device called Vars and have Attributes Var1 and Var2. I have a slider with the value Device Binding to {Binding Vars.Var1}. In the plugin I am only using the onChangeRequest and for now I have a single line of code to test with.

function onChangeRequest(device, attribute, value) {
   device.Var2=device.Var1;
   console.log("Var1 ="+device.Var1);
   console.log("Var2 ="+device.Var2);
}

When I move the slider the plugin gets called as the console.logs display. But for some reason the device.Var1 shows ‘null’ and then so does device.Var2 getting it’s value from Var1. I added a label and tied the text to Vars.Var1 and it just blanks out, probably due to the null value. I set Var1 and Var2 to a value inside the plugin and once the plugin was triggered they had this value. Changing the slider now still called the plugin but the Slider.value was never set to Var1 like it should.

Another way I tried was to read a variable value inside the plugin. Is there a way to do that?

Jerry

hi JerryH,
I think you should get the slider value in the “value” parameter.
Can you try and log that?

console.log(“device:” + device.DisplayName);
console.log(“attribute:” + attribute);
console.log(“value:” + value);

I believe you can set the variable like this:

App.SetDeviceAttribute(“Vars.Var1”, value);
App.SetDeviceAttribute(“Vars.Var2”, “test123”);

I took it from here: If then Conditions

BR - kro

That’s because you haven’t assigned a value to the attribute. You need to complete the change request by forwarding “value” into your device attribute.

device.Var1 = value

Thanks Chris and Bill, I understand better now. I thought in my plugin device.Var1 would contain a value I could use, like it was a variable. I added a switch statement back into the onChangeRequest function and use it to load the plugin variable with “value” being sent and it’s working now.