Template not working with a variable

Hi!
I am using OpenHasp with HomeAssistant and I want to update the values on my display based on the light selected in the first display element. My config looks like this:

      - obj: "p3b1"
        event:
          "changed":
            - service: openhasp.command
              data:
                keyword: jsonl
                parameters: "{\"page\":3,\"id\":2,\"tag\":\"{{ text }}\",\"val\":\"{{ 1 if states(\"light.{{ text }}\") == \"on\" else 0 }}\"}"
              target:
                entity_id: openhasp.aztouch

The part that doesn’t work is {{ 1 if states(\"light.{{ text }}\") == \"on\" else 0 }}, for some reason it always returns 0. Setting the tag works, so i highly doubt that the {{ text }} variable (the id of the light for example: test_led) is the problem. When hardcoding a specific light it works. Any ideas what I am doing wrong/how to fix that? Thanks in advance!

Rather use single quotes within double quotes or vice versa, then you don’t need to escape it. If you use multiline YAML (>) you don’t need the outer quotes at all.

What do you get when you render the template string in your dev tools?

The general format you need here is:

parameters: "{{ 'some text:' ~ variable }}"

In other words: Make the whole thing a template and concatenate within using the tilde operator.

Changing {{ text }} to ~ text solved the problem.
I ended up setteling on:

parameters: "{'page':3,'id':2,'tag':'{{ text }}','val':'{{ 1 if states(\"light.\" ~ text) == \"on\" else 0 }}'}"

as it worked best for me.
Thanks for the help!