Template Sensor for Date

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!

Select Timestamp.

1 Like

Thanks so much! it works!

I have read about sun2 integration. But I don’t know if it is a good integration, it’s strange that it’s not on HACS repository … It is needed to add it manually to HACS repositories.
With regards,

1 Like