@CestLaGalere wrote:
I am trying to add a random amount of time to an input_datetime time field.
(see Add random_at: to platform: time)
I would like to do something like the following to add between 20 minutes and two hours to the current timeaction: service: input_datetime.set_datetime entity_id: input_datetime.lights_off data_template: time: "{{ now() | as_timestamp() | int + (range(1200, 7200)|random) | timestamp_custom('%H:%M:%S', False) }}"
however this doesn’t seem to work
I can run
time: "{{ now() | as_timestamp() | int | timestamp_custom('%H:%M:%S', False) }}"
or
time: "{{ (range(10, 3600)|random) | timestamp_custom('%H:%M:%S', False) }}"
which both work fine - what am I doing wrong please (I have looked at the templating and the jinja docn, as well as other template that add to temperatures ( such as {{ states(‘sensor.temperature’) | float + 1 }} ) and am stuck. Thanks
Posts: 4
Participants: 3