I’m trying to do this:
condition: template
value_template: >-
"{{ states('counter.greet_{{ states('sensor.time_of_day') }}_{{ state_attr(' {{
trigger.entity_id }} ','matches') }}' < 1) }}"
But i keep getting:
Message malformed: invalid template (TemplateSyntaxError: expected token ',', got 'sensor') for dictionary value @ data['condition'][0]['value_template']
If i remove the “{{ and }}” at the beginning and end i get no errors, but then it keeps saying the condition failed and it shouldn’t (these counters are all set to 0). I guess that’s a good thing, but i cannot see where this fails.
For clarity :
I am saying good morning/noon/evening using a timer day sensor and double_take_sensors.
I have counters set for every recognised person so that they don’t get more then 1 good morning/noon/evening per time of day e.g.:
counter.greet_morning_
These are all set to 0 and are incremented when the automation has ran at the end.
Full code for clarity’s sake:
alias: Greet person based on time of day
description: >-
Good morning that uses face recognition (Compreface and Doubletake) and the
time of day sensor to recognise the person who it sees.
It uses double_take_camera and checks if there is a match, then says good
timeofday using the appropriate alexa using a trigger.id then delays by the
defined time in time of day sensor so it only runs once.
trigger:
- platform: state
entity_id:
- sensor.double_take_kitchen
attribute: matches
id: garage
- platform: state
entity_id:
- sensor.double_take_diningroom
attribute: matches
id: dining_room
condition:
- condition: template
value_template: >-
"{{ states('counter.greet_{{ states('sensor.time_of_day') }}_{{
state_attr(' {{ trigger.entity_id }} ','matches') }}' < 1) }}"
action:
- service: notify.alexa_media_{{ trigger.id }}
data:
message: >-
Good {{ states('sensor.time_of_day') }} {% set f = state_attr('{{
trigger.entity_id', 'matches') %} {{ f[0].name if f is iterable and
f|count > 0 and f[0].name is defined else "Unrecognized" }}.
data:
type: tts
method: all
- service: counter.increment
data: {}
target:
entity_id: >-
counter.greet_{{ states('sensor.time_of_day') }}_{{ state_attr('{{
trigger.entity_id }}','matches') }}
mode: single
Appreciate the help.