Automation using event_id for Z-Wave value notification event

I have a Z-Wave switch with scenes. I want an automation that triggers on a double key press. I can do this with device_id’s, but I’m trying to purge all these from my system and use event_id’s instead. Here is the log when I double tap the switch:

MW Backlight fired Central Scene CC 'value notification' event for 'Scene 002': 'KeyPressed2x'

12:30:06 PM - 33 minutes ago

MW Backlight Scene 002 detected an event

Here is the automation that I have tried that doesn’t work:

- id: '1732305613538'
  alias: Manual Goodnight
  description: ''
  trigger:
    - platform: 
      event_type: value_notification
      event_data:
        property_key: "Scene 002"  # Click up
        value: "KeyPressed2x"
        entity_id: event.media_wall_backlight_scene_002
  action:
    - action: light.turn_off
      entity_id: light.couch

And here is the one that does work:

- id: '1732305613538'
  alias: Manual Goodnight
  description: ''
  triggers:
  - device_id: 7b4757ab126c9589273dcdedaf74b28f
    domain: zwave_js
    type: event.value_notification.central_scene
    property: scene
    property_key: '002'
    endpoint: 0
    command_class: 91
    subtype: Endpoint 0 Scene 002
    trigger: device
    value: 3
  conditions: []
  actions:
  - action: script.goodnight
    metadata: {}
    data: {}
  mode: single

Any tips on how I can get this to work without using device_id’s?

There’s no such event named value_notification provided by the Z-Wave integration. It looks like you are attempting to use zwave_js_value_notification, so I guess that’s your first mistake. https://www.home-assistant.io/integrations/zwave_js/#scene-events-value-notification

Second, that event does not support an entity_id field in event_data, instead it does support device_id so you can just replace that. If you want to dynamically lookup device ID based on an entity ID instead, you can use the device_id helper template.

  trigger:
    - platform: 
      event_type: zwave_js_value_notification
      event_data:
        property_key: "Scene 002"  # Click up
        value: "KeyPressed2x"
        device_id: "{{ device_id('event.media_wall_backlight_scene_002') }}"

You can also use the event.media_wall_backlight_scene_002 with a state trigger instead. It’s a little more complicated to do so than an event IMO, but might be easier for others. An example is provided in the Event integration docs.

I can do this easily enough using device_id (and did you mean to change entity_id to device_id in the correction?). But I read that using entity id’s was better, so I was trying to get away from them.

The code I provided is using an entity by dynamically looking up the device id. The event doesn’t provide entity_id in the event data, only device_id or node_id, so it would be impossible to match on entity.

Whoops, yes I did, sorry about that. Fixed it.

Well, I guess I’ll just use the solution that uses device_id. If it helps, there’s what the device state that I want to key off of looks like:


[event.media_wall_backlight_scene_002](http://homeassistant.local:8123/developer-tools/state#)

MW Backlight Scene 002 2024-12-07T21:30:31.821+00:00 event_types: KeyHeldDown, KeyPressed, KeyPressed2x, KeyPressed3x, KeyReleased event_type: KeyPressed2x value: 3 friendly_name: MW Backlight Scene 002

And here’s what the log entry looks like when it fires:

MW Backlight fired Central Scene CC 'value notification' event for 'Scene 002': 'KeyPressed2x'

2:30:31 PM - 14 minutes ago

MW Backlight Scene 002 detected an event

2:30:31 PM - 14 minutes ago

So, if I have to use device_id, I will, it just looked like there should be a way have the trigger fire on the event directly.

I don’t think I understand your concern. The YAML I posted, modified from your original, is triggering directly from the event. Then the device_id template helper is converting the entity ID into a device ID which matches the event data. You don’t use the device ID directly.

This one is the Event entity I described above, it’s not a Device. If you want to use that, follow the example in the docs:

I’m sure I’m missing something obvious, but when I use:

- id: '1733520810997'
  alias: Man GdNight with DeviceId
  description: ''
  trigger:
  - platform: 
    event_type: zwave_js_value_notification
    event_data:
      property_key: "Scene 002"  # Click up
      value: "KeyPressed2x"
      device_id: "{{ device_id('event.media_wall_backlight_scene_002') }}"  
      actions:
      - action: light.turn_on
        metadata: {}
        data: {}
        target:
          entity_id: light.fireplace
  mode: single

I get the error:

Automation is unavailable

Triggers: expected str for dictionary value @ data[0]['platform']

Just a mistake when I copied your automation.

https://www.home-assistant.io/integrations/zwave_js/#node-events-notification

Use - trigger: event, not - platform:.

Also I don’t think your actions block is supposed to be there.

Still no joy, here’s the updated yaml (which at least “compiles”):

- id: '1733520810997'
  alias: Man GdNight with DeviceId
  # event.media_wall_backlight_scene_002
  description: ''
  triggers:
    - trigger: event
      event_type: zwave_js_value_notification
      event_data:
        property_key: "Scene 002"  # Click up
        value: "KeyPressed2x"
        device_id: "{{ device_id('event.media_wall_backlight_scene_002') }}"  
  actions:
    - action: light.turn_on
      metadata: {}
      data: {}
      target:
        entity_id: light.fireplace
  mode: single

And from the log:

MW Backlight fired Central Scene CC 'value notification' event for 'Scene 002': 'KeyPressed2x'
10:50:00 AM - In 1 second
MW Backlight Scene 002 detected an event`

I also tried entering the device_id directly, but that also didn’t work.

Sigh

Are you sure property_key: "Scene 002" is correct?

I’d suggest using the Dev Tools → Event viewer to get the correct event data. Listen to zwave_js_value_notification and trigger the event, and you’ll see the data reported.

Based on the device trigger, It’s probably:

property: scene
property_key: '002'

The non-discoverability of the events is one reason why the Event entity was added, as it provides more information up front.

Oh so close. You were right, the key was “002”, and if I use the actual device id, it works perfectly. But if I use:

"{{ device_id('event.media_wall_backlight_scene_002') }}"

then it doesn’t trigger. Did I get the template entered correctly?

And thanks for hanging in there with me!

Plug that template into Dev Tools → Template and make sure it’s returning the value you expect.

Also maybe post your latest automation YAML.

Dev Tools->Template returns the value I expect (and the one that if I enter it in the automation, things work). My latest yaml:

- id: '1733520810997'
  alias: Manual Goodnight
  description: 'Goodnight triggered by wall switch'
  #"{{ device_id('event.media_wall_backlight_scene_002') }}" 
  # 7b4757ab126c9589273dcdedaf74b28f
  triggers:
    - trigger: event
      event_type: zwave_js_value_notification
      event_data:
        property_key: "002"  
        value: "KeyPressed2x"
        device_id: "{{ device_id('event.media_wall_backlight_scene_002') }}" 
  actions:
  - action: script.goodnight
    metadata: {}
    data: {}
  mode: single