How do I send a notification when a door is opened after being closed for a week? (Useful for vacation or second home)

I’ve got a HA installed at my parents house. Now that they’re retired, they’re constantly traveling and I’d like to setup a notification when any of the doors are opened after being closed for a week. Below is the first pass I’ve taken at this but I’ve noticed it’s not working. My guess is that the conditional check will never be > 1 week because it inherently gets reset in order to trigger the automation.

In order to fix the issue described above, should make a new input_datetime that is set by an automation after 1 minute after any of the doors are opened and then update the notification automation to compare the week delta with that time?

alias: Door opened after a week - Telegram Alert
description: ''
trigger:
  - platform: state
    entity_id: binary_sensor.door_front
    to: 'on'
    from: 'off'
  - platform: state
    entity_id: binary_sensor.door_deck
    to: 'on'
    from: 'off'
  - platform: state
    entity_id: binary_sensor.door_basement
    to: 'on'
    from: 'off'
condition:
  - condition: template
    value_template: >-
      {{ (as_timestamp(now()) -
      as_timestamp(states.binary_sensor.door_front.last_changed)) > 604800 }}
action:
  - service: telegram_bot.send_message
    data:
      ...
mode: single

The only safe way to do that - would be to have an automation that stores the datetime in an input_text helper when the door is closed. Then an automation (even the same automation) that checks the datetime in the input_text helper when the door is opened and check if (now()|as_timestamp) - (states('input_text.door_last_closed')|as_timestamp) > 604800 (or something similar to that)

I made up the telegram part. Correct it. Note parallel mode.

alias: Door opened after a week - Telegram Alert
description: ''
trigger:
  - platform: state
    entity_id: 
      - binary_sensor.door_basement
      - binary_sensor.door_deck
      - binary_sensor.door_front
    to: 'off'
    for: '168:00:00'
action:
  - wait_template: "{{is_state(trigger.entity_id, 'on')}}"
  - service: telegram_bot.send_message
    data:
      message: "{{trigger.to_state.attributes.friendly_name}} has been opened"
mode: parallel
1 Like