Subtract hours from sunset - adjustable with a slider

I’d like to create an automation that triggers a certain number of hours before sunset, based on an input_number slider - so it is configurable from the frontend.
I’m struggling with the time formatting and subtraction, can anyone please suggest how I do it?
thanks
Darren

Quick thought would be to create a template sensor based on input_datetime.sunset and offset by your input_number. Then set your automation(s) to reference this ‘value of a date/time helper’.

Use a template in the trigger

{{ as_local(as_datetime(state_attr('sun.sun', 'next_setting'))) - timedelta(hours=states('input_number.sunsetmin')|int) }}
1 Like