Issue with template

I am trying to rewrite the value of a binary sensor from off/on to Yes/No. Here is the template:

- binary_sensor:
    - name: "pihole_core_updatable_off_to_no"
      unique_id: "pihole_core_updatable_off_to_no"
      state: >-
        {% if is_state('binary_sensor.pi_hole_core_update_available', '"off"') %}
          No
        {% else %}
          Yes
        {% endif %}

But I never get the Yes/No value to appear on my card… it is still on/off. I am using the id that I created: binary_sensor.pihole_core_updatable_off_to_no.

Anybody know why this might be? Thx

Instead of yes/no use on/off in all lowercase

I want to go from off to No. And, from on to Yes.

Try this version:

      state: "{{ 'No' if is_state('binary_sensor.pi_hole_core_update_available', 'off') else 'Yes' }}"

I overlooked to mention that the most important thing you need to change is the first line. Change it from this:

- binary_sensor:

to this:

- sensor:

Why? Because a sensor’s states can be whatever you want but a binary_sensor’s states can only be on/off.

Normally you would simply change the binary_sensor’s device_class in order to display on/off with different words in the Lovelace UI. However, there’s no device_class that represents on/off as Yes/No.

1 Like

Binary sensor only supports on/off, as another user posted below, you should convert it into normal sensor.