LZW45 Quick Strip Effects Script for Home Assistant

Hey guys, I made a script for home assistant that properly sets the Quick Strip Effects via Home Assistant. Here’s the link to the script on home assistant.

For those of you that are too lazy to click the link, here’s the script:

Zwave 1.4 & OpenZwave

Script

lzw45_quick_strip_effect:
  alias: LZW45 Quick Strip Effect
  description: Sets quick strip effects for the Inovelli LZW45 LED Strip
  mode: restart
  fields:
    service: 
      description:
        (required) The name of the service. 
          OpenZwave (Beta) -> 'ozw.set_config_parameter'
          OpenZwave (1.4) -> 'zwave.set_config_parameter'
      example: ozw.set_config_parameter
    lzw45: 
      description: (required) The entity_id for the lzw45 LED Strip.
      example: light.lzw45_light_strip_level
    effect:
      description: (required) The desired effect - 'off', 'solid', 'chase', 'fast-blink', 'slow-blink', 'fast-fade', 'slow-fade'
      example: slow-fade
    hue:
      description: (exclusive) The Hue.  Valid ranges are 0 to 360.  You cannot combine this with color_temp.
      example: 360
    color_temp:
      description: (exclusive) The color temperature (2700 - 6500).  You cannot combine this with hue.
      example: 2700
    brightness_pct:
      description: (optional) The brightness percent, 0 - 100.  Defaults to 100 if omitted.
      example: 10
    seconds:
      description: (optional) Duration of the effect in seconds (0 - 60 seconds).  Cannot be combined with 'minutes' or 'hours'.
      example: 1
    minutes:
      description: (optional) Duration of the effect in minutes (0 - 60 minutes).  Cannot be combined with 'seconds' or 'hours'.
      example: 1
    hours:
      description: (optional) Duration of the effect in hours (0 - 60 hours).  Cannot be combined with 'seconds' or 'minutes'.
      example: 1
    endless:
      description: (optional) Set to true if you want the effect to stay 'forever'.
      example: true
  variables:
    service: >
      {{ service | default('ozw.set_config_parameter') }}
    node_id: >
      {%- if lzw45 is not defined %}
        0
      {%- else %}
        {%- set node_id = state_attr(lzw45, 'node_id') %}
        {{ node_id if node_id else 0 }}
      {%- endif %}
    byte1: >
      {%- if hue is defined and color_temp is not defined %}
        {%- set hue = hue | int %}
        {%- set hue = hue if hue >= 0 else 0 %}
        {%- set hue = hue if hue <= 360 else 360 %}
        {{ (hue / 360 * 255) | int }}
      {%- elif color_temp is defined and hue is not defined %}
        {%- set color_temp = color_temp | int %}
        {%- set color_temp = color_temp if color_temp >= 2700 else 2700 %}
        {%- set color_temp = color_temp if color_temp <= 6500 else 6500 %}
        {{ ((color_temp - 2700) / (6500 - 2700) * 255) | int }}
      {% else %}
        0
      {%- endif %}
    byte2: >
      {%- set pct = (brightness_pct | default(100)) | int %}
      {%- if 0 <= pct <= 100 %}
        {%- if pct == 100 %}
          10
        {%- else %}
          {{ 128 + pct }}
        {%- endif %}
      {%- else %}
        0
      {%- endif %}
    byte3: >
      {%- set seconds = (seconds | default(0)) | int %}
      {%- set minutes = (minutes | default(0)) | int %}
      {%- set hours = (hours | default(0)) | int %}
      {%- set forever = endless | default(false) %}
      {%- if forever %}
        255
      {%- elif 0 < seconds <= 60 %}
        {{ seconds }}
      {%- elif 0 < minutes <= 60 %}
        {{ minutes + 60 }}
      {%- elif 0 < hours <= 60 %}
        {{ hours + 120 }}
      {%- else %}
        0
      {%- endif %}
    byte4: >
      {%- if hue is defined or color_temp is defined %}
        {%- set color_type = 64 if color_temp is defined else 0 %}
        {%- set effects = { 'off': 0, 'solid': 1, 'chase': 2, 'fast-blink': 3, 'slow-blink': 4, 'fast-fade': 5, 'slow-fade': 6 } %}
        {%- set value = 0 %}
        {%- set value = value + effects.get(effect, 0) %}
        {{ value + color_type }}
      {%- else %}
        0
      {%- endif %}
    bytes: >
      {{ byte4 * 2**24 + byte3 * 2**16 + byte2 * 2**8 + byte1 }}
  sequence:
  - condition: template
    value_template: "{{ node_id != 0 }}"
  - service: "{{ service }}"
    data:
      node_id: "{{ node_id }}"
      parameter: 21
      value: "{{ bytes }}"

