How to detect a ZWave device ON button being pressed, when the device is already ON?

I have a Leviton DZ15S ZWave switch. It’s connected to a bathroom fan. The switch is a toggle, up for ON and down for OFF. When I press the ON button I want to run the fan for 10 minutes, if i press the ON button again I want to add another 10 mins to the run time. If I press it a third time I want the fan to stay on (i.e. no timer).

I believe I need to do this by capturing an Event. The issue is that no ZWave events appear to be firing. When I listen to zwave_js_notification or zwave_js_value_notification in the Event watcher tool I get nothing for any of my ZWave devices. If I listen to * I can see the state change when the switch changes from OFF to ON or ON to OFF but I can’t see anything when the ON button is pressed and the switch is already ON. When I watch this happen in the ZWave log I can see activity every time I press the ON button.

Any help on finding out what Event I should be listening for would be helpful. Or any other proposed solution. Thanks!

What does the log show?

This is the log when the device is OFF and I press the ON button:
Subscribed to Z-Wave JS Log Messages…
Log Level changed to: Silly
2022-06-14T23:09:40.518Z SERIAL « 0x010a00040010028201cf00af (12 bytes)
2022-06-14T23:09:40.532Z SERIAL » [ACK] (0x06)
2022-06-14T23:09:40.539Z DRIVER « [Node 016] [REQ] [ApplicationCommand]
└─[HailCC]
2022-06-14T23:09:40.547Z CNTRLR [Node 016] Hail received from node, refreshing actuator and sensor values…
2022-06-14T23:09:40.554Z CNTRLR » [Node 016] querying Binary Switch state…
2022-06-14T23:09:40.605Z SERIAL » 0x0109001310022502250ffa (11 bytes)
2022-06-14T23:09:40.609Z DRIVER » [Node 016] [REQ] [SendData]
│ transmit options: 0x25
│ callback id: 15
└─[BinarySwitchCCGet]
2022-06-14T23:09:40.615Z SERIAL « [ACK] (0x06)
2022-06-14T23:09:40.619Z SERIAL « 0x0104011301e8 (6 bytes)
2022-06-14T23:09:40.622Z SERIAL » [ACK] (0x06)
2022-06-14T23:09:40.625Z DRIVER « [RES] [SendData]
was sent: true
2022-06-14T23:09:40.948Z SERIAL « 0x011800130f00002103cfcab0b97f01010306080b0001010000ac (26 bytes)
2022-06-14T23:09:40.952Z SERIAL » [ACK] (0x06)
2022-06-14T23:09:40.958Z DRIVER « [REQ] [SendData]
callback id: 15
transmit status: OK, took 330 ms
repeater node IDs: 6, 8, 11
routing attempts: 1
protocol & route speed: Z-Wave, 9.6 kbit/s
ACK RSSI: -49 dBm
ACK RSSI on repeaters: -54 dBm, -80 dBm, -71 dBm
ACK channel no.: 1
TX channel no.: 1
2022-06-14T23:09:41.131Z SERIAL « 0x010b00040010032503ffcf00f5 (13 bytes)
2022-06-14T23:09:41.142Z CNTRLR [Node 016] [~] [Binary Switch] currentValue: false => true [Endpoint 0]
2022-06-14T23:09:41.148Z SERIAL » [ACK] (0x06)
2022-06-14T23:09:41.155Z DRIVER « [Node 016] [REQ] [ApplicationCommand]
└─[BinarySwitchCCReport]
current value: true
2022-06-14T23:09:41.164Z CNTRLR « [Node 016] received Binary Switch state:
current value: true

