[ST Edge] Device Preferences

@TAustin

Indeed, there’s an issue with integer ranges because they’re only supporting -999 to 999 by default, even if you define smaller references. This has been already documented and the engineers will apply the corresponding patch as soon as possible.

Some of these issues had been already documented and for others, we’re still gathering the proper information to keep track of them properly.

2 Likes

Modification of the “edge Driver st Multiporpuse Sensor” to add in the preferences the custom configuration settings for Temperature Reports:

-There are two preference settings:

UPDATE
To prevent the limit of integer preferences, -999 to 999 had changed the maximum interval to minutes instead of seconds.

I have increased the rabgo of the 2 preferences

  • maxTime”: Maximum interval of the temperature report, between (5 sec and 240min)
  • changeRep”: Reportable temperature change, between 10 (0.1º) and 600 (6º)
    categories:
      - name: MultiFunctionalSensor
preferences:
  - preferenceId: tempOffset
    explicit: true
  - name: "maxTime"
    title: "Temp Rep Max Interval(5..240 min)"
    required: false
    preferenceType: integer
    definition:
      minimum: 5
      maximum: 240
      default: 5   
  - name: "changeRep"
    title: "Rep Temp Change 0.1 to 6(10..600)"
    required: false
    preferenceType: integer
    definition:
      minimum: 10
      maximum: 600
      default: 10    
  - name: "garageSensor"
    title: "Use on garage door"
    required: false
    preferenceType: enumeration
    definition:
      options:
        "Yes" : "Yes"
        "No"  : "No"
      default: "No"

When installed it is configured with the default values (30, 300, 10) in samjin subdriver

local function do_configure(self,device)
  print ("subdriver do_configure")
  local maxTime = device.preferences.maxTime * 60
  local changeRep = device.preferences.changeRep
  print ("maxTime y changeRep: ",maxTime, changeRep )
    device:send(device_management.build_bind_request(device, tempMeasurement.ID, self.environment_info.hub_zigbee_eui))
    device:send(tempMeasurement.attributes.MeasuredValue:configure_reporting(device, 30, maxTime, changeRep))
    device:configure()
end

When a setting is changed or the drivers are changed by other in the app, the lifecycle handler “infoChanged” will be executed, which has been assigned a function that reconfigures the reports on the device.

-- preferences update
local function do_preferences(self, device)
    local maxTime = device.preferences.maxTime * 60
    local changeRep = device.preferences.changeRep
    print ("maxTime y changeRep: ", maxTime, changeRep)
      device:send(device_management.build_bind_request(device, tempMeasurement.ID, self.environment_info.hub_zigbee_eui))
      device:send(tempMeasurement.attributes.MeasuredValue:configure_reporting(device, 30, maxTime, changeRep))
      device:configure()
  end

  local zigbee_multipurpose_driver_template = {
    supported_capabilities = {
        capabilities.contactSensor,
        capabilities.battery,
        capabilities.threeAxis,
        capabilities.accelerationSensor,
        capabilities.refresh
    },
    zigbee_handlers = handlers,
    lifecycle_handlers = {
        added = added,
        infoChanged = do_preferences
    },
    ias_zone_configuration_method = constants.IAS_ZONE_CONFIGURE_TYPE.AUTO_ENROLL_RESPONSE,
    sub_drivers = { require("smartthings"), require("samjin") }
}

--Run driver
defaults.register_for_default_handlers(zigbee_multipurpose_driver_template, zigbee_multipurpose_driver_template.supported_capabilities)
local zigbee_multipurpose = ZigbeeDriver("smartthingsMultipurposeSensor", zigbee_multipurpose_driver_template)
zigbee_multipurpose:run()

The title of the preference is limited to 36 characters and the explanatory text in the app settings is not very clear.

With the code that @nayelyz created to modify the default configuration during the installation of the device, has been able to modify the driver to change the configuration of the reports through the preferences in a zigbee device, just as it can be done in the zwave devices.
It’s a big step Thank you @nayelyz !!!

It is working well
I will update you if there is any change or malfunction.
Thanks again

1 Like

Great job, @Mariano_Colmenarejo. Thank you for sharing your solution. In this case, I noticed only one issue pending to report:

Is this correct?

Yeah that’s right.
When performing the package driver it gave the error because the preference title was greater than 36 characters and must be between 3 and 36 according to the log

PS C:\Users\Mariano\smartthings> .\smartthings edge:drivers:package C:\Users\Mariano\Documents\Mariano\VSC\SampleDrivers\st-multipurpose-sensor-pref
(node:8768) UnhandledPromiseRejectionWarning: Error: Request failed with status code 422: {"requestId":"EF72B156-2D5A-4E61-86A4-A3EB25E6CEB0","error":{"code":"ConstraintViolationError","message":"Invalid device profile specification for st-multipurpose","details":[{"code":"SizeError","target":"title","message":"title must have a length between 3 and 36.","details":[]}]}}
    at createError (C:\snapshot\smartthings-cli\node_modules\axios\lib\core\createError.js:16:15)
    at settle (C:\snapshot\smartthings-cli\node_modules\axios\lib\core\settle.js:17:12)
    at IncomingMessage.handleStreamEnd (C:\snapshot\smartthings-cli\node_modules\axios\lib\adapters\http.js:260:11)
    at IncomingMessage.emit (events.js:327:22)
    at IncomingMessage.EventEmitter.emit (domain.js:482:12)
    at endReadableNT (_stream_readable.js:1221:12)
    at processTicksAndRejections (internal/process/task_queues.js:84:21)
(node:8768) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). To terminate the node process on unhandled promise rejection, use the CLI flag `--unhandled-rejections=strict` (see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 2)
(node:8768) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will

@nayelyz,

I have installed two multipurpose sensors on the same driver with different temperature report setting preferences for each sensor and it works fine. Each sensor sends the reports according to the selected preferences.
I had to test it to see if it worked well, since the preferences must be in a table linked to the device.
A single driver with different preferences for each device is fine.

@nayelyz,

The preferences title also does not support the degree character " º ".
It is not that it is very important, but if can add this character to the filter pattern.

Can’t write this:

  title: "Rep Temp Change 0.1º to 6º(10..600)"
PS C:\Users\Mariano\smartthings> .\smartthings edge:drivers:package C:\Users\Mariano\Documents\Mariano\VSC\SampleDrivers\st-multipurpose-sensor-pref
(node:20012) UnhandledPromiseRejectionWarning: Error: Request failed with status code 422: {"requestId":"6130DA66-6DBC-4C0A-9E31-C64CEB61D321","error":{"code":"ConstraintViolationError","message":"Invalid device profile specification for st-multipurpose","details":[{"code":"PatternError","target":"title","message":"title does not match the pattern ^[A-Za-z][\\w()\\\\/.?,~!@#$%^\\&*()_+ ]+$.","details":[]}]}}
 

Have you tried treating it like you would in HTML? So something like ° or °?

does not admit it.
It interprets it as individual characters not as html, as have done here by using “quote”

It also does not support <> =… I think all character that are not in the list.
Unless there is another way to introduce these characters in a string

This can be done with the description property of the preference, it accepts more characters and also the special ones. Eg.

  - name: "testInput"
    title: "testInput"
    description: "test input to see how many characters it accepts ºº!#%$ xxxxx xxxxxxx xxxxxxx xxxxxx x xxxxx xxx xxx xxx"
    required: false
    preferenceType: string
    definition:
        stringType: "text"

1 Like

I added the description field and changed the texts like this:

  - name: "maxTime"
    title: "Temperature Report Configure"
    description: "Select Temp. Report Max. Interval (5 min to 240 min)"
    required: false
    preferenceType: integer
    definition:
      minimum: 5
      maximum: 240
      default: 5   
  - name: "changeRep"
    title: "Temperature Report Configure"
    description: "Select Temp. Reportable Change 0.1º to 6º (10 to 600)"
    required: false
    preferenceType: integer
    definition:
      minimum: 10
      maximum: 600
      default: 10    

In the App the description field is not shown and if you delete the title field it gives an error when making the package because it is mandatory

It’s possible that your configuration is not refreshed yet. Did you package, published and installed the driver again in your Hub?

Remember that you can use this single command for those steps (this is available in the last version of the CLI):

smartthings edge:drivers:package .\multihello-w\ --channel <channelId> --hub <hubId>

@nayelyz,
Yes, it was installed since the new text that I put in the title appears:

Ohh, got it, it’s because I didn’t include a default value but it was only a reference. The description appears when you click to edit the preference.
Update: I removed the default value and the device was discovered correctly

@nayelyz
I tried it and it comes out like this when you open the setting


Thanks

Is it possible to dynamically update preference values from the driver or are they strictly, one-way?

1 Like

Looks like one thing got fixed today: Fields in Settings now appear in the right order!

Thank-you SmartThings, but now please fix the more insidious behavior of missing or multiple lifecycle calls to the driver with the wrong data!

The engineering team is already working on that but they detected certain issues with the preferences that are not impacting only the Edge drivers. We’ll let you know once we find out more.

2 Likes

@nayelyz,

Remember to correct the limit of number +/- and 999.9 and +/- 999 for integer preferences.

For example, you cannot choose a custom color temperature value in preferences.
You have to put the input in xxx.x format and multiply x 10 in the code.

Is there anything else required to get device preferences to display in the device’s menu? I have this but the setting are not available in the UI. I am just trying to add a simple string value

# hello-world-profile
name: hello-world.v1
components:
- id: main
  capabilities:
  - id: refresh
    version: 1
  preferences:
  - title: "Local Token"
    name: token
    description: "Local Token from the Bond app settings"
    required: true
    preferenceType: string
    definition:
      stringType: text
      minLength: 16 
      maxLength: 16
metadata:
  deviceType: Bridge
  ocfDeviceType: oic.d.bridge
  deviceTypeId: Bridge

If it is any sort of clue, my capabilities are not being shown either. I tried a simple refresh.