Service

service: script.lzw45_quick_strip_effect
data:
  service: ozw.set_config_parameter
  lzw45: light.lzw45_light_strip_level
  effect: slow-fade
  hue: 360
  brightness_pct: 100
  seconds: 20

Zwave JS

Script

lzw45_quick_strip_effect:
  alias: LZW45 Quick Strip Effect
  description: Sets quick strip effects for the Inovelli LZW45 LED Strip
  mode: restart
  fields:
    lzw45: 
      description: (exclusive) The entity_id for the lzw45 LED Strip.
      example: light.lzw45_light_strip_level
    effect:
      description: (required) The desired effect - 'off', 'solid', 'chase', 'fast-blink', 'slow-blink', 'fast-fade', 'slow-fade'
      example: slow-fade
    color:
      description: (optional) hue or color_temp
      example: hue
    hue:
      description: (exclusive) The Hue.  Valid ranges are 0 to 360.  You cannot combine this with color_temp.
      example: 360
    color_temp:
      description: (exclusive) The color temperature (2700 - 6500).  You cannot combine this with hue.
      example: 2700
    brightness_pct:
      description: (optional) The brightness percent, 0 - 100.  Defaults to 100 if omitted.
      example: 10
    seconds:
      description: (optional) Duration of the effect in seconds (0 - 60 seconds).  Cannot be combined with 'minutes' or 'hours'.
      example: 1
    minutes:
      description: (optional) Duration of the effect in minutes (0 - 60 minutes).  Cannot be combined with 'seconds' or 'hours'.
      example: 1
    hours:
      description: (optional) Duration of the effect in hours (0 - 60 hours).  Cannot be combined with 'seconds' or 'minutes'.
      example: 1
    endless:
      description: (optional) Set to true if you want the effect to stay 'forever'.
      example: true
  variables:
    color_type: >
      {{ 64 if color == 'color_temp' else 0 }}
    byte1: >
      {%- if color_type == 0 %}
        {%- set hue = hue | int %}
        {%- set hue = hue if hue >= 0 else 0 %}
        {%- set hue = hue if hue <= 360 else 360 %}
        {{ (hue | default(360) / 360 * 255) | int }}
      {%- else %}
        {%- set color_temp = color_temp | int %}
        {%- set color_temp = color_temp if color_temp >= 2700 else 2700 %}
        {%- set color_temp = color_temp if color_temp <= 6500 else 6500 %}
        {{ ((color_temp | default(2700) - 2700) / (6500 - 2700) * 255) | int }}
      {%- endif %}
    byte2: >
      {%- set pct = (brightness_pct | default(100)) | int %}
      {%- if 0 <= pct <= 100 %}
        {%- if pct == 100 %}
          10
        {%- else %}
          {{ 128 + pct }}
        {%- endif %}
      {%- else %}
        0
      {%- endif %}
    byte3: >
      {%- set seconds = (seconds | default(0)) | int %}
      {%- set minutes = (minutes | default(0)) | int %}
      {%- set hours = (hours | default(0)) | int %}
      {%- set forever = endless | default(false) %}
      {%- if forever %}
        255
      {%- elif 0 < seconds <= 60 %}
        {{ seconds }}
      {%- elif 0 < minutes <= 60 %}
        {{ minutes + 60 }}
      {%- elif 0 < hours <= 60 %}
        {{ hours + 120 }}
      {%- else %}
        0
      {%- endif %}
    byte4: >
      {%- set effect = effect | default('static') | lower | replace(' ', '-') %}
      {%- set effects = { 'off': 0, 'solid': 1, 'chase': 2, 'fast-blink': 3, 'slow-blink': 4, 'fast-fade': 5, 'slow-fade': 6 } %}
      {%- set value = 0 %}
      {%- set value = value + effects.get(effect, 0) %}
      {{ value + color_type }}
    bytes: >
      {{ byte4 * 2**24 + byte3 * 2**16 + byte2 * 2**8 + byte1 }}
  sequence:
  - condition: template
    value_template: "{{ lzw45 is defined }}"

  - service: zwave_js.bulk_set_partial_config_parameters
    target:
      entity_id: "{{ lzw45 }}"
    data:
      parameter: 21
      value: "{{ bytes }}"

Service

service: script.lzw45_quick_strip_effect
data:
  lzw45: light.lzw45_light_strip_level
  effect: slow-fade
  hue: 360
  brightness_pct: 100
  seconds: 20
2 Likes