This is the log when the device is already ON and I press the ON button again:
Subscribed to Z-Wave JS Log Messages…
2022-06-14T23:10:33.595Z SERIAL « 0x010a00040010028201cf00af (12 bytes)
2022-06-14T23:10:33.602Z SERIAL » [ACK] (0x06)
2022-06-14T23:10:33.607Z DRIVER « [Node 016] [REQ] [ApplicationCommand]
└─[HailCC]
2022-06-14T23:10:33.613Z CNTRLR [Node 016] Hail received from node, refreshing actuator and sensor values…
2022-06-14T23:10:33.618Z CNTRLR » [Node 016] querying Binary Switch state…
2022-06-14T23:10:33.633Z SERIAL » 0x01090013100225022510e5 (11 bytes)
2022-06-14T23:10:33.635Z DRIVER » [Node 016] [REQ] [SendData]
│ transmit options: 0x25
│ callback id: 16
└─[BinarySwitchCCGet]
2022-06-14T23:10:33.643Z SERIAL « [ACK] (0x06)
2022-06-14T23:10:33.647Z SERIAL « 0x0104011301e8 (6 bytes)
2022-06-14T23:10:33.649Z SERIAL » [ACK] (0x06)
2022-06-14T23:10:33.651Z DRIVER « [RES] [SendData]
was sent: true
2022-06-14T23:10:34.311Z SERIAL « 0x011800131000004303cfcaaeb97f01010306080b0001010000cf (26 bytes)
2022-06-14T23:10:34.316Z SERIAL » [ACK] (0x06)
2022-06-14T23:10:34.321Z DRIVER « [REQ] [SendData]
callback id: 16
transmit status: OK, took 670 ms
repeater node IDs: 6, 8, 11
routing attempts: 1
protocol & route speed: Z-Wave, 9.6 kbit/s
ACK RSSI: -49 dBm
ACK RSSI on repeaters: -54 dBm, -82 dBm, -71 dBm
ACK channel no.: 1
TX channel no.: 1
2022-06-14T23:10:34.733Z SERIAL « 0x010b00040010032503ffcf00f5 (13 bytes)
2022-06-14T23:10:34.739Z CNTRLR [Node 016] [~] [Binary Switch] currentValue: true => true [Endpoint 0]
2022-06-14T23:10:34.745Z SERIAL » [ACK] (0x06)
2022-06-14T23:10:34.748Z DRIVER « [Node 016] [REQ] [ApplicationCommand]
└─[BinarySwitchCCReport]
current value: true
2022-06-14T23:10:34.756Z CNTRLR « [Node 016] received Binary Switch state:
current value: true

This is the Listen to Events tool when I subscribe to “*”:
Event 0 fired 5:11 PM:

{
“event_type”: “state_changed”,
“data”: {
“entity_id”: “switch.scene_capable_switch_on_off_4”,
“old_state”: {
“entity_id”: “switch.scene_capable_switch_on_off_4”,
“state”: “off”,
“attributes”: {
“friendly_name”: “PowderRoomFan”
},
“last_changed”: “2022-06-14T23:11:27.846853+00:00”,
“last_updated”: “2022-06-14T23:11:27.846853+00:00”,
“context”: {
“id”: “01G5J7RY36AN4ZHE8DXD6RRXXV”,
“parent_id”: null,
“user_id”: null
}
},
“new_state”: {
“entity_id”: “switch.scene_capable_switch_on_off_4”,
“state”: “on”,
“attributes”: {
“friendly_name”: “PowderRoomFan”
},
“last_changed”: “2022-06-14T23:11:39.551190+00:00”,
“last_updated”: “2022-06-14T23:11:39.551190+00:00”,
“context”: {
“id”: “01G5J7S9GZGEHCZ8MN9G26H2X8”,
“parent_id”: null,
“user_id”: null
}
}
},
“origin”: “LOCAL”,
“time_fired”: “2022-06-14T23:11:39.551190+00:00”,
“context”: {
“id”: “01G5J7S9GZGEHCZ8MN9G26H2X8”,
“parent_id”: null,
“user_id”: null
}
}

You can use the zwave_js.value_updated event, which allows you to trigger on any value notification the Z-Wave JS driver reports and isn’t suppressed for unchanged values.

Probably the easiest way is to use a Device automation via the Automation UI. Go to the Device page, click the + button in the Automations card, click “Show N more…” in the " Do something when…" section, click “Value change on a Z-Wave JS Value”.

In the Trigger section, a Device trigger will be partially pre-filled, with the selected Device and the Trigger. Choose “Binary Switch” for the command_class and “currentValue” for the property. Pick “from” or “to” depending on your use case. Those values should either be “true” or “false”.

The trigger should highlight whenever you press a button.

If you’re not using the automation UI, you can just create something based on the example in the docs.

The hardest part of all this is probably detecting 1, 2 or 3 button presses.

1 Like

Perfect! Thank you so much!

This is exactly what I was looking for, thanks! Here’s how the YAML snippet reads for the “on while on” and “off while off” for my device.

alias: Log onon/offoff Switch Presses
description: "Does basically nothing but trigger during events; customized as you see fit"
trigger:
  - id: onwhileon
    platform: device
    device_id: 2fa870cfb7c387ba8d751a72bc77d532
    domain: zwave_js
    type: zwave_js.value_updated.value
    command_class: 37
    property: currentValue
    from: "true"
    to: "true"
  - id: offwhileoff
    platform: device
    device_id: 2fa870cfb7c387ba8d751a72bc77d532
    domain: zwave_js
    type: zwave_js.value_updated.value
    command_class: 37
    property: currentValue
    from: "false"
    to: "false"
condition: []
action:
  - stop: ""
mode: single

This is awesome, any chance it can be adapted to a Dimmer? I have tried, but no luck. Dimmers don’t have BinarySwitch, but MultiLevel Switch.

You just switch the command_class to 38 and use 0-99 for from/to. Downloading the device diagnostic shows you all possible values.