I have added the following sensor to my configuration yaml which works as expected. Unfortunately Home Assistant shows an error in my configuration settings.
I get Error: template value should be a string for dictionary value @ data[ājson_attributes_templateā].
Using ChatGPT as a guide I have tried every way I can to eliminate the error including putting the code in the ādeveloper tools template checkerā and that shows the values as expected.
I also tried
As the error states, json_attributes_template expects a string (in this case a json string)ā¦ you are giving it a YAML dictionary.
That is generally a bad ideaā¦ the overwhelming majority of the source data for LLMs about HA configuration is either out of date or from people who have posted configurations that donāt work to forums like this oneā¦
The Template tool only āunderstandsā templating, it does not know if your YAML is valid at any level.
Thank you for your help. This now fixes the error. I also did ask ChatGPT to explain the syntax which now has helped me understand the answer and hopefully stop taking up time of helpful people such as yourselfā¦ Its a real shame there is so much poor data regarding the problem in ChatGPT.
Just for completeness this was the response
This YAML statement appears to be configuring a json_attributes_template in a YAML file, likely for a home automation system or a similar application. The template seems to be written in Jinja2, a templating language commonly used in configuration files.
Here's a breakdown of the YAML statement:
yaml
json_attributes_template: |
{% set val = value_json.LD2410 %}
{{ {
"LD2410_Distance_1": val.Distance[0],
"LD2410_Distance_2": val.Distance[1],
"LD2410_Distance_3": val.Distance[2],
"LD2410_Energy": val.Energy
} | tojson }}
json_attributes_template: This specifies a template for generating JSON attributes.
|: The pipe symbol (|) indicates that a block scalar follows, allowing the multiline representation of the template.
{% set val = value_json.LD2410 %}: This line sets a variable val to the value of value_json.LD2410. It seems like value_json is a JSON object, and the template is extracting the LD2410 property from it.
{{ ... }}: This is Jinja2 syntax for rendering expressions. The content inside the double curly braces is an expression that will be evaluated.
{"LD2410_Distance_1": val.Distance[0], ...}: This part creates a dictionary with keys corresponding to different distance properties (LD2410_Distance_1, LD2410_Distance_2, LD2410_Distance_3, LD2410_Energy) and values extracted from the val variable.
| tojson: The entire dictionary is then converted to a JSON string using the tojson filter.
In summary, this YAML statement defines a template for generating JSON attributes. It extracts specific values from a JSON object (value_json.LD2410) using Jinja2 syntax and constructs a new JSON object with a subset of these values. This resulting JSON object is then converted to a JSON string.
Dear Troon,
Many thanks for your willingness.
My problems is that:
I try to connect LD2410 to tasmota and itās done, have values as belows (form console window)