Zooz Z-Wave JS Light Handler v2

Zooz light switch handler for the Z-Wave JS Integration. Requires scene control to be enabled on the switch. Supports all scene events from the switch, and both old and new scene IDs. If the top button is triggering the actions you have on the bottom button, toggle the Old Firmware switch. Optionally can send refresh commands to node IDs on single press and release events to support associated devices that don’t properly report their status back to the controller (now uses the native Z-Wave JS service). Supports pre and post 2021.4 events.

blueprint:
  name: 'Zooz Light Switch'
  description: Trigger actions from button presses
  domain: automation
  input:
    light_switch:
      name: Zooz Light Switch
      description: The Zooz Light Switch that will trigger the actions
      selector:
        device:
          integration: zwave_js
          manufacturer: Zooz
    associations:
      name: Refresh Associated Z-Wave Devices
      description: "Optional list of entities to refresh after switch is pressed. (Note: you must select an entity and not a device or area)"
      default: {}
      selector:
        target:
          entity:
            integration: zwave_js
    refresh_delay:
      name: Refresh Delay
      description: Number of seconds to wait after switch press to issue refresh
      default: 5
      selector:
        number:
          unit_of_measurement: seconds
          mode: box
          min: 0
          max: 60
    old_firmware:
      name: Old Firmware
      description: Enable if the Up and Down actions are reversed
      default: false
      selector:
        boolean:
    press_up_1x:
      name: 1x Press Up
      description: Pick an action for when the light switch UP button is pressed once.
      default: 
      selector:
        action:
    press_up_2x:
      name: 2x Press Up
      description: Pick an action for when the light switch UP button is pressed twice.
      default: 
      selector:
        action:
    press_up_3x:
      name: 3x Press Up
      description: Pick an action for when the light switch UP button is pressed three times.
      default: 
      selector:
        action:
    press_up_4x:
      name: 4x Press Up
      description: Pick an action for when the light switch UP button is pressed four times.
      default: 
      selector:
        action:
    press_up_5x:
      name: 5x Press Up
      description: Pick an action for when the light switch UP button is pressed five times.
      default: 
      selector:
        action:
    up_held:
      name: Up Held
      description: Pick an action for when the light switch UP button is held.
      default: 
      selector:
        action:
    up_released:
      name: Up Released
      description: Pick an action for when the light switch UP button is released.
      default: 
      selector:
        action:
    press_down_1x:
      name: 1x Press Down
      description: Pick an action for when the light switch DOWN button is pressed once.
      default: 
      selector:
        action:
    press_down_2x:
      name: 2x Press Down
      description: Pick an action for when the light switch DOWN button is pressed twice.
      default: 
      selector:
        action:
    press_down_3x:
      name: 3x Press Down
      description: Pick an action for when the light switch DOWN button is pressed three times.
      default: 
      selector:
        action:
    press_down_4x:
      name: 4x Press Down
      description: Pick an action for when the light switch DOWN button is pressed four times.
      default: 
      selector:
        action:
    press_down_5x:
      name: 5x Press Down
      description: Pick an action for when the light switch DOWN button is pressed five times.
      default: 
      selector:
        action:
    down_held:
      name: Down Held
      description: Pick an action for when the light switch DOWN button is held.
      default: 
      selector:
        action:
    down_released:
      name: Down Released
      description: Pick an action for when the light switch DOWN button is released.
      default: 
      selector:
        action:
mode: parallel
max: 10
trigger:
  - platform: event
    event_type: zwave_js_value_notification
    event_data:
      command_class: 91
      device_id: !input "light_switch"
  - platform: event
    event_type: zwave_js_event
    event_data:
      command_class: 91
      device_id: !input "light_switch"
