Convert color (word) to hue (number) inside a script

Greetings,

I’m setting up a script to turn on the notifications on my Inovelli light switches. I have this script, which is working well:

inovelli_led_notification_test:
  alias: Inovelli LED notification test
  mode: single
  sequence:
  - service: zwave_js.set_config_parameter
    target:
      entity_id:
      - switch.mudroom_light
      - switch.stevens_lamp
      - switch.katherines_lamp
    data: #Color
      parameter: 8
      bitmask: 255
      value: "{{ color }}"
  - service: zwave_js.set_config_parameter
    target:
      entity_id:
      - switch.mudroom_light
      - switch.stevens_lamp
      - switch.katherines_lamp
    data: #Effect
      parameter: 8
      bitmask: 2130706432
      value: "{{ effect }}"

I would like to make some adjustments so that when I call the script from an automation I can specify the name of the color I want, and the script will convert it to a number. Something like this?

data: #Color
  parameter: 8
  bitmask: 255
  value: >
    {% if color, 'green' %}
      135
    {% elif color, 'red' %}
      0
    {% elif color, 'blue' %}
      200
    {% else %}
      75
    {% endif %}

Any insight is appreciated. Thanks.

You can do that or use a dictionary.

data: #Color
  parameter: 8
  bitmask: 255
  value: "{{ {'green': 135, 'red': 0, 'blue': 200 }.get(color, 75) }}"

Thanks @123! You are rapidly becoming one of my best friends!

1 Like

You may also want to look through some of the existing scripts and see if they already do what you’re trying to accomplish. It could save you some time unless it’s more about figuring it out for yourself, which I can understand. If nothing else, you can reference these for differences in their dimmers, switches, and fan / light combo devices, which use different values for the same effects.

Red series dimmers: GitHub - kschlichter/Home-Assistant-Inovelli-Red-Dimmer-Switch: Scripts for setting LED indicators and effects on Inovelli products.
Blue series dimmers: home-assistant-blueprints/inovelli_blue_led_zigbee2mqtt.yaml at 5d14728fc377457f97c1f1afcec5887946b60921 · zanix/home-assistant-blueprints · GitHub

Thanks @kschlichter.

I will look into those links, but you are right, a big part of this is figuring out how everything works under the hood so I can solve more complex problems down the road.

Good attitude. Although @123’s solution is (as usual) more elegant, your original script solution was very close. The syntax is thus:

{% if color == 'green' %}
1 Like