I have a template in jinja who’s giving the wanted result in the editor but I cannot find how to implement in the lovelace screen.
The file is named niveau.ninja and placed in custom_templates.
Looks to me it’s doing nothing, I tried to put the template in the config file but that gives me a lot of errors, so help wanted to understand why or what to do.
I prefer jinja, that’s more clear.
sensor:
- platform: template
sensors:
niveau_piscine:
friendly_name: "Niveau"
unit_of_measurement: "State"
value_template: >-
{% set mapper = {
'4095' : 'bon',
'0' : 'à remplir' } -%}
{%- set state = states('sensor.niveau_piscine_2') -%}
{{ mapper[state] if state in mapper else 'inconnu' }}
I assume you mean .jinja? The jinja files in custom_templates are for macros only, that is why you gor the response above. But what you display seems to be a template sensor, which is yaml (with jinja inside).
If you have a template.yaml it goes in there (everyting indented one level less), if you have no template.yaml file it can also be placed below below a template: line in configuration.yaml. If you are unclear on the difference between the two methods, check:
What do you mean “no conversion”?
What is a state of your entity?
Use Dev tools → State to see what is inside your entity.
Also, use Dev tools → Template for testing your templates.
You’re right, my system has changed automaticly the sensorname by adding _3
I’ve changed the code but won’t help me.
In the template editor works it, in the configuration file it still won’t.
The UI is too complicated for me Ildar, I don’t know what to fill in.
I’ve programmed in Z80 machine language, doïng so now in Python is already a big step.
So what you’re saying is that the example you posted here isn’t what is actually in your system? If that’s the case then it makes it exceptionally difficult for us to solve your problems.
The Template Editor only checks the Jinja2 template. It doesn’t validate the Template Sensor’s configuration.
Obviously you’re still doing something wrong in the configuration.yaml file.
It’s not python. The example you posted is a combination of YAML and Jinja2.
Creating a Template Sensor helper via the UI is far simpler than creating one using YAML. The UI also validates the Template Sensor’s configuration and reports its computed value.
The screenshot you posted still shows your template is self-referential. I have already pointed out that this is invalid.
What is the entity_id of the sensor that reports the pool’s level as a number? It cannot be the same entity_id as the Template Sensor you are creating.