Binary sensor state text

Is it still not possible to change the on/off text for a binary sensor? I have a washing machine and want the text “running/stopped” instead of on/off.
No device class seems to fit this need.
I tried with “alias” in customize but no effect.
alias_on: ‘Running’
alias_off: ‘Stopped’

You could use a template sensor based on your binary sensor:

- platform: template
  sensors:
    washing_machine:
      friendly_name: Washing Machine
      entity_id: binary_sensor.washing_machine
      value_template: >
        {% if is_state('binary_sensor.washing_machine', 'on') %}
          Running
        {% else %}
          Stopped
        {% endif %}

But a running device class would be more elegant and is worth a feature request. I’ve been thinking about asking for a capacity device class (full / empty).

Thanks.
I have already used this solution for now but I miss the color and shape changing icon when converting it to a sensor.
Yes a running device class would be nice.

Vote here:

This will give you chaging icons but not colours

- platform: template
  sensors:
    washing_machine:
      friendly_name: Washing Machine
      entity_id: binary_sensor.washing_machine
      value_template: >
        {% if is_state('binary_sensor.washing_machine', 'on') %}
          Running
        {% else %}
          Stopped
        {% endif %}
      icon_template: >
        {% if is_state('binary_sensor.washing_machine', 'on') %}
          mdi:restart
        {% else %}
          mdi:restart-off
        {% endif %}
1 Like

Nice, one way to change the colour would be to use custom-ui

For one of mine, I needed colour change so downloaded the icons from MDI, edited it in photoshop to be the correct colours (in this case red and green), saved them as PNGs in WWW folder and used entity_picture_template instead of the icon template. Bit of a faff but that’s why we like HA !

Still probably easier than installing and using custom-ui.

Just noticed on MDI that you can use advanced export and colour it there before dowloading it

1 Like

Yes i know the custom ui but think it is a bit too much just for the icon change.

Could you show an example of your entity_picture_template?

Something like this, need to change the colour of the icon using advanced export from MDI as PNGs and put them in the WWW folder

- platform: template
  sensors:
    washing_machine:
      friendly_name: Washing Machine
      entity_id: binary_sensor.washing_machine
      value_template: >
        {% if is_state('binary_sensor.washing_machine', 'on') %}
          Running
        {% else %}
          Stopped
        {% endif %}
      entity_picture_template: >-
        {% if is_state('binary_sensor.washing_machine', 'on') %}
          /local/restart_green.png
        {% else %}
          /local/restart_red.png
        {% endif %}

I have tried this now and it Works :slight_smile:
However the size of the icon differs a bit from the original mdi icon. What size have you choosen so it fits? I chose 24x24
I also see that the colors has to be adjusted to fit the default ones from HA.

Can’t really remember, I know it was a lot of trial and error scaling with Photoshop to get it to look the same. I only use picture elements cards now so I can use other icons than MDI.

I will try something :slight_smile: thanks

I’ve just discovered this:

I am using it to change icon colour based on state. For example, icon changing from green to red when door unlocked:

type: entities
title: Front Door Lock
show_header_toggle: false
style: |
    ha-card {
      background: var(--background-card-color);
    }
    #states div:nth-of-type(1) {
      --paper-item-icon-color: [[ if(lock.assa_abloy_yale_conexis_l1_sd_l1000_ch_locked == "unlocked", "red", "green)) ]];
    }
entities:
  - entity: lock.assa_abloy_yale_conexis_l1_sd_l1000_ch_locked
    name: Lock

How about the custom button card?

          - type: custom:button-card
            entity: cover.garage
            icon: mdi:garage
            color_type: icon
            label_template: >
              return 'Garage is currently: '
              + (states['cover.garage'].state ==='closed'
                ? '<span style="color: #00FF00;">closed</span>'
                : '<span style="color: #FF0000;">open</span>')
            show_label: true
            state:
              - value: 'open'
                color: red
                name: Open
              - value: 'closed'
                color: green
                name: Closed
            show_state: false
            tap_action:
              action: call-service
              service: input_boolean.toggle
              service_data:
                entity_id: input_boolean.garagedoor

image

Thanks but the OP just wanted to change an icon in an entity card and when you use icon template, it doesn’t change colour with state, he wanted a way to do that

I guess this is only for lovelace, which I don´t use. At least for now :slight_smile:
I have managed to modify the icons so the size now fits and it looks great.