Question about template/automation setting time for helper

Good afternoon,
I’m new to home assistant and a bit puzzled - jumping from automations to yaml to scripts to templates…
I’m trying to convert my shutter programs from ioBroker to home assistant.

These are my first steps:
Manually set helpers:
input_datetime.rolladenaz_downearly holds the earliest (manual) time when the shutter may be closed.
input_datetime.rolladenaz_offset holds the + or - minutes from the sensor.sun_next_dusk

Helper to be set by automation or template sensor (what is better?):
input_datetime.rolladenaz_downtime This is the wanted time in a separate (!) helper for later automations and the possibility to display this time in a dashboard.

In an automation or template sensor (?) the following should happen:
input_datetime.rolladenaz_downtime should be set to the time of sensor.sun_next_dusk if it is later than
input_datetime.rolladenaz_downearly otherwise to input_datetime.rolladenaz_downearly.

The problems I have is with the new syntax. How can I set my helper
input_datetime.rolladenaz_downtime?

Thank you!

That is not very clear. I have no idea what the “it” in this refers to “if it is later than”. Current time? next dusk? down early?

Anyway this should give you a hint on how to do it even if you need to adjust the logic:

actions:
  - if:
      - condition: template
        value_template: "{{ states('input_datetime.rolladenaz_downearly')|as_datetime > states('sensor.sun_next_dusk')|as_datetime }}"
    then:
      - action: input_datetime.set_datetime
        target:
          entity_id: input_datetime.rolladenaz_downtime
        data: 
          datetime: "{{ states('sensor.sun_next_dusk')|as_datetime }}"
    else:
      - action: input_datetime.set_datetime
        target:
          entity_id: input_datetime.rolladenaz_downtime
        data: 
          datetime: "{{ states('input_datetime.rolladenaz_downearly')|as_datetime }}"

You may also need to use the |as_local time filter. Try it out in the developer tools → template editor.

Thank you!