Get max time between sunset hour and an int [Solved]

I live in a country where sunset ranges from around 4pm in winter to 10pm in summer.
My ikea lights are turned on by home assistant at sunset and they go off at 10pm.
I’d like to ensure that the earliest they come on is 6pm.
max(int(sun.sun.sunset.hour), 6)

Any ideas how this could be done with templates?

Thank you for your help, newbie here.

If you are using an automation you could do it this way, no templates required:

trigger:
  - platform: time  # trigger at sunset and at 6pm
    at: "18:00:00"
  - platform: sun
    event: sunrise
condition:
  - condition: state   # must be after sunset AND after 6pm
    entity_id: sun.sun
    state: 'below_horizon'
  - condition: time
    after: '17:59:59'
action:
   ...

If sunset is before 6pm the time condition wont allow the lights to turn on. It will trigger again at 6pm and will turn on.

If sunset is after 6pm the conditions wont allow the 6pm time trigger to turn the lights on, but the trigger at sunset will.

Thank you Tom.
This looks like it will do the trick!
Marked as solved.

No problem. There’s a button to mark posts as solved. Look at the icons under my post, it’s the check-box icon.

automation:
- alias: 'Front Entrance Light'
  trigger:
    - platform: time
      at: "17:30:00"
    - platform: sun
       event: sunset
  condition:
    condition: and
    conditions:
      - condition: state
         entity_id: sun.sun
         state: 'below_horizon'
      - condition: time
        after: '17:29:59'
  action:
    - service: light.turn_on
      entity_id: light.my_light
1 Like

Your indentation is a bit off in a few places. Corrected indention highlighted with ###. Also you dont need to specify AND for the conditions. That’s what they are by default.

automation:
- alias: 'Front Entrance Light'
  trigger:
    - platform: time
      at: "17:30:00"
    - platform: sun
      event: sunset ###
  condition:
    - condition: state
      entity_id: sun.sun ###
      state: 'below_horizon' ###
    - condition: time
      after: '17:29:59'
  action:
    - service: light.turn_on
      entity_id: light.my_light

Thanks again Tom!