Templates - Getting max values from a mixed string

Hi All,

I’m trying to create some marine forecast cards with a bit more depth than my current ones.

From an endpoint, I currently get a HTML formatted blob of text that has the marine forecast for the next 5 days. This is easy to display as one block like the below:

.

However I’m working on a set of cards that will provide more information for each day. I’d like each card to have:

  • Day name and date
  • Tide times (2 sets of high and low)
  • Water Temp
  • Swell
  • Wind min, max
  • Forecast Text

To achieve this I’m going through and putting each of the above into their own sensor (or in some cases one sensor with multiple attributes).

Where I’m stuck is the Wind min, max values. I could probably serach for another endpoint to go grab this data directly from, however as I have the descriptions in the text above (e.g. “Friday: Northerly 30 knots, easing to 25 knots early and to northwest 15 knots in the afternoon. Rain, turning to showers”) I’d like to parse that text and pull out “30, 25, 15”, and arrive at a wind min of 15 knots and wind max of 30 knots.

Using this sensor as an example, does anyone know how I could achieve that?

There might be better ways but this is one method.

{% set string = "Friday: Northerly 30 knots, easing to 25 knots early and to northwest 15 knots in the afternoon. Rain, turning to showers" %}
{% set r = string | regex_findall("(\d*)\sknots") %}
{% set r = r | map('int', 0) | sort(reverse=false) %}
{{ r[0] }} # 15
{{ r[r|count-1] }} # 30