How to display a trigger time taking into account the for time

Hello,

I have this automation :

  - entity_id:
      - person.alex_bostoen
    to: home
    id: alex_bostoen is thuis
    trigger: state
    for:
      hours: 0
      minutes: 0
      seconds: 1
...

          - data:
              titel: >
                {% set x = trigger.id %} {% set x = x.replace(' is
                thuis','').replace(' is weg','').replace(' is zeker weg','') %}
                {% set y = x.split('_') %} {{ y[0].capitalize() + ' ' +
                y[1].capitalize() + ' is ten huize Bostoen' }}
              boodschap: >
                {{'Thuisgekomen op ' + now().timestamp() |
                timestamp_custom('%d/%m/%Y') + ' om ' +  (now() -
                timedelta(seconds = trigger.for.seconds|int(0) )).timestamp() |
                timestamp_custom('%H:%M:%S')}}
              notificatie: false
              mail: true
              tts: true
              tts_boodschap: >-
                {% set x = trigger.id %} {% set x = x.replace(' is
                thuis','').replace(' is weg','').replace(' is zeker weg','') %}
                {% set y = x.split('_') %} {{ y[0].capitalize() + ' ' +
                y[1].capitalize() + ' is aangekomen' }}
            action: script.berichten


This works great !

But how take into account the number of minutes… ?

I did this :

          - data:
              titel: >
                {% set x = trigger.id %} {% set x = x.replace(' is
                thuis','').replace(' is weg','').replace(' is zeker weg','') %}
                {% set y = x.split('_') %} {{ y[0].capitalize() + ' ' +
                y[1].capitalize() + ' is ten huize Bostoen' }}
              boodschap: >
                {{'Thuisgekomen op ' + now().timestamp() |
                timestamp_custom('%d/%m/%Y') + ' om ' +  (now() -
                timedelta(minutes = trigger.for.minutes|int(0), seconds = trigger.for.seconds|int(0) )).timestamp() |
                timestamp_custom('%H:%M:%S')}}
              notificatie: false
              mail: true
              tts: true
              tts_boodschap: >-
                {% set x = trigger.id %} {% set x = x.replace(' is
                thuis','').replace(' is weg','').replace(' is zeker weg','') %}
                {% set y = x.split('_') %} {{ y[0].capitalize() + ' ' +
                y[1].capitalize() + ' is aangekomen' }}
            action: script.berichten

But get this error ?

What am I missing here ?

A timedelta has no minutes attribute, as internally it only stores days, seconds and microseconds.

Which exact part of the template is throwing the error? I am guessing the trigger.for, as that is the only part where you are attempting to access a minutes attribute.

Just get rid of that part entirely as whatever you may or may not have specified in minutes as part of the trigger will be baked into the value for seconds.

Also, since trigger.for is apparently already a timedelta, there is no point in creating a new timedelta – just do the subtraction as-is:

now() - trigger.for

Thank you ! :ok_hand: