Quantcast
Channel: Configuration - Home Assistant Community
Viewing all articles
Browse latest Browse all 95437

Adding a random time to input_datetime (for lighting)

$
0
0

@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 time

action:
  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

Read full topic


Viewing all articles
Browse latest Browse all 95437

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>