Identical code not executing same in different functions

Hello,

I am modifying the published Z-Wave Metering Dimmer DTH so that it can modify device parameters to change/control the actual behavior of the physical device. I have created a custom function called setParam(int, int, int) to perform this task using the zwave.configurationV1.configurationSet command. However, I can never get the actual parameters on the dimmers to change when using the setParam function.

def setParam(paramID, paramVal, paramSize) {
log.debug “setParameter(int, int, int): Setting parameters(paramID=$paramID, paramVal=$paramVal, paramSize=$paramSize)”
//delayBetween([
// zwave.configurationV1.configurationSet(parameterNumber: paramID, size:1, scaledConfigurationValue: paramVal.toInteger()).format(),
// zwave.configurationV1.configurationGet().format(),
//], 1000)
delayBetween([
zwave.configurationV1.configurationSet(parameterNumber: 125, size: 1, scaledConfigurationValue: rampRate.toInteger()).format(),
zwave.configurationV1.configurationSet(parameterNumber: 131, size: 1, scaledConfigurationValue: minBrightness.toInteger()).format(),
zwave.configurationV1.configurationSet(parameterNumber: 132, size: 1, scaledConfigurationValue: maxBrightness.toInteger()).format(),
zwave.configurationV1.configurationGet().format(),
], 1000)
log.debug “done”
}

However, when I take the exact same configurationSet commands and put them into a different function called strobe(), the expected behavior is applied to the physical dimmer successfully.

def strobe()
{ log.debug "$rampRate, $minBrightness, $maxBrightness"
delayBetween([
zwave.configurationV1.configurationSet(parameterNumber: 125, size: 1, scaledConfigurationValue: rampRate.toInteger()).format(),
zwave.configurationV1.configurationSet(parameterNumber: 131, size: 1, scaledConfigurationValue: minBrightness.toInteger()).format(),
zwave.configurationV1.configurationSet(parameterNumber: 132, size: 1, scaledConfigurationValue: maxBrightness.toInteger()).format(),
zwave.configurationV1.configurationGet().format(),
], 1000)
//setParameter(125, rampRate, 1)
//setParameter(131, minBrightness, 1)
//setParam(132, maxBrightness, 1)
}

Eventually, I need to uncomment the code in the setParams function so I can set multiple parameters using this function, but I cant seem to identify why the exact same code functions differently in two different functions.

When you try setParam(), does it successfully print to the log both times? (Just to make sure it’s even making it into the function and down to the bottom of it…)

Try surrounding your code with a try/catch:

try {
     //code
     }
catch (e) {
     log.error "Problem: $e"
     }

I don’t see any issues with the setParams() function being called, or having issues executing. All of the log.debug commands execute without throwing runtime exceptions in the Live Logging screen. Even after adding a try-catch statement around the delayBetween command, no exception was caught.

The configurationSet commands appear to be correct, but they are still not changing the behavior of the device when sent using the setParam function. However, those same configurationSet commands execute perfectly and change the devide behavior when executed in the strobe function.

That is truly bizarre. So as I understand it, when you run setParam() everything seems to happen as it should, except that the calls to configurationSet() do not actually affect the device.

Some thoughts:

  1. Are you calling setParam() from a SmartApp, or from within the device handler? If calling it externally, did you properly declare the custom command setParam() at the top of the device handler?
  2. In rare cases, you might run into something that simply does not make sense, possibly because of some weird name conflict with the API functions. In that case, try changing the name of setParam() to something else and see if it works. strobe() is a function that is likely defined by the device capability, so that is probably why that name works. Try a different custom command name.

It is actually the reverse - calling the strobe() function works as expected, but calling the setParams() functions does not change behavior of the physical device even though it completes successfully, without errors or exceptions.

I am calling both functions from the device handler. Yes, I have a “command strobe” and “command setParam” lines defined in the definition closure:

    command "strobe"
    command "setParam", ["number", "number", "number"]     

I have considered the setParam function is not working because of a reserved name or function, so I have tried changing the name to setParameter. However, that did not make the function perform better. Additionally, if the function name was reserved, I would expect none of the code in my function to execute, but it clearly does.

I have not tried changing the name of strobe, but will try that and report back.

I have also found things in a device handler I wrote. One bit of code that has an if statement works fine in a regular function, but in the parse function it doesn’t evaluate the if statement and just gives null. So very weird!

Changing the name of the strobe() function to stobe2(), and updating all associated commands, does not change the behavior of the function. stobe() works as expected, and renaming it to strobe2() continues to work as expected. So it does not look like the issue is related to function calls or reserved function names.