Can't get Custom Text UI Binary Template to work

Hi All,

I am having troubles getting some custom text on my UI.

I have a binary sensor which monitors my computers lock state, so HA knows if I am using my machine or not. This works fine.

I wanted to create a UI element instead of saying On/Off,Detected/Clear etc, it says something like “In Use” or “Locked”

I looked at this thread (and others) which seemed to be exactly what I wanted.

The Template Dev tool shows this is working, but I can’t seem to get it to work after adding it to my configuration. The computer_in_use_template sensor always shows Off.

The following is from my binary_sensors.yaml. First part is the MQTT sensor for the computer lock state, second is the template.

- platform: mqtt
  name: "Computer Lock State"
  state_topic: "computer/lock-state"
  payload_on: "unlocked"
  payload_off: "locked"
  device_class: power
  unique_id: computer_lock_state

- platform: template
  sensors:
    computer_in_use_template:
      friendly_name: Computer State
      entity_id: binary_sensor.computer_lock_state
      value_template: >-
        {% if is_state('binary_sensor.computer_lock_state', 'on') %}
          Using
        {% else %}
          Locked
        {% endif %}

Any help is appreciated!

Cheers

Binary sensors have a state of on or off only. The way these states are displayed in the front end can be changed using device class. This only changes the way they are displayed the states still stay on/off.

If none of the device classes fit your need then you will have to create a template sensor instead of a template binary sensor. A template sensor can have any state under 255 characters.

Thanks!

So I moved the template from the binary_sensors to the sensors config and its working fine.

After typing it out it makes sense. Thanks for your help!