Help on automation multi based condition on template

HI,

I have an irrigation system. I made a lovelace card to configure it. In the card, I can choose between 3 options: sunrise, sunset or specific time.

They are all exclusive, only one is activated at a time.

On my automation condition, I created a template to test all conditions:

{% set agora_ts = as_timestamp(now()) -%}
{% set nascerdosol_ts = as_timestamp(state_attr("sun.sun", "next_rising"))  -%}
{% set pordosol_ts = as_timestamp(state_attr("sun.sun", "next_setting"))  -%}

{% set agora = agora_ts | timestamp_custom("%H:%M") -%}
{% set nascerdosol = nascerdosol_ts | timestamp_custom("%H:%M") -%}
{% set pordosol = pordosol_ts | timestamp_custom("%H:%M") -%}

 
{%- if is_state("input_boolean.rafis_nascer_do_sol", "on") %}
    {% if (agora == nascerdosol) -%}
       true
    {%- else %}
       false
    {%- endif %}
{%- elif is_state("input_boolean.rafis_por_do_sol", "on") -%}
    {% if (agora == pordosol) -%}
       true
    {%- else %}
       false
    {%- endif %}
{%- elif agora ==  states("sensor.hora_irriga_rafis") -%}
       true
{%- else %}
       false
{%- endif %}

Th problem is that it is nor working. The tests are OK , but I think the problem is that when I activate it on sunset, I get sunset time and now() time. And since it is activated at sunset, after that when I get the sunset on the template it is getting the next sunset (next day), may it be true ? Or are there another error I’m not seeing here ?

Thanks.

What is the automation’s trigger? Please post it as well.

Sorry, now I see it was incomplete to full understand.

But while responding to this, I thought about what I did and found out that I was doing unnecessary tests (but I’ll leave this topic because this doubt is good and I may need on future projects). Let me explain.

Trigger is sunset or sunrise or manual time configured.
Any of them starts automation. I also have a interval (input_number, in days) so that the irrigation must engage not before this time.
Everytime the irrigation starts, I store on a input_datetime the last time it was activated, to calculate with next automation start and test if the interval has passed.

I was checking all of those conditions, because I need to calculate if the time was passed. But I realised that since the minimum interval time is 1 day, I don’t. need to make all checkings, I just need to test to see if the interval has passed, because if the time configure is sunrise, and the interval is 1 day, only on the next sunrise the condition will be true.

But thanks anyway for any help, I am still curious about if when I check the sunrise or sunset after a trigger of the same event occurs, the value will be of the next day or still the current day…

Best regards…