ZwaveJS Start Level Change command

Is it possible to use the service: zwave_js.set_value to send the command startLevelChange and stopLevelChange to a z wave node?

I am trying to dim a dimmer and i want to start a transition on button press and stop when button is released to get smooth dimming but i must be missing something obvious.

Calling light on service with step 0 after transition started only sets the light to full or 0 dim.

I manage to call the service with this parameters but it only sets the current level and i cant figure out how to send startLevelChange and stopLevelChange

service: zwave_js.set_value
data:
  command_class: "38"
  endpoint: 0
  property: targetValue
  value: 10

Level Change values are documented here, but it’s not easy to understand. You should download the device diagnostic file for your device and see which values are exposed. For example, I have:

Level Values
        "2-38-0-Up": {
          "endpoint": 0,
          "commandClass": 38,
          "commandClassName": "Multilevel Switch",
          "property": "Up",
          "propertyName": "Up",
          "ccVersion": 2,
          "metadata": {
            "type": "boolean",
            "readable": false,
            "writeable": true,
            "label": "Perform a level change (Up)",
            "ccSpecific": {
              "switchType": 2
            },
            "valueChangeOptions": [
              "transitionDuration"
            ],
            "states": {
              "true": "Start",
              "false": "Stop"
            },
            "stateful": true,
            "secret": false
          }
        },
        "2-38-0-Down": {
          "endpoint": 0,
          "commandClass": 38,
          "commandClassName": "Multilevel Switch",
          "property": "Down",
          "propertyName": "Down",
          "ccVersion": 2,
          "metadata": {
            "type": "boolean",
            "readable": false,
            "writeable": true,
            "label": "Perform a level change (Down)",
            "ccSpecific": {
              "switchType": 2
            },
            "valueChangeOptions": [
              "transitionDuration"
            ],
            "states": {
              "true": "Start",
              "false": "Stop"
            },
            "stateful": true,
            "secret": false
          }
        },

For my device, there are two values, 2-38-0-Up and 2-38-0-Down for either direction of a level change. The property fields are Up/Down, but these could also be Off/On, Close/Open, etc depending on the device. However, the driver accepts any of these despite the names. So it should be safe to just use “Up” and “Down” for property if you want. To start and stop level changes you use boolean values true and false.

service: zwave_js.set_value
data:
  command_class: "38"
  endpoint: 0
  property: Up  # or Down for other direction
  value: true  # or false to stop

If you need more control over the options for startLevelChange, then you’ll need to use service zwave_js.invoke_cc_api instead, with startLevelChange API. The only option available for the value API is duration.

2 Likes

First thanks for your answer your first example works like a charm.
Now i am however struggling with zwave_js.invoke_cc_api since i also wanted to test the duration parameter.

I have tried many different calls with different parameters and data types. Reading the docs the correct call should be 4 parameters if i understand correctly but everything i test only yields error message Z-Wave error ZWaveError: options is not a MultilevelSwitchCCStartLevelChangeOptions (ZW0322)
I assume after reading that MultilevelSwitchCCStartLevelChangeOptions has 4 parameters (direction, ignoreStartLevel, startLevel, and optionally duration) but i might understand this wrong?

Example which in my mind should work. Any idea what i am doing wrong?

service: zwave_js.invoke_cc_api
data:
  command_class: "38"
  method_name: startLevelChange
  parameters:
    - 0 # enum Down=1 Up = 0
    - false #, ignoreStartLevel bool, 
    - 100 #startLevel number
    - "10" #duration string
target:
  device_id: XXX

A few problems with your code:

  1. The parameter is a single Javascript object (dict in YAML) argument
  2. direction is one of the strings “up” or “down”, the other options are not allowed here
  3. Valid Levels in Z-Wave are 0-99

You can see here in the driver code how the previous set value is translated to the CC API.

service: zwave_js.invoke_cc_api
data:
  command_class: "38"
  method_name: startLevelChange
  parameters:
    - direction: "down" # or "up"
      ignoreStartLevel: false
      startLevel: 99 # number 0-99
      duration: "10" # can also be "10 seconds"
target:
  device_id: XXX

If you don’t need the start level, then you can still use the set value api, passing in the duration as an option (yes, the duration names are slightly different, because value options are somewhat generic).

service: zwave_js.set_value
data:
  command_class: "38"
  endpoint: 0
  property: Down  # or Up
  value: true  # or false to stop
  options:
    transitionDuration: 10 seconds
target:
  device_id: XXX

If you get an error about transitionDuration not existing, re-interview the device. My device did not have this attribute, it was added in a later driver version and re-interviewing picks it up.

1 Like

Thank you very much for a very informative and helpful answer freshcoast.

1 Like

If you want to do a “hold down to dim” effect you can also use call light.turn_on with brightness_step_pct in a loop.

E.g., trigger on the hold down, then repeat while not stop button event and call light.turn_on with brightness_step_pct 10 or -10 followed by a delay of 0.5s or so. This also allows you to dim a whole set of lights together.
-David

Thanks David! I tried that as my first attempt but i did not get the smoothness i wanted. To short time with small step and i got to many messages in the network. Perhaps i did some mistake?

I find it strange that this should be so tricky since its built in functionality in almost all dumb dimmers you buy. However thanks to the responses here its now working as expected!