As_timestamp subtracted by automation.last triggered not working

I cant get my following automation to work, could anybody help me what I have done wrong?
I want the following goal:

I have an automation “telegram_marked_done” which is an automation triggered by a telegram chat. So when I write in telegram /done this automation gets triggered.

Now I want another automation: If I havent triggered the automation “telegram_marked done” in the last 2,5 hours at 22:30 o clock and if I am at home (located by google maps) I want my google home to speak “you have forgotten to mark as done”
I believe the following code is wrong: ‘{{ as_timestamp(now()) - as_timestamp(states.automation.telegram_marked_done.last_triggered) | int > 220 }}’

Here is my complete current code:

  - alias: 'Not marked as done'
    hide_entity: true
    initial_state: on
    trigger:
      - platform: time
        at: '22:30'
    condition:
      condition: and
      conditions:
        - condition: template
          value_template: "{{ states.device_tracker.google_maps_116561.state == 'home' }}"
        - condition: template
          value_template: '{{ as_timestamp(now()) - as_timestamp(states.automation.telegram_marked_done.last_triggered) | int > 220 }}'
    action:
      service: tts.google_translate_say
      entity_id: media_player.schlafzimmer
      data:
        message: 'You have forgotten to mark as done'

Try casting to int as_timestamp(now)) in the value_template for your second condition.

value_template: '{{ as_timestamp(now()) - as_timestamp(states.automation.telegram_marked_done.last_triggered) | int > 220 }}'

should be

value_template: '{{ as_timestamp(now()) | int  - as_timestamp(states.automation.telegram_marked_done.last_triggered) | int > 220 }}'

last_triggered is not a direct field of a State object, but rather a field under attributes. Try this:

value_template: '{{ as_timestamp(now()) - as_timestamp(states.automation.telegram_marked_done.attributes.last_triggered) | int > 220 }}'

Or better yet:

value_template: "{{ as_timestamp(now()) - as_timestamp(state_attr('automation.telegram_marked_done', 'last_triggered')) | int > 220 }}"
1 Like

Great, thank you! That was it. Now its working fine