I am trying to create a single sensor for my irrigation system next watering time. Each zone has it’s own time so I wrote a template sensor to sort and take the first. This returns a “unknown” even though both sensors have a date for their next event. I also tried using the min function but same result.
If those sensors have dates, they will need to be converted from strings to datetime objects before sorting. You could also use min instead of sorting and picking the first. Based on Taras’ suggestion:
{{ ['sensor.1_next_cycle','sensor.5_next_cycle']
| map('states') | map('as_datetime') | min }}
Seeing that it was first to provide you with a detailed explanation and a working solution, please consider marking my post above with the Solution tag.