Template newbie advice with offset to sun.sun entity

Having lots of fun over the past couple months moving my devices and automations from Homeseer to HA. I am starting to venture into tHavinghe world of templating. I have a need to collect on/off, time/duration, using the “history_stats” integration for a binary sensor that tracks each time outdoor brightness (lux) falls below 8500. I want to set the history_stats “start:” time based on sunset, modified by an offset (prior to). The "t_sunset_offset"code below provides the offset I am looking for. I am stumped on how to get the resulting H, M, S results, into the hour=, minute= second=, syntax of the “history_stats” integration. I appreciate any advice you can provide. TIA!.. Don

t_sunset_offset: “{{ ((as_timestamp(state_attr(‘sun.sun’, ‘next_setting’)) - 180*60) | timestamp_custom(’%H,%M,%S’)) }}”

{{ now().replace(hour=0, minute=0, second=0) }}

You don’t need to get them into the replace method because you can use the datetime object directly.

{{ state_attr('sun.sun', 'next_setting')
| as_datetime | as_local - timedelta(hours=3) }}
1 Like