Error binary sensor template

Hi all,
I’d like change the output of my binary_sensor.230…

What is wrong?

sensor:
    - platform: template
      sensors:
        230:
          entity_id: binary_sensor.230
          value_template: >
            {% if is_state('binary_sensor.230', 'on') %}
              OK
            {% else %}
              FAIL
            {% endif %}

many thanks

You can’t change the state of a binary sensor to anything but on or off.

You can change the way it is displayed by picking a device class.

If there is no device class that suits use a sensor instead of a binary sensor.

Also I would recommend against starting your entity names with a number. It can make things more complicated when templating.

EDIT: I’m blind. You are using a sensor. Your issue is the complication I linked to.

Try:

{% if is_state("binary_sensor['230']", "on") %}

Also delete the entity_id: line. This has been depreciated.

Thanks for your reply…

    - platform: template
      sensors:
        rete:
          value_template: >
            {% if is_state('binary_sensor.rete', 'on') %}
              OK
            {% else %}
              FAIL
            {% endif %}

I changed the name with a number… But I still see this:
image

If you alreadey have a binary_sensor.230 or binary_sensor.rete, what state does it show in Dev Tools/states?

A template_sensor supports sensors which get their values from other entities.

it shows ON/OFF

Sorry but I don’t understand… Could I use binary_sensor.rete or I have to use sensor.rete?

Please show us a screenshot of the entity in Dev Tools/states.
For example:

Then your template sensor should work,

sensor:
  - platform: template
    sensors:
      rete:
        value_template: >
          {% if is_state('binary_sensor.rete', 'on') %}
            OK
          {% else %}
            FAIL
          {% endif %}

and should produce a sensor.rete

many thanks… it works… sorry but I’m newbie…

I didn’t know that if I have a binary_sensor.rete and i create a sensor template, it creates a new sensor (sensor.rete)…

sory and thanks again

1 Like

You’re welcome! :slightly_smiling_face: