Value_template used truncate, but want type 'slice'


I have a sensor today where I get a long value in return.
I’ve used truncate earlier that works fine, but it takes the first X letters of the value.

Now I want to grab some text in the ‘middle’ and was hoping ‘slice’ would work, but no…

This is the current code:

  - platform: command_line
    name: NUC BIOS
    command: "cat /sys/class/dmi/id/bios_vendor"
    value_template: '{{value|truncate(18,True)}}'

The reason for value ‘18’ is to include the 18 periods after the truncated value.

How can I use my ‘value_template’ to get characters 7 to 15 to be the value of the sensor?

This should work:

"{{ value[6:15] }}"
1 Like

Thx @Tediore