Scripts - using fields in condition value template

Need some help understanding how to use a script field value in a conditional. What I’m trying to do is pass in a zwave sensor entity and check that it’s node_name attribute matches a string before setting zwave configuration parameters.

In the script below I have a field called entity_id, I am then creating a variables called entity and trying to use it in a value_template. I get a configuration error. How do I properly use this field in the value_template?

The error is

invalid key: "OrderedDict([("states(entity).attributes.node_name == 'AEON Labs ZW100 MultiSensor 6'", None)])"
in "/config/scripts.yaml", line 85, column 0

Line 85 is the value_template line below.

Similarily, I will need to find a way to get the .node_id attribute of the entity and use that where I have {{node_id}}

So two problems, hopefully with similar solutions.

configure_aoetec_multisensor_node:
    alias: configure_aoetec_multisensor
    description: 'Configures / reconfigures the AOETec Mulitsensor'
    fields:
      entity_id:
        description: 'Entity Id'
        example: 'zwave.sensor_2'
    mode: single
    variables:
      entity: "{{ entity_id }}"
    sequence:
      - service: system_log.write
        data:
          message: "Before Test"
      - condition:
          condition: template
          value_template: {{ states(entity).attributes.node_name == 'AEON Labs ZW100 MultiSensor 6' }}
      - service: system_log.write
        data:
          message: "After Test"
      # https://products.z-wavealliance.org/products/2684/configs
      - service: zwave.set_config_parameter
        data:
          # Temp, Humidity, Luminance
          node_id: "{{ node_id }}"
          parameter: 101
          value: 224
          size: 4
      - service: zwave.set_config_parameter
        data:
          # Report interval
          node_id: "{{ node_id }}"
          parameter: 111
          value: 240
          size: 4
      - service: zwave.set_config_parameter
        data:
          # No report on threshold
          node_id: "{{ node_id }}"
          parameter: 40
          value: Disabled
          size: 1
      - service: zwave.set_config_parameter
        data:
          # Disable motion sensor for now.
          node_id: "{{ node_id }}"
          parameter: 4
          value: Disabled
          size: 1



Where is the variable node_id defined? Is it passed to the script?

That’s a great question. In the original script I was passing the node_id in and then performing all the zwave configuration steps for the node which worked fine. It then occurred to me, that if I passed in a node_id that was not this Aoetec device, i could really mess the config up. So I decided to try to pass the Zwave Device object in.

So yes, once I figure out how to check that the device object is the right type of device, I will then need to get the node_id from the device object and use it for those calls also.

The Template Condition is missing outer double-quotes. It should look like this:

          value_template: "{{ states[entity].attributes.node_name == 'AEON Labs ZW100 MultiSensor 6' }}"

EDIT

Correction. Replaced parenthesis with square brackets.

Thank you so much @123 , that got me on the right path. Also had to update the code to this for it to work:

        value_template: "{{ state_attr(entity, 'node_name')== 'AEON Labs ZW100 MultiSensor 6' }}"

And was able to get the node_id later on using a data_template

      - service: zwave.set_config_parameter
        data_template:
          # Temp, Humidity, Luminance
          node_id: "{{ state_attr(entity, 'node_id') }}"
          parameter: 101
          value: 224
          size: 4