because 115.x doesnt like the older Enhanced Sun integration and throws errors on Sun integration not supporting triggers ( Integration 'sun' does not provide trigger support
), I took it out and try to rely completely on the core Sun integration and Sun2, with its extra sensors and attributes. Had some templates sensors that gave me todays time difference in daylight and other noteworthy timings, but those were all based on the attributes from the Enhanced Sun integration, I now no longer have…
below are my templates which are from this community, so must be floating around in older posts. I think I have managed to rebuild most of them (check the commented old code per template) but am stuck with a few daylight templates:
daylight_sec, daylight_hr and daylight_hms I need to get fixed.
Probably dead simple, but my eyes won’t see them correctly now I fear.
Please have a look and help me out here (and if you spot an error in the others, please dont hold back…:
sunset_offset:
friendly_name: Sunset offset
# entity_id: sensor.time #, sun.sun
value_template: >
{% set t = states('sensor.time') %}
{% set nw = as_timestamp(now()) %}
{% set ss = as_timestamp(states('sensor.astral_sunset')) %}
{{'- ' if nw < ss}}{{(nw - ss)|abs|timestamp_custom('%H:%M:%S',false)}}
sunrise_offset:
friendly_name: Sunrise offset
# entity_id: sensor.time #, sun.sun
value_template: >
{% set t = states('sensor.time') %}
{% set nw = as_timestamp(now()) %}
{% set ss = as_timestamp(states('sensor.astral_sunrise')) %}
{{'- ' if nw < ss}}{{(nw - ss)|abs|timestamp_custom('%H:%M:%S',false)}}
daylight_sec:
friendly_name: Daylight seconds ??ok??
value_template: >
{{states('sensor.astral_civil_daylight')|float*60*60}}
# {{state_attr('sun.sun','daylight')|int}}
unit_of_measurement: sec
daylight_hr: ??ok??
friendly_name: Daylight hours
value_template: >
{{(states('sensor.astral_civil_daylight')|float*60*60)|timestamp_custom('%H',false)}}
# {{(state_attr('sun.sun','daylight')/(60*60))|round(2)}}
unit_of_measurement: hr
daylight_hms: ??ok??
friendly_name: 'Daylight hh:mm:ss'
value_template: >
{{(states('sensor.astral_civil_daylight')|float*60*60)|int|timestamp_custom('%X',false)}}
# {{state_attr('sun.sun','daylight')|int|timestamp_custom('%X',false)}}
daylight_chg:
friendly_name: Daylight change from yesterday
value_template: >
{{(states('sensor.astral_civil_daylight')|float -
state_attr('sensor.astral_civil_daylight','yesterday')|float)|round(2)}}
# {{(state_attr('sun.sun','daylight') - state_attr('sun.sun','prev_daylight'))|int}}
unit_of_measurement: sec
daylight_remaining_min:
friendly_name: Daylight remaining minutes
# entity_id: sensor.time
value_template: >
{% set t = states('sensor.time') %}
{{((as_timestamp(states('sensor.astral_sunset')) - now().timestamp())/60)|int}}
# {% set t = states('sensor.time') %}
# {{((as_timestamp(state_attr('sun.sun','sunset')) - now().timestamp())/60)|int}}
unit_of_measurement: min
daylight_remaining_hm:
friendly_name: 'Daylight remaining hh:mm'
# entity_id: sensor.time
value_template: >
{% set t = states('sensor.time') %}
{{(as_timestamp(states('sensor.astral_sunset')) - now().timestamp())
|timestamp_custom('%H:%M', false)}}
# {% set t = states('sensor.time') %}
# {{(as_timestamp(state_attr('sun.sun','sunset')) - now().timestamp())
# |timestamp_custom('%H:%M', false)}}
thanks for having a look!