Help for welcome automation


I made this automation to send a welcome message based on person status and last update of my front door:

- id: Benvenuto HUB
  alias: Benvenuto
  initial_state: true
    platform: template
    value_template: >
      {{ is_state('person.marco','home') and
        (now() - states.person.marco.last_changed).total_seconds() < 5*60 and
        (now() - states.binary_sensor.porta_ingresso.last_changed).total_seconds() <> 5*60 }}
    - service: script.my_notify
        call_no_annuncio: 1
        title: Benvenuto
        message: >
          {% set person = trigger.entity_id.split('.')[1]|replace('_', ' ')|capitalize %}
          {%- macro benvenuto(person) -%}
          {{ [
          "Bentornato a casa " ~person~" ",
          "Indovina chi è a casa? è " ~person~" ",
          person + " è ora in casa. ",
          ] | random }}
          {%- endmacro -%}
          {{ benvenuto(person) }}

The issue is that it never get trigged and that even if code seems correct using vscode i receive a persistent notification that my automations (all of them can be loaded after reboot).

Can someone please point me in the right direction?

Check your templates in Developer tools -> Templates and you’ll see that the trigger is evaluated when those two entities update - person.marco and binary_sensor.porta_ingresso. The use of now() is ignored, or the template would be getting evaluated every second (or faster).

Instead you want a couple of triggers and conditions.

Maybe something like this?

      - platform: state
        entity_id: person.marco
        to: 'home'
        for: '00:01:00'
      - wait_template: "{{ states.binary_sensor.porta_ingresso.state == 'on' }}"
      - delay: 00:00:01 

But I can I abort the automation if the wait_template action doesn’t happen in for example five minutes?

Yes, and see the docs for the wait_template. However, you may instead want the wait_for_trigger option.

I’ll do some tests and post the results so it will be used by anybody.

In the meantime, thanks! :slight_smile:

Here I am.

This config works:

      - platform: state
        entity_id: person.marco
        # from: 'not_home'
        to: 'home'
      - wait_for_trigger:
        - platform: state
          entity_id: binary_sensor.porta_ingresso
          to: 'on'

Thank you!

1 Like