Template sensor unknown state

Hi everyone, I can’t understand the problem in the following template sensor:

- sensors:
    template_entrance_door_lock:
      value_template: >-
        {% if states('sensor.vibration_entrance_door_lock_angle_x') | float > 20 %}
          locked
        {% else %}
          potentially unlocked
        {% endif %}
      icon_template: >
        {% if states('sensor.vibration_entrance_door_lock_angle_x') | float > 20 %}
          mdi:shield-lock
        {% else %}
          mdi:help-rhombus
        {% endif %}

I use this template in a mushroom template card. The icon is correct, and changes depending on the state, but the state is always unknown. What am I doing wrong? :frowning:

Are you using this in the “State template” field of the Template Helper editor or did you place it in your configuration file?

Hi, I modified my post, the first line of code got cut out. The code above is indeed in the “template:” context.

It suddenly works, don’t know why :confused: … I restarted HA many times before,…