Extracting value from string using templates

I have the following string turn_on_x_minutes (where x is an integer)
I’d like to extract x using a template to send it in a Telegram message

What’s the best way to do that ?
Thanks in advance

{% set str = 'turn_on_33_minutes' %}
{% set sub = str.split('_')[2] %}
{{ sub }}

Above code should work however long the number is…

2 Likes

Thank you for this ! :slight_smile: