Why does my template not work

Hi,

i have a modbus sensor

- name: "Wallbox Fahrzeug Status"
  unique_id: wallbox_juice_vehicle_state
  slave: 1
  address: 122
  input_type: holding
  data_type: uint16
  # Status: 1=A, 2=B (verbunden), 3=C (lädt), 4=D, 5=E

works fine so far, can be displayed in the UI no problem.

strage is in the entiy search i find the following

so first question is … why does it get another entiy_id even i defined a unique id?

but the main problem is, i want to display a text according to the state, so i created a template

template:
  - sensor:
      - name: "Wallbox Fahrzeug Status Text"
        state: >
          {% if is_state('sensor.wallbox_fahrzeug_status', '1') %}
            Standby (A)
          {% elif is_state('sensor.wallbox_fahrzeug_status', '2') %}
            Fahrzeug verbunden (B)
          {% elif is_state('sensor.wallbox_fahrzeug_status', '3') %}
            Ladevorgang aktiv (C)
          {% elif is_state('sensor.wallbox_fahrzeug_status', '4') %}
            Laden mit Belüftung (D)
          {% elif is_state('sensor.wallbox_fahrzeug_status', '5') %}
            Fehler (E)
          {% else %}
            Unbekannt
          {% endif %}
        icon: >
          {% if is_state('sensor.wallbox_fahrzeug_status', '1') %}
            mdi:ev-station
          {% elif is_state('sensor.wallbox_fahrzeug_status', '2') %}
            mdi:car-connected
          {% elif is_state('sensor.wallbox_fahrzeug_status', '3') %}
            mdi:battery-charging-100
          {% elif is_state('sensor.wallbox_fahrzeug_status', '4') %}
            mdi:battery-charging-100
          {% elif is_state('sensor.wallbox_fahrzeug_status', '5') %}
            mdi:alert-circle
          {% else %}
            mdi:help-circle
          {% endif %}

i tried to use sensor.wallbox_fahrzeug_status as well as sensor.wallbox_juice_vehicle_state, but i never get a entity Wallbox Fahrzeug Status Text … but also no error … any idea what i am doin wrong?

PS.:


here at least the code seams to work fine

The template seems fine, so the most likely cause is that it wasn’t loaded. Where did you put it in your config, did you restart HA or reload templates, and where did you check for errors?

i put it at the end of the configuration.yaml, i reloded the entire config, it restarted HA … nothing changed

If you had previous template sensors, then the duplicate template: line would be the cause. You can only have one in corfiguration.yaml, and all templates should be listed beneath it. If the original template line had an include after it, the sensor should be in the file named there, without the template line and appropriately indented (one level less).

The error would hve shown up in the logs though.

i checked this, and also no errors in the log

The entity ID is not determined from the unique_id.

Once you work out why it’s not working from other suggestions, the template can be tidied up a bit:

        state: >
          {% set map = {
               '1': 'Standby (A)',
               '2': 'Fahrzeug verbunden (B)',
               '3': 'Ladevorgang aktiv (C)',
               '4': 'Laden mit Belüftung (D)',
               '5': 'Fehler (E)' } %}
          {{ map.get(states('sensor.wallbox_fahrzeug_status'), 'Unbekannt') }}

Unless the templated icon is important to you, you can set up Template Sensor Helpers in the UI to avoid fiddling with YAML.

Are you sure you edited the configuration.yaml that your system is reading, and not a backup / alternative file?

What log did you check? The file is not updated by default anymore, you should check the logs via the GUI.

i checke Settings → System → Logs and then show original log

the icon is the reason why i did use yaml and not the editor because i dont know how to set the icons in the editor

It creates a new entity, it doesn’t overwrite your existing one.

Look for sensor.wallbox_fahrzeug_status_text

i was searching for that

the funny thing is today it appeared, dont know why and how i changed nothing

if it was your first template entity, you have to restart. Reloading won’t work.

As is sayed i restarted multible times :confused: dont know what i did wrong

but thanks for all your assistants now it works fine