Adding time to set_datetime

Hello again,

I try to figure out how I best handle delays for my lamps. For now, I understood that there are a better way then delays and timers. “Datetime” function should do the trick and is also reboot proof.

So far so good. I set up everything I need and now I don’t know how I can set my “DateTime” helper with a additional time. Lets say the actual time + 10 minutes. What do I have to write into here?

I think, it’s not possible to do this with the GUI. So I switched to YAML and try a code from another user and modified the minutes from 30 to 5:

alias: Flur-UG-Licht
description: ""
trigger:
  - platform: state
    entity_id:
      - input_select.flur_ug_bewegung
    from: null
    to: Bewegung erkannt
    id: Bewegung
  - platform: time
    at: input_datetime.flur_ug_licht
    id: Zeit
  - platform: state
    entity_id:
      - event.g_og_buro_wt_1_0_ch3
    id: Bewegung
    from: null
    to: null
condition: []
action:
  - choose:
      - conditions:
          - condition: trigger
            id:
              - Zeit
        sequence:
          - service: switch.turn_off
            data: {}
            target:
              entity_id: switch.g_ug_flur_licht_0_g_ug_flur_licht
      - conditions:
          - condition: trigger
            id:
              - Bewegung
        sequence:
          - service: switch.turn_on
            metadata: {}
            data: {}
            target:
              entity_id: switch.g_ug_flur_licht_0_g_ug_flur_licht
          - service: input_datetime.set_datetime
            metadata: {}
            data:
              timestamp: "{{ (now() + timedelta(minutes=5).timestamp()) | int(0) }}"
            target:
              entity_id: input_datetime.flur_ug_licht
mode: single

In the trace it shows an error with:

Error rendering data template: UndefinedError: 'datetime.timedelta object' has no attribute 'timestamp'

Is there a better way to do this?

Thanks and regards!

You have a misplaced )… as described in the error message, the template above is applying the timestamp() method directly to the timedelta object instead of the results of the time addition.

{{ (now() + timedelta(minutes=5)).timestamp() | int(0) }}