Add minutes to string

Hi,

I have a script that generates heating on/off times along with temperature set points. At the moment I have times for when kids are at school and times for when they are at home.

The time is printed as ‘07:30’ as a string and my question is, is there a way of adding a timedelta to this string? For example

delta = 30
timeam = " ‘07:30’"
timeam2 = timeam + timedelta(minutes=delta)

variables:
  delta: 30
  timeam: "07:30"
  timeam2: "{{ (timeam ~ ':00') | as_timedelta + timedelta(minutes=delta) }}"

(as_timedelta requires the time to include seconds)

Thank you.

Having added a replace (to remove the ’ ’ either side of the time), this is the output I get

time2am= (timeam ~ ‘:00’) | replace(“'”,“”) | as_timedelta + timedelta(minutes=delta) %}

timeam - ‘07:00’
timeam2 - 7:30:00

how do I get timeam2 to appear as ‘07:30’ instead of 07:30:00 (seconds removed, single quotation marks added)

Either use the removesuffix function or the strptime filter/function.

If you want exact code to just copy-paste, post your complete code. It is pretty messy and difficult to understand what is supposed to be HASS/YAML and what is a Jinja template.

variables:
  delta: 30
  timeam: "07:30"
  timeam2: "{{ (today_at(timeam) + timedelta(minutes=delta)).strftime('%H:%M') }}"