Having trouble using the local timezone time in a script

I’m having a heck of a time with this. I’ve gone through dozens of examples on the forums to try to get this working but just can’t get it dialed in.

What I’m trying to do is set the value of an input_datetime to be a random time between 20 and 60 minutes from now, but the first go around put it in UTC, so hours ahead. I tried all sorts of variations of local_timestamp or forcing the timezone and couldn’t get it to work right.

The best I’ve come up with so far is this one, and I’m just hard subtracting the offset, but even that really doesn’t set the time properly and when DST ends it’ll require a modification. How can I do this to the local timezone?

  - service: input_datetime.set_datetime
    entity_id: input_datetime.next_driveway_patrol
      time: "{{ (now().timestamp() - 21600 + range(1200, 3600) | random) | timestamp_custom('%H:%M', False) }}" 

This works for me (note the lower case “true” and use of data_template is no longer required.

  time: "{{ (now().timestamp() + range(1200, 3600) | random) | timestamp_custom('%H:%M', true) }}"

That is almost the same as I have now, I don’t have an issue writing to the input_datetime, its that when I use the same string as you typed out it puts it 7 hours ahead of me (and my HASS timezone is correct). I just need to figure out how to convert THAT value to local time.

The template I posted is in local time for me. Try it.

Ahh, yes, I mis-read your post, the way it was worded I read that “no longer required” and didn’t read into the fact that was two different statements rather than both being “no longer required”. The “true” is the fix!

Thank you so much!