action:
  - variables:
      scene_id: "{{ trigger.event.data.property_key_name }}"
      scene_value: "{{ trigger.event.data.value }}"
      associations: !input associations
      old_firmware: !input old_firmware
      up_scene: "{% if old_firmware == true %} 002 {% else %} 001 {% endif %}"
      down_scene: "{% if old_firmware == true %} 001 {% else %} 002 {% endif %}"
  - choose:        
    - conditions:
      - "{{ scene_id == up_scene }}"
      - "{{ scene_value == 'KeyPressed' }}"
      sequence: !input press_up_1x
    - conditions:
      - "{{ scene_id == up_scene }}"
      - "{{ scene_value == 'KeyPressed2x' }}"
      sequence: !input press_up_2x
    - conditions:
      - "{{ scene_id == up_scene }}"
      - "{{ scene_value == 'KeyPressed3x' }}"
      sequence: !input press_up_3x
    - conditions:
      - "{{ scene_id == up_scene }}"
      - "{{ scene_value == 'KeyPressed4x' }}"
      sequence: !input press_up_4x
    - conditions:
      - "{{ scene_id == up_scene }}"
      - "{{ scene_value == 'KeyPressed5x' }}"
      sequence: !input press_up_5x
    - conditions:
      - "{{ scene_id == up_scene }}"
      - "{{ scene_value == 'KeyHeldDown' }}"
      sequence: !input up_held
    - conditions:
      - "{{ scene_id == up_scene }}"
      - "{{ scene_value == 'KeyReleased' }}"
      sequence: !input up_released
    - conditions:
      - "{{ scene_id == down_scene }}"
      - "{{ scene_value == 'KeyPressed' }}"
      sequence: !input press_down_1x
    - conditions:
      - "{{ scene_id == down_scene }}"
      - "{{ scene_value == 'KeyPressed2x' }}"
      sequence: !input press_down_2x
    - conditions:
      - "{{ scene_id == down_scene }}"
      - "{{ scene_value == 'KeyPressed3x' }}"
      sequence: !input press_down_3x
    - conditions:
      - "{{ scene_id == down_scene }}"
      - "{{ scene_value == 'KeyPressed4x' }}"
      sequence: !input press_down_4x
    - conditions:
      - "{{ scene_id == down_scene }}"
      - "{{ scene_value == 'KeyPressed5x' }}"
      sequence: !input press_down_5x
    - conditions:
      - "{{ scene_id == down_scene }}"
      - "{{ scene_value == 'KeyHeldDown' }}"
      sequence: !input down_held
    - conditions:
      - "{{ scene_id == down_scene }}"
      - "{{ scene_value == 'KeyReleased' }}"
      sequence: !input down_released
  - choose:
    - conditions:
      - "{{ (associations|length()) and ((scene_id == up_scene or scene_id == down_scene) and (scene_value == 'KeyPressed' or scene_value == 'KeyReleased'))}}"
      sequence:
        - delay:
            seconds: !input refresh_delay
        - service: zwave_js.refresh_value
          target: !input associations
1 Like

I was using your old light handler and it worked perfectly… Was really happy to see you updated so quickly following the event changes with the new update, but I’m getting the following error in my logs from the new blueprint…

Logger: homeassistant.components.automation
Source: components/automation/__init__.py:626
Integration: Automation (documentation, issues)
First occurred: 7:56:41 PM (4 occurrences)
Last logged: 7:56:41 PM

Blueprint Zooz Light Switch generated invalid automation with inputs OrderedDict([('light_switch', '12eab632bc323e8f090ebb21e892eded'), ('old_firmware', True), ('press_up_1x', [OrderedDict([('service', 'light.turn_on'), ('target', OrderedDict([('entity_id', 'light.kitchen_lights')]))])]), ('press_up_2x', [OrderedDict([('service', 'light.turn_on'), ('target', OrderedDict([('entity_id', 'light.sink_level_light_color_on_off')]))])]), ('press_down_1x', [OrderedDict([('service', 'light.turn_off'), ('target', OrderedDict([('entity_id', 'light.kitchen_lights')]))])]), ('press_down_2x', [OrderedDict([('service', 'light.turn_off'), ('target', OrderedDict([('entity_id', 'light.sink_level_light_color_on_off')]))])])]): expected a dictionary for dictionary value @ data['action'][2]['choose'][0]['sequence'][1]['target']. Got None
Blueprint Zooz Light Switch generated invalid automation with inputs OrderedDict([('light_switch', '12eab632bc323e8f090ebb21e892eded'), ('old_firmware', True), ('press_up_1x', [OrderedDict([('service', 'light.turn_on'), ('target', OrderedDict([('entity_id', 'light.kitchen_lights')]))])]), ('press_up_2x', [OrderedDict([('type', 'turn_on'), ('device_id', 'd2ad93c553735d124887047bdced4de6'), ('entity_id', 'light.sink_level_light_color_on_off'), ('domain', 'light')])]), ('press_down_1x', [OrderedDict([('service', 'light.turn_off'), ('target', OrderedDict([('entity_id', 'light.kitchen_lights')]))])]), ('press_down_2x', [OrderedDict([('type', 'turn_off'), ('device_id', 'd2ad93c553735d124887047bdced4de6'), ('entity_id', 'light.sink_level_light_color_on_off'), ('domain', 'light')])])]): expected a dictionary for dictionary value @ data['action'][2]['choose'][0]['sequence'][1]['target']. Got None
Blueprint Zooz Light Switch generated invalid automation with inputs OrderedDict([('light_switch', '12eab632bc323e8f090ebb21e892eded'), ('press_up_1x', [OrderedDict([('service', 'light.turn_on'), ('target', OrderedDict([('entity_id', 'light.kitchen_lights')]))])]), ('press_down_1x', [OrderedDict([('service', 'light.turn_on'), ('target', OrderedDict([('entity_id', 'light.kitchen_lights')]))])])]): expected a dictionary for dictionary value @ data['action'][2]['choose'][0]['sequence'][1]['target']. Got None

Any input on this?

Thanks for your work!

Can you post the entry from automations.yaml for the specific automations?

1 Like

Sure, here you go:

- id: '1618364998481'
  alias: Kitchen Switch
  description: ''
  use_blueprint:
    path: mattstocum/zooz-z-wave-js-light-handler-v2.yaml
    input:
      light_switch: 12eab632bc323e8f090ebb21e892eded
      old_firmware: true
      press_up_1x:
      - service: light.turn_on
        target:
          entity_id: light.kitchen_lights
      press_up_2x:
      - service: light.turn_on
        target:
          entity_id: light.sink_level_light_color_on_off
      press_down_1x:
      - service: light.turn_off
        target:
          entity_id: light.kitchen_lights
      press_down_2x:
      - service: light.turn_off
        target:
          entity_id: light.sink_level_light_color_on_off

I just edited the blueprint, can you re-grab it and try again? The issue was with my handling of when no entities were selected to refresh. I think I’ve got it fixed now

1 Like

That worked perfectly! Thanks for the help!

Side note to anyone else who’s updating from the old blueprint to this one… Delete the old blueprint and import this one, but save it with the same name as the old one (just delete the -V2) and you won’t need to rebuild any automations.

This didn’t occur to me until I was deleting and re-adding the corrected V2, but thankfully i hadn’t deleted the old automations yet. Thank goodness for that, because I have 14 zooz switches, most of which use this blueprint.

You could also go into automations.yaml and correct the path to the new blueprint, but don’t try to modify old blueprinted automations in the GUI or it will make you start over with all of your inputs.

If you go into YAML mode in the GUI you can change the path, then switch back to the visual editor, and it won’t reset any of your inputs. Happy to hear you were able to get switched over without any breakage. I made this a new blueprint because if you were using the old MQTT based refresh, switching to this one would break all of your automations, requiring you to go into automations.yaml to fix them, or at least that’s what happened to me.

True, editing yaml in the GUI is actually how I changed the automation I posted here when I took the steps I mentioned…

However, if I was editing multiple automations this way, I’d just do it in the automations.yaml file… A lot less clicks to accomplish the same thing.

Thanks again for your work! I don’t remember if I posted thanks on your V1, but I really appreciate it. I had created my own blueprint for OZW because none existed for Zooz, and didn’t want to invest the time to create it all over again (plus mine was much more rudimentary than yours is).

1 Like

Switched over to the zwavejs2mqtt addon from the zwavejs addon - still using the same zwavejs integration. Previously - using this blueprint for automations worked like a dream. Now, no automations are working - and I’m getting this error -
Error: UndefinedError: ‘dict object’ has no attribute ‘event’

I’m not seeing anyone comment that using the zwave2jsmqtt has caused automation issues.

FYI - I have scene control turned on for the zooz switches. Like I mentioned - I’ve used this blueprint prior and it worked.

Appreciate any help here.

@mattstocum Thank you for this blueprint, it’s made my life a LOT easier today.

Question for you, what are you doing for dimming?

Just something like this:

    up_held:
      - service: light.turn_on
        data:
          brightness_step_pct: 1
        target:
          entity_id: light.front_porch_bulb
    down_held:
      - service: light.turn_on
        data:
          brightness_step_pct: -1

Or do you need to include the the up_released / down_released ?