I have made modifications to an excellent weather driver here. However, I'm stuck just a few feet from the finish line.
In a driver, there a preference that can be saved. If it is overridden by a function in the driver itself via a command, how to update that Preference? Updating an attribute shows immediately on the device's Command page. However, I can not get any change to stick as a preference.
(ignore any extraneous commas or parenthesis. Just showing what I am trying to do and my attempt at it.)
command ("setAltCoordLat", [
[
"name": "Latitude",
"type": "STRING",
],
])
sendEvent(name: "altLatitude", value: altLat)
sendEvent(name: "altLongitude", value: altLon)
I do that in my drivers, to keep settings synced with the attributes.
When you update the setting, you also set the attribute. When you update the attribute, you also update settings.
I call a method that does both at the same time when I change the attribute:
{device.updateSetting("circulateVent",[value: false,type:"bool"]); sendEvent(name: "circVent", value: "Disabled")}
To update the attribute when the setting is changed, I do the sendEvent in the updated() method:
if (circulateVent) {sendEvent(name: "circVent", value: "Enabled")} else {sendEvent(name: "circVent", value: "Disabled")}
1 Like
I'll have to look more into the updateSetting and sendEvent functions. Thank you.
I used type:"bool" in the example, but updateSettings() can take other types like "string" or "number" for the type.
Also, in my example the types are different. Setting is a true/false bool, and my attribute is an enum using "enabled, disabled", but if you keep the types the same it is even easier, and you do not have to evaluate the setting to set the attribute, you can just make it match the value.
Understood. Steering me in the direction of the relevant methods was most important.