Help with templating in an array

Hi

I have the following YAML code to try to assign a user name in an array and send the user name via notification but I can’t find a way to return the results when the Z-wave notifiction is “Keypad unlock operation”

The following code keeps giving the following error “Message malformed: template value should be a string for dictionary value @ data[‘action’][1][‘data’]” code when I try to save the automation:
states(‘input_text.{{device_attr(trigger.event.data.device_id,“name”)|regex_replace(find=’ ‘, replace=’_‘,ignorecase=False) + ‘_last_user_name’}}’) I am pretty sure that the code is OK but I can’t find the way to get it to work in the array

Can someone explain me what I am missing here
thanks

P.s., I have also tried the following variant but nothing works:

{{ states(‘input_text.{{ device_attr(trigger.event.data.device_id,“name”)|regex_replace(find=’ ‘, replace=’_‘,ignorecase=False) + ‘_last_user_name’}}’) }}

{{ states(‘input_text.{{ device_attr(trigger.event.data.device_id,‘name’)|regex_replace(find=’ ‘, replace=’_‘,ignorecase=False) + ‘_last_user_name’}}’) }}

{{ states(‘input_text.{{ device_attr(trigger.event.data.device_id,“name”) | regex_replace(find=’ ‘, replace=’_‘,ignorecase=False) + “_last_user_name”}}’) }}

alias: Serrures Notification Pushover
description: ""
trigger:
  - platform: event
    event_type: zwave_js_notification
    event_data: {}
condition:
  - condition: template
    value_template: "{{trigger.event.data.command_class == 113}}"
action:
  - delay:
      hours: 0
      minutes: 0
      seconds: 5
      milliseconds: 0
  - service: notify.pushover_serrures
    data:
      message: |-
        {% set Lock_State_Array = {
           "Lock state: Lock jammed": 'Moteur bloqué',
           "Keypad lock operation": 'Barrée par le claiver',
           "Keypad unlock operation": states('input_text.{{ device_attr(trigger.event.data.device_id,"name")|regex_replace(find=' ', replace='_',ignorecase=False) + '_last_user_name'}}'),
           "Manual lock operation": 'Barrée manuellement' ,
           "Manual unlock operation": ' Débarrée manuellement',
           "RF lock operation": 'Barrée par RF',
           "RF unlock operation": 'Débarrée par RF',
           "Auto lock locked operation": 'Barrée automatiquement',
           "Battery level status: Charge battery soon": 'Changer les piles bientôt',
           "Battery level status: Charge battery now": 'Changer les piles immédiatement'
        } %}   
        {{ Lock_State_Array[ trigger.event.data.event_label ]}}
      title: "{{ device_attr(trigger.event.data.device_id,'name') }}"
      target:
        - iphonebruno
      data:
        sound: spacealarm
mode: single

Don’t nest templates, that is not valid.

Keypad unlock operation line has incorrectly nested single quotes.

Sorry, I have only been playing with coding for a very short time, can you show me how to correct the line ? I tought I tried every possible optin but can’t put my finger on the error

thanks

"Keypad unlock operation": states("input_text."~{{ device_attr(trigger.event.data.device_id,'name')|regex_replace(find=' ', replace='_',ignorecase=False) + '_last_user_name'}}),

Probably. I’m on a phone so not very easy to check.

1 Like

It would also be a good idea to add a lower filter to avoid issues with upper case letters.

{% set Lock_State_Array = {
   "Lock state: Lock jammed": 'Moteur bloqué',
   "Keypad lock operation": 'Barrée par le claiver',
   "Keypad unlock operation":  states('input_text.'~ device_attr(trigger.event.data.device_id,'name') | lower | replace(' ', '_') ~ '_last_user_name',
   "Manual lock operation": 'Barrée manuellement' ,
   "Manual unlock operation": ' Débarrée manuellement',
   "RF lock operation": 'Barrée par RF',
   "RF unlock operation": 'Débarrée par RF',
   "Auto lock locked operation": 'Barrée automatiquement',
   "Battery level status: Charge battery soon": 'Changer les piles bientôt',
   "Battery level status: Charge battery now": 'Changer les piles immédiatement'
} %}   
{{ Lock_State_Array[ trigger.event.data.event_label ]}}
2 Likes

YEAH , that was the solution, thank you all for the help, I am always surprise how effective and fast help can be on this forum.

The learning curve is sometime heavy for an old user of a other plateforme… Coding is not running imn my blood