Removing (splitting) output to only show some of the entity output

I have managed to get my charger to display output for some fields in HA using mqtt. But I need help to only display time as hh:mm:ss and not hh:mm:ss.xxxxxxxx where x is a decimal value 0

Also when displaying the speed of the charge as slow, fast etc it always prefixes with ChargingSpeed. Then slow fast etc. how do I hide the ChargingSpeed. Part of the out put




Thanks in advance

Please dont post pictures of text. Post the actual text formatted correctly for the forum. It helps us help you as we can copy and paste.

What Tom said ^

See the value_template setting here:

For the first one, add:

value_template: "{{ value.split('.')[1] }}"

to your sensor configuration, then reload manual MQTT entities from the Developer Tools / YAML page.

You could also add |lower or |title if you don’t want ALL CAPS:

For the second one, we’d need to know when the MQTT topic message actually is. If it is the string 3:30:00.000000, then almost the same answer:

value_template: "{{ value.split('.')[0] }}"

but if that doesn’t work, you’ll need to get us the topic content.

apologies phone wouldn’t allow copy and paste from HA.

1 Like

Thank you so much - exactly what I needed on both accounts.

Does the [0] indicate the side of the split to use - either before or after?

It amazes me how many people are editing HA from mobile devices.

It is really not the best way. Though I can understand making quick edits on the go, you should be using a desktop PC for the majority of your config editing. It’s a much better experience.

I do, but with a quick question being put up last night when the laptop battery was flat, I went for the screenshot method, a one off and as I believed it would need a one line answer as @Troon kindly did, I believed copy and paste would not play a part of it.

1 Like

Yeah ok. It’s my standard response when I see people posting pictures of text. If I’d clicked your profile I would have seen you are not a new user and have many correctly formatted posts.

1 Like

It’s more than just a side of the split, it’s the index of the resultant list (and it’s zero-based, so the first item is [0]). Example:

{{ "one, two, three, four, five".split(', ') }}

1 Like

nearly, split generates an array (or I guess list in Jinja?) so for example:

{% set tmp = "01/02/2024" %}
{{ tmp.split("/")[2] }}

In computer code, counting typically starts at 0, so:

[0] - 01
[1] - 02
[2] - 2024

1 Like