Quantcast
Channel: Configuration - Home Assistant Community
Viewing all articles
Browse latest Browse all 102810

Starting a Script Sequence With A For Loop

$
0
0

I have a script to control the LED bar on Inovelli switches, dimmers, and combo fan / light dimmers. At the moment I have to call it separately for each type of device (switches, dimmers, the fan portion of the combo device, and the light portion of the combo device). Goal: re-write the script so it can determine the device type of each entity and can be called once with mixed entity types. Ultimately, I’d like to call the script with an area and use area_entities(). I can’t assume all entities are devices of the same model and the parameters in Z-Wave JS are different for each model.

Here’s a simplified version of the script:

mode: parallel
max: 10

fields:
  entity:
    name: Entity
    description: The light.* entity for the LED we're setting.  Can be a comma separated list.
    required: yes
    example: light.office, light.guest_room
    selector:
      entity:
        integration: zwave_js
        domain:
          - light
          - fan
        multiple: true

  model:
    name: Model
    description: What type of device is this?
    required: yes
    example: Dimmer
    selector: 
      select:
        options:
          - Dimmer
          - Switch
          - Combo_Light
          - Combo_Fan

  LEDcolor:
    name: LED Color (non-effect)
    description: Sets the color of the LED indicating brightness levels
    required: no
    example: Blue
    selector:
      select:
        options:
          - "Off"
          - Red
          - Green
          - Blue

  parameters:
    "dimmer_effect_bulk": 16
    "dimmer_effect_color": "LED Indicator: Effect Color"

    "switch_effect_bulk": 8
    "switch_effect_color": "LED Effect Color"

    "combo_light_effect_bulk": 24
    "combo_light_effect_color": "Light LED Effect Color"

    "combo_fan_effect_bulk": 25
    "combo_fan_effect_color": "Fan LED Effect Color"

sequence:

##################
# LED strip color
##################
  - choose:
    - conditions: >
        {{ LEDcolor != "no change" }}
      sequence:
        - service: zwave_js.set_config_parameter
          data:
            entity_id: '{{ entity }}'
            parameter: |
              {% set effect_param = model + '_ledcolor' %}
              {{ parameters[effect_param] }}
            value: |
              {{ color_set[LEDcolor] }}

I thought I could use a for() loop to handle each entity one at a time, like this:

sequence:

  {% for entity in area_entities('office') %}
    {% if is_device_attr(entity, 'manufacturer','Inovelli') %}
      {% set model = device_attr(device_id(entity),'model') %}

##################
# LED strip color
##################
        - choose:
          - conditions: >
              {{ LEDcolor != "no change" }}
            sequence:
              - service: zwave_js.set_config_parameter
                data:
                  entity_id: '{{ entity }}'
                  parameter: |
                    {% set effect_param = model + '_ledcolor' %}
                    {{ parameters[effect_param] }}
                  value: |
                    {{ color_set[LEDcolor] }}
      {% endif %}
  {% endfor %}

However, that results in an error pointing to the start of the for() loop.

Error loading /config/configuration.yaml: while scanning for the next token
found character ‘%’ that cannot start any token
in “/config/scripts/inovelli_led_zwavejs.yaml”, line 342, column 4

There must be a way to do this, but I can’t find the right documentation. I’m not a software engineer but if you type slowly I might understand.

1 post - 1 participant

Read full topic


Viewing all articles
Browse latest Browse all 102810

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>