Add a value (string) to current time

Ah, OK — try this:

          value_template: "{{ as_timestamp(now() + timedelta(hours = states('sensor.battery_duration')|int)) | timestamp_custom('%H:%M') }}"

Your sensor state is a string and needs converting to an int (or float if you need fractional hours) to add to the timestamp.

Always use Developer Tools / Templates for debugging this sort of thing. I pasted my prior attempt in, replaced your sensor with one that exists in my setup, and got this:

TypeError: unsupported type for timedelta hours component: str

which tipped me off as to where the problem was.

1 Like