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
trigger:
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 }}
action:
- service: script.my_notify
data_template:
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.