Hi!
I have created a template to get today’s sun setting and it works in developer section of home assistant. But when adding new template and I select sensor type Date it shows unknown in the preview.
{% set currentDay = now().day %}
{% set nextSetting = state_attr('sun.sun', 'next_setting') | as_datetime | as_local %}
{% if (currentDay == nextSetting.day) %}
{{ nextSetting }}
{% else %}
{{ nextSetting - timedelta(days = 1) }}
{% endif %}
I suppose that the problem is the data type but I have tryed in several ways searching on the forum and didn’t works.
Thanks for your help!

