Help with splitting state using value template

Hi, I’m struggling with a value template and wonder if anyone can help me? I’ve tried a fair bit and read through the jinja documentation but I’m new to it so think I’m missing something! So far I’ve got:

value_template: >-
      {%- set line = value.split("\r\n") -%}
      {{ (line[2] }}

Which gives me a state of:

dev/md0        3.6T  506G  3.1T  14% /mnt

All I actually want though is the “14%” part as the state. I’ve tried a few things, split using &nsbp, things like that but I’m either barking up the wrong tree or I’m getting the formatting wrong because it’s not working!

Thanks in advance!

1 Like
value_template: >
  {{ value.split("\r\n")[2].split(" ")[14] }}

And if you want to get rid of the % symbol to be able to graph the state:

value_template: >
  {{ value.split("\r\n")[2].split(" ")[14]|replace("%","") }}

You can then add the % as a unit_of_measurement.

Thats worked perfectly, thanks so much for the help!
Looks like I was on the right lines but definitely the wrong format!

Can I just ask, why a . Between the splits and not a | as there is when replacing the %

.split() is a function.

|replace() is a filter.

Ah OK. Everyday’s a learning day! Thanks again

List of jinja filters (not sure if all are implemented):

https://jinja.palletsprojects.com/en/3.0.x/templates/#list-of-builtin-filters

And I don’t have a list of functions.