How can I use escape characters while templating?

I read the docs here:

However I need to use a template to send a MQTT payload that has {{ test }} in it. I’m using data_template to build my MQTT payload.

How can I do this?

I’ve tried the template tester in dev tools and cannot figure out how to do it

{{ '{{ test }}' }}
2 Likes

Nice, I didn’t know you could print things within the brackets like that. It works great, thanks. :slight_smile:

I was trying to set up variables like this:

{% set json = {
  "start": "{{",
  "end": "}}"
} %}

{{ json.start }} test {{ json.end }}

But {{ '{{ test }}' }} works better and doesn’t need multiple lines also.

Yeah, it’s just a string being output. Also, you can make a macro that does the same thing if you need to use it multiple times inside a template:

{%- macro ret(v) %}
{{- '{{{{ {} }}}}'.format(v) }}
{%- endmacro %}

1 Like