Template entity from Sun Integration

Hello Guys,

Would anyone be able to tell me if it is possible to create an entity based on the Sunset and Sunrise times listed in the Sun.sun entity?

Yes, it’s possible, with a Template Sensor, but what is the goal given that the information is already accessible from the sun.sun entity?

If it’s just to display the next sunrise/sunset in the UI, in what date/time format do you want the result to be shown?

Examples:

Hello,

Thank you for the reply, your suggest seems to work in the developer tool however when I attempt to create the sensor in my configuration file I am given the following error:

  - platform: template
    sensors:
      sunrise:
        friendly_name: 'Sunrise'
        value_template: '{{state_attr('sun.sun', 'next_rising') | as_datetime | as_timestamp | timestamp_custom('%-H:%M')}}'

Not sure why but if a tweak the code slightly changing the ’ to " it seems to fix the issue.

thanks for your help

  - platform: template
    sensors:
      sunset_time:
        friendly_name: 'Sunset'
        value_template: '{{state_attr("sun.sun", "next_rising") | as_datetime | as_timestamp | timestamp_custom("%-H:%M")}}'

If you use single-quotes inside a template, you have to use double-quotes outside the template.

If you use double-quotes inside a template, you have to use single-quotes outside the template.

You can’t use the same kind quote inside and outside the template.