Settting custom values for states

Hello All

I am trying to create a display for the door sensors on all doors. Currently the sensor is displaying the value 22 and 23 (for open and close). What I wanted to know is, can I change this so that I can either see open or close. Ideally I would like to see a toggle button which is highlighted if door is closed and not if door is open. Can I achieve this?

Here is the code that I used in the Yaml file.

group:
  default_view:
    view: yes
    entities:
      - group.front_main_door
  front_main_door:
    name: All Doors
    view: no
    entities:
      - sensor.ecolink_unknown_type0004_id0002_access_control_3_9
      
  front door1:
    name: FrontDoorOther
    view: no
    entities:
      - binary_sensor.ecolink_unknown_type0004_id0002_sensor_3_0
      - sensor.ecolink_unknown_type0004_id0002_alarm_level_3_1
      - sensor.ecolink_unknown_type0004_id0002_burglar_3_10
      - sensor.ecolink_unknown_type0004_id0002_power_management_3_11
      - sensor.ecolink_unknown_type0004_id0002_sourcenodeid_3_2
      - sensor.ecolink_unknown_type0004_id0002_access_control_3_9
      - sensor.ecolink_unknown_type0004_id0002_alarm_type_3_0

Kindly help me out. Thanks

Take a look at this: https://home-assistant.io/components/sensor.template/

~Cheers

A template sensor, or template binary_sensor, is what you’re after. Here’s what I used for a garage door sensor:

- platform: template
  sensors:
    garage_door:
      friendly_name: 'Garage door'
      value_template: '{% if is_state("sensor.garage_sensor_11_1", "255") %} open {% else %} closed {% endif %}'

If you use a binary sensor, then the icon changes colour when open. There are many worked examples to be found from the links above.

I’ve tried modifying the template provided on the template documentation and applying it in http://[my IP]:8123/developer-tools/template and, while the sample output window on the right appears correct (new values correspond to old state values) the states are not updating accordingly in the Lovelace UI. Is there another step that needs to happen to get the changes to reflect there?

You can make a template sensor to display open/closed so you can display as you wish in lovelace. You can also use the sensor in automations but that seems silly.

#Make the sensor show Closed or Open
sensor: 
  - platform: template
    sensors:
      mydoor_sensor:
        friendly_name: "1 Door Open-Closed"
        unique_id: "single_garage_door_open_closed_sensor"
        value_template: >-
          {% if is_state('binary_sensor.door1', 'off') %}
            closed
          {% elif is_state('binary_sensor.door1', 'on') %}
            open
          {% endif %}

edit: -I cut out of my sensor.yaml file and didn’t add in the ‘sensor:’ to start

i copied from another post