Simple evaluation of script variable gives error 'expected a dictionary for dictionary value'

I’m trying to create a simple messaging script to use one script for multiple purposes, but getting errors with quite the cryptic error messages - god knows what they mean (okay, some of you probably do).

Script is as follows:

alias: msg_Telegram
sequence:
  - alias: "Set variables"
    variables:
      msg_target: >
        {% if {{ target }} == "Laurens" %}
          12345
        {% elif {{ target }} == "Dymphy" %} 
          12346
        {% else %} 
          12347
        {% endif %}
  - choose:
      - conditions:
          - condition: template
            value_template: "{{ photo_url } is defined"
        sequence:
          - service: telegram_bot.send_photo
            data:
              target: {{ msg_target }}
              caption: "{{ title }}"
              file: "{{ photo_url }}"
      - conditions:
          - condition: template
            value_template: "{{ video_url }} is defined"
        sequence:
          - service: telegram_bot.send_video
            data:
              caption: "{{ title }}
              target: {{ msg_target }}
              file: "{{ video_url }}"
    default:
      - service: telegram_bot.send_message
        data:
          title: "{{ title }}"
          target: {{ msg_target }}
          message: "{{ message }}"
mode: single
icon: mdi:message

Resulting error: Message malformed: expected a dictionary for dictionary value @ data[‘sequence’][0][‘variables’]

I’ve checked all indentation, tabs etc. Still doing something wrong?

You can’t put {{ }} inside {% %}. These indicators go on an entire line. They cannot be nested.

Okay, then how would I evaluate input variables?

by removing the {{ }} around target…

Makes sense… thanks, error went away.

You have some other things to fix as well. All your conditional templates do not contain all the code, only the variable. And you’re missing a } on the first one.

I noticed the missing }.
As for the conditionals, I just want to check if the input variable is set, in the assumption that “is defined” would do that (found it off a google search). Haven’t tested it yet so probably will return searching the forums :slight_smile:

The is defined needs to be in the template, right now it’s not. {{ is the start of the template, }} is the end.