I have difficulties in getting the below automation to output a value to ‘input_datetime.drip1_next_run_time’. The template gives the right values when testing in Jinja2.
It is supposed to output the next time for the drip irrigation based on the time of the day. If the sun is above horizon and the drip irrigation is enabled it just add the interval time and if the sun is below horizon and the drip irrigation is enabled the next drip time will be at sun rise next day as it is not supposed to run in the night.
I haven’t been able to figure it out by searching the forum.
- alias: Set drip1 next scheduled run time
trigger:
- platform: state
entity_id: input_boolean.drip1_valve
to: "off"
for: "00:00:05"
action:
- service: input_datetime.set_datetime
entity_id:
- input_datetime.drip1_next_run_time
- service: >
{% if is_state('input_boolean.drip1_enable' , 'on') and is_state('sun.sun' , 'above_horizon') %}
{{(state_attr('input_datetime.last_drip1_time', 'timestamp') + (states('input_select.drip1_interval_time') | int * 3600)) | timestamp_custom('%d-%m-%Y at %H:%M') }}
{% elif is_state('input_boolean.drip1_enable', 'on') and is_state('sun.sun', 'below_horizon') %}
{{ (as_timestamp(states.sun.sun.attributes.next_rising)) |float| timestamp_custom('%d-%m-%Y at %H:%M')}}
{% else %}
None
{% endif %}