Show last characters from sensor state on cards

Hello,

i cannot find a way to only display the last characters off a sensor state on a card

sensor state is : ENGINE_HOOD_STATUS_CLOSED

In only want to display on a card closed or open

I have 20 more sensors from the car same issue , state output text is too long.

How can i do that ?

it depends on what you know about the text. if you always have the front 19 characters always the same like this:
ENGINE_HOOD_STATUS_CLOSED and
ENGINE_HOOD_STATUS_OPEN

you could do

{{ states('sensor.your_sensor')[19:] }}

or you split it up by the _ and grab the nth item:

{{ states('sensor.your_sensor').split('_')[3] }}

or if you know it’s the last one you can do:

{{ states('sensor.your_sensor').split('_')[-1] }}

does that get you what you want?

1 Like

Can i use it directly in the fronted card yaml code?

I tried this >> Entity Card configuration

  • entity: sensor.lynk_co_door_engine_hood_status
    icon: mdi:car
    name: Motorkap
    state: {{ states(‘sensor.your_sensor’).split(‘_’)[3] }}

but that is not working., thanks for your reply

not all dashboard cards accept jinja templates.

unforunately entity card does not. but cards like markdown does. so it’ll depend on the card you choose… and the card you choose will depend on what funcationlity and look you want…

if for some reason you must use the entity card, you could create a template sensor (go to helpers and create a template sensor) then put that template i gave you above into it. that will create a simple entity that has just this state. then you can put that entity into an entity card… however i suspect you’re better off with a more interesting card than the entity card.

I tried the markdown , but i am just learning home asssitant so not sure how to do it right.

i used this code in the markdown card , is not working can you correct the code

  • entity: sensor.lynk_co_door_engine_hood_status
    icon: mdi:car
    name: Motorkap
    state: {{ states(sensor.lynk_co_door_engine_hood_status).split(‘_’)[3] }}

Again many thanks, if i get this working then i can add the other sensors from the car.

i’m not sure what all you’re trying to show and accomplish in the card, but here’s a start for you.

type: markdown
content: >-
   {{ states('sensor.lynk_co_door_engine_hood_status').split('_')[3] }}

  The **Markdown** card allows you to write any text. You can style it **bold**,
  *italicized*, ~strikethrough~ etc. You can do images, links, and more.

  For more information see the [Markdown
  Cheatsheet](https://commonmark.org/help).

the documentation for markdown is here:

it looks to me like you may have just taken the entity card yaml and used it on markdown… that won’t work. markdown’s a totally different card.

also, if you post yaml, please be sure to use the preformatting tags in this forum. that way it will format like mine above. the spacing and all are very important, so the formatting is important. use the </> icon in the post toolbar to do this.

EDIT: whoops. missed a close quote. fixed

Thank you,

I used >>

#### Open / dicht
<ha-icon icon="mdi:car"></ha-icon>  Motorkap: &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {{states('sensor.lynk_co_door_engine_hood_status').split('_')[3] }} 
<ha-icon icon="mdi:car-door-lock"></ha-icon> Driverdoor:&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {{ states('sensor.lynk_co_door_lock_status_driver')[17:]  }}
<ha-icon icon="mdi:car-door-lock"></ha-icon> Passenger:&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {{ states('sensor.lynk_co_door_lock_status_passenger')[17:] }}

<<
I tried to align the text with ‘& nbsp;’ which provides a " ". of course is this not an optimal result.

Is there a way to align the sensors text outputs to the right of the card. ?

deuren Knipsel

Markdown tables should work:

1 Like