Error sending setColor commands with variable duration in libraries 46.x

Hi @nayelyz

When I manually handle the function capability_handlers.set_color() in a driver copied from the colorControl default 46.x libraries, an error occurs, but when running the defaults directly in libraries error does not appears.

--- Issue an RGB color set command to the specified device.
--- @param driver st.zwave.Driver
--- @param device st.zwave.Device
--- @param command table ST color control capability command
function capability_handlers.set_color(driver, device, command)
  local duration = constants.DEFAULT_DIMMING_DURATION
  local r, g, b = utils.hsl_to_rgb(command.args.color.hue, command.args.color.saturation)
  device:set_field(CAP_CACHE_KEY, command)
  local set = SwitchColor:Set({
    color_components = {
      { color_component_id=SwitchColor.color_component_id.RED, value=r },
      { color_component_id=SwitchColor.color_component_id.GREEN, value=g },
      { color_component_id=SwitchColor.color_component_id.BLUE, value=b },
      { color_component_id=SwitchColor.color_component_id.WARM_WHITE, value=0 },
      { color_component_id=SwitchColor.color_component_id.COLD_WHITE, value=0 },
  device:send_to_component(set, command.component)
  local query_color = function()
    -- Use a single RGB color key to trigger our callback to emit a color
    -- control capability update.
      SwitchColor:Get({ color_component_id=SwitchColor.color_component_id.RED }),
  device.thread:call_with_delay(constants.MIN_DIMMING_GET_STATUS_DELAY, query_color)
2023-02-27T09:33:15.757524306+00:00 TRACE Z-Wave Bulb Mc  Received event with handler capability
2023-02-27T09:33:15.758505306+00:00 INFO Z-Wave Bulb Mc  <ZwaveDevice: e78f6785-37e1-48bd-a197-ecf8dbc13260 [27] (Dimmer Switch)> received command: {"args":{"color":{"hue":69.19,"saturation":91.11296187999636}},"capability":"colorControl","command":"setColor","component":"main","positional_args":[{"hue":69.19,"saturation":91.11296187999636}]}
2023-02-27T09:33:15.760355306+00:00 TRACE Z-Wave Bulb Mc  Found CapabilityCommandDispatcher handler in zwave_bulb -> Fibaro RGBW Controller
2023-02-27T09:33:15.761485639+00:00 PRINT Z-Wave Bulb Mc  <<<<<< duration       default
2023-02-27T09:33:15.762602306+00:00 ERROR Z-Wave Bulb Mc  Dimmer Switch thread encountered error: [string "st/dispatcher.lua"]:233: Error encountered while processing event for <ZwaveDevice: e78f6785-37e1-48bd-a197-ecf8dbc13260 [27] (Dimmer Switch)>:
    arg1: table: 0x1a036c0
[string "st/dispatcher.lua"]:233: Error encountered while processing event for <ZwaveDevice: e78f6785-37e1-48bd-a197-ecf8dbc13260 [27] (Dimmer Switch)>:
    arg1: table: 0x1a036c0
[string "st/zwave/init.lua"]:340: unrecognized argument 'duration'

I don’t understand why it says that it unrecognize the “duration” argument, am I doing something wrong or is there an error in the 46.x libraries?

Hi, @Mariano_Colmenarejo
Let me check with the engineering team, I saw that message comes from this function where it’s validated that the table passed has no extra arguments. It should get the table and a template but I’m not sure where that comes from in the case of the defaults, so, I will ask about that.

1 Like

Following up, @Mariano_Colmenarejo, the team mentioned it could be due to the Command Class version you’re using because the V1 of SwitchColor doesn’t have the field duration, only V2 and V3 do.
Which one are you using?

Thanks @nayelyz

Yes this driver use v1, is a old device.
Sorry, I should have noticed that when I saw that the defaults use v3 and that’s why it worked fine :man_facepalming:

No problem, @Mariano_Colmenarejo
Let us know if you need help with something else :smiley: