My Brute Force Automation Approach For Multiple Entities Seems.. Wrong

I have a bunch of GE 14295 Z Wave dimmer switches and recently figured out how to get the double tap feature to work. My intent was to have a shortcut to get full brightness from the light switch. In the example I followed/modified, I created an automation that looks like this:

- alias: 'Back Porch Light Double Tap On'
  - platform: event
    event_type: zwave.node_event
      entity_id: zwave.back_porch_light
      basic_level: 255
  - service: light.turn_on
      entity_id: light.back_porch
      brightness: 255

Note that the basic_level and brightness both being 255 is coincidental, don’t worry about that.

Having taken care of one switch, I proceeded to brute force this method and duplicate it for another 22 lights in my house. 12 lines of code times 22 instances later, I now have a small maintenance nightmare on my hands. I split each automation in to their own file, but that really only helps future cut and paste engineering, which still isn’t ideal.

Any yaml/templates/scripts/other way to consolidate this automation to something that makes more sense to maintain? The only unique things here are the alias, the zwave entity, and the light entity. Having a unique alias for each switch isn’t important to me, a solution with one automation would be fine. My intent is for each switch to have identical behavior.

Thanks in advance. And apologies if this was already covered somewhere else in the docs/forum, I didn’t find it.

This is just throwing out spit-balls here but…

could you change the trigger to check for any generic zwave node event then template the action based on the event data?

- alias: 'Light Double Tap On'
  - platform: event
    event_type: zwave.node_event
  - service: light.turn_on
      entity_id: >
          {% if = 'zwave.back_porch_light' %}
          {% elif = 'zwave.something_else' %}
          {% else %}
          {% endif %}
      brightness: 255

I’m not exactly sure how to extract the entity_id from the event data but I think that’s pretty close.

Might be worth it to give it a try tho.


That would require only one event listener instead of 22 and would seem to be the better way to go.