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.