Trigger based on time unless sunset started (node red? template sensor?)

I live in Sweden which has very dramatic changes in light levels over the year.

Normally I would trigger an automation at 19:00 (I have a time helper called ‘evening’) but I need this to trigger earlier if sunset has started. I use this to set lighting scenes in the house.

I’d like to avoid repeating the same logic for every automation trigger. I have some basic knowledge of template sensors but I don’t know how to compare times (or get the current sunsetStart time.

Something like:
if sunsetStart > 19:00 then return 19:00 else return sunsetStart

Can someone please point me in the right direction?

you don’t necessarily need to know the time of sunset. you just need to know which happens first - sunset or 1900.

so you could use this template in a binary sensor:

{{ is_state('sun.sun', 'below_horizon') or now().hour >18 }}

the above will be true when it’s after sunset or after 1900 whichever is first. then it reverts to false at sunrise.

then just use the binary sensor in the trigger