As you can see, the automation discriminates watering from one hour before sunset to sunrise and from one hour after sunrise to sunset as the irrigation intervals can be different.
Now I would need to create a label with custom button card that tells me:
Next watering: datetime.
How can I do?
{% set x = states('input_select.choicedaywateringinterval') | int + states('input_number.irrigationduration') | int %}
{% set ns = namespace(n_min=[]) %}
{% for h in range(0,24) if h >= now().hour%}
{% for m in range(0, 56, 5) -%}
{%- set mod0 = ((h*60) + m) % x -%}
{%- set dt = today_at(h|string~':'~ (m|string if m < 10 else '0'~m|string)) %}
{%- set ns.n_min = (ns.n_min + [dt]) if (mod0 == 0 and dt >= now()) else ns.n_min %}
{% endfor %}{% endfor %}
{{ (ns.n_min) | reject('<=', state_attr('sensor.sun_rising', 'today') | as_datetime)
| reject('>', state_attr('sensor.sun_setting', 'today') | as_datetime + timedelta(hours=1)) | map("string") | first | default('None Scheduled', 1) }}
NOTE: This template uses sensors from the Sun2 custom integration something similar can be created using a trigger-based template sensor if you don’t want to use Sun2.
EDIT: Fixed typo noted below and updated rising and setting sensor reference to use today attribute.
I created similar templates to yours and still get the correct results. I think we can eliminate your sensors. Check the sun sensors in Developer Tools to see if they are currently showing dates