2.0.2 added

  • app.updateSetting(): now creates setting if it doesn’t exist.

Please consider doing this for devices also


1 Like

What do you mean? Devices don't have settings, they have preferences and capabilities. If you declare a preference in the driver, it shows up in the edit device page.

Are you saying you want to be able to add a setting/preference to a device via an app? That's not really how it works. If it's not in the driver the device won't know what to do with it.

Sorry for the mix of terminology but device.updateSetting() changes preferences in device handlers except it throws an error if the preference doesn't currently have a value.

Yeah... Because the preference has to be defined in the driver. You can't add a setting for a device in an app. The driver has to have it defined.

I'm not trying to do it in an app, I'm trying to do it in the parse routine of the driver based on information that is coming in from my device.

I'm working on a device driver that makes web requests and one of the preferences is a filter to be sent in the request. If the web request is made without a filter then the response has a suggested filter in it. I'd like to put that value into the preference so it can be seen and changed if necessary.

So is the issue you are having that you can't update the preference setting at all....or that you can only update the preference after it has already been given a value of some kind?

If the preference has a value then updateSetting() can change it, if it doesn't have a value updateSetting() throws an error about a null value. The same thing used to happen in app code and it was fixed there but apparently not for device derives.

Tagging @chuck.schwer as he usually handles this type of request.

1 Like

Im sorry, I don't underatand. If you use update setting, it doesn't now have a setting. Also, your original request was that if the setting doesn't exist to create it. Which is not the same thing.

@Ryan780, his original post was referencing a problem that previously existed with apps (issue was fixed with a fw update) and apparently also exists with devices.

The problem is that you cannot update a device preference unless a value has already been set for the in order to dynamically change the setting, you first have to manually enter a value...after that you could edit the value using the updateSetting call. This is not ideal in many scenarios.

I read in another post that @chuck.schwer is under the weather so a response may be down the road.
In the meantime @mlciskey, can you set a default value for that preference of the driver when it is created?

Here's what I'm thinking...
I'm assuming the driver you are referring to is a custom driver and is being created by your app... therefore a childDevice. If you include a default value for the preference when it is created ("Not Set" for example), then you should be able to apply the updateSettings at will. In the web request method you could code around it to disregard if preference = "Not Set" . I haven't fully thought it out but it seems right in my head at least.

This is just a custom device driver without a custom app or parent device. For now I'm leaving the preference setting empty and putting the suggested filter result from the web response into a custom attribute and manually setting the preference later.

Why can't you set a default value?


Was this ever resolved? I am trying to modify a WAN device handler, and it requires a MAC address and an IP Address. It seems ridiculous to require a user to enter both, then the device reports back its MAC address. As such, I want to store the MAC address value in the device's settings if not already set, or if reported changed (manual override in device) during a refresh. Not all target devices will have a MAC address reported by the web API, so I still need the user to be able to override it.

Having this fixed would make life so much easier.

For now, I am pre-defining the setting so that I can set it.

@chuck.schwer any update on this request? I would also like to programmatically change an input value without having to set the value to something else first.

Welp I missed this request (multiple times apparently) I've added it to our bug tracker.

1 Like

@chuck.schwer - has this one been fixed yet?

I have an existing driver that I am adding a new user preference setting to. However, if the users simply update the driver, without going into the device and clicking save, I receive errors due to the new setting being null when the code tries to use it. I can trap the error, however I would like to force the value of that setting to a default if possible.

This is the new input...

        input "timeOut", "number", title: "Timeout in Seconds", description: "Max time w/o HubDuino update before setting device to 'not present'", defaultValue: "900", required: true, displayDuringSetup:true

and here is the snippet of code that doesn't seem to help...

        if (timeOut == null) {
            log.debug "updating timeOut value to default of 900"
            device.updateSetting("timeOut", [value: "900", type: "number"])
        log.debug "timeOut = ${timeOut}"
        runIn(timeOut, timeOutHubDuino)

and here is the error from the logs for the runIn() command

 errorjava.lang.NullPointerException: Cannot get property 'id' on null object on line 112 (parse)

Any ideas of what I am doing wrong? Or is this issue still on the list of things to be added in a future firmware release?


Yes, it is fixed in 2.1.5



Thanks Chuck!