So how would people want to see this work ? It’s important to know that we cannot have functions available in templates to store variables because rendering a template cannot have a side effect. They obviously would be able to access it.
Have a script action:
action:
- variables.store:
key: my_var
type: datetime
value: >
{% if is_state("sun.sun", "above_horizon") %}
{{ states.input_datetime.something_1.state }}
{% else %}
{{ states.input_datetime.something_2.state }}
{% endif %}
If the value does not match the type, it would stop the script there with a fatal error.
And then in a template you can use:
{{ variables.my_var }} (this would be datetime object)