Input_datetime.set_datetime with button

hello,

i have an input_datetime set to 1am every day to turn of the light in the living room.
i want to create two buttons, one increasing this input_datetime 15mins (on every button press +15 mins), the other decreasing. i already lerned that i need to call a script to do that, however i was only able to do the first +15min, it is not increasing more…how do i need to edit the script to do so?

service: input_datetime.set_datetime
data:
  time: >-
    {{ (states('input_datetime.time2sleep') | as_datetime | default(now(), true)
    + timedelta(minutes=15)).strftime('%H:%M') }}
target:
  entity_id: input_datetime.time2sleep

thanks for your help!

The first half of your template is going to default to now() every time, use today_at() instead of as_datetime:

service: input_datetime.set_datetime
data:
  time: >-
    {{ (today_at(states('input_datetime.time2sleep')) + timedelta(minutes=15)).strftime('%H:%M') }}
target:
  entity_id: input_datetime.time2sleep

thats it, thank you!