Value_template not working for a sensor

Hi all
i’m trying to change the value status for a sensor but the value is not changing based on a condition.
Despite that the ICON is working and changing as expected.

the value is set now to OFF and not changing status.
which can be the issue?

this is the sensor:

  - platform: template
    sensors:
      ingressoporta:
        friendly_name: "Ingresso Porta"
        value_template: >-
          {% if is_state("binary_sensor.ingressomovimento", "on") %}
            Closed
          {% else %}
            Open
          {%endif %}
        icon_template: >-
          {% if is_state("binary_sensor.ingressomovimento", "on") %}
            hass:remote
          {% else %}
            mdi:weather-sunset-down
          {% endif %}

Is this a binary template sensor or a template sensor?

Hi Tom,
thanks for the reply is a binary sensor in a dedicated file binary_sensor.yaml

this is the first i need to customize

the default value are: Clear and Detected, and i would like to put it in my native language, so just replace that value

For binary template sensors the value_template must resolve to true or false. e.g.

value_template: "{{ is_state("binary_sensor.ingressomovimento", "on") }}"

If you want to change the Off/On state display of this in the front end you need to apply a device class.

  - platform: template
    sensors:
      ingressoporta:
        friendly_name: "Ingresso Porta"
        value_template: "{{ is_state("binary_sensor.ingressomovimento", "on") }}"
        device_class: door

This will also change the icons.

You could apply the device class directly to binary_sensor.ingressomovimento in customize and not need a template binary sensor at all.

Tom i read about that that is not what i need because if i change the device class i will use the status value as per it.

what i would like to do is replace on/off, open/closed, clear/detected… with different label in my UI based on a condition.

so if the device class return CLEAR/DETECTED i would like to replace this value with APERTO/CHIUSO so different state.

i tried as well since last 2 days to change also the customize from UI but i cannot change it based on a condition.

hope i clarify the scenario and thanks for helping :slight_smile:

User Profile (bottom left of main screen) / Language. If that is set to Italian, the displayed states should also be translated. I’ve just changed my language to Italian, and:

image

You can’t do that for binary sensors. Their sate is always ‘on’ or ‘off’. The only way to change how they are displayed is to apply a device class.

You can make a template sensor though.

sensor:
  - platform: template
    sensors:
      ingressoporta:
        friendly_name: "Ingresso Porta"
        value_template: >-
          {% if is_state("binary_sensor.ingressomovimento", "on") %}
            Closed
          {% else %}
            Open
          {%endif %}
        icon_template: >-
          {% if is_state("binary_sensor.ingressomovimento", "on") %}
            hass:remote
          {% else %}
            mdi:weather-sunset-down
          {% endif %}

Hi Troon
i know i can change this to Italian, i was simplying the translation for what i want…

for example instead of acceso/spento i would like to put some more different value out of this available from the platform.(like: working/not working etc…)

as this is not available for binary sensor i will keep it in english :slight_smile: as i want just some sensor customized and rest can stay as per platform

yes if i use as normal sensor it works…
will consider as well you advice

thanks