JSON message with Jinja2 template

How to create JSON message with Jinja2 template ?

{% set my_test_json = {'1': '{{ states("device_tracker.paulus") }}'  %}
{{ my_test_json }}

I got:
Error rendering template: TemplateSyntaxError: expected token ‘,’, got ‘device_tracker’

It should be { ‘1’:‘unknown’}

This worked for me
{%
set my_test_json = {
‘1’: states(“device_tracker.paulus”)
}
%}
{{ my_test_json }}

1 Like
{% set my_test_json = {'1': states('device_tracker.paulus')}  %}
{{ my_test_json }}
1 Like

Thank you, it works :wink: