Read through the threads. Trying to set up a sub attribute condition.
- condition: or
conditions:
- condition: template
value_template: {{ state_attr('sensor.double_take_kalitka','matches')["name"] == "andrey" }}
And this is what i get in return
I have already tried various combinations
jchh
((not John))
July 25, 2023, 7:03pm
2
Try
- condition: template
value_template: “{{ state_attr('sensor.double_take_kalitka','name’) = ‘andrey’ }}”
Btw, by ‘name’, do you mean friendly_name
?
No. It’s a sub attribute “name” for the “matches” attribute in the cam config. And i believe it’s missing in your suggestion. In this case you are calling attribute “name”
Something like over here https://community.home-assistant.io/t/working-with-nested-attributes-in-a-template/282716
Show the entity info from the States tool… we need to know if matches
is a list or dictionary. Also, your template is missing quotes…
1 Like
Can you share both templates for the better understanding?
What is returned when you paste the following in the template editor?
{{ state_attr('sensor.double_take_kalitka', 'matches') }}
Troon
(Troon)
July 25, 2023, 9:52pm
7
Rule 1:
Templating - Home Assistant (home-assistant.io)
value_template: "{{ state_attr('sensor.double_take_kalitka','matches')['name'] == 'andrey' }}"
1 Like
Guess i was too early.
This are the attributes for the sensor
id: b4e75ff9-8fc5-4cb9-b769-d8a901axxxx
duration: 1.3
timestamp: 2023-07-26T07:23:07.302Z
attempts: 1
camera: kalitka
zones:
matches:
- name: andrey
confidence: 99.82
match: true
box:
top: 282
left: 1002
width: 489
height: 594
type: mqtt
duration: 0.46
detector: compreface
filename: 8ad68add-d664-427d-bdca-376f73e12690.jpg
base64: null
misses:
unknowns:
personCount: 0
counts:
person: 0
match: 0
miss: 0
unknown: 0
icon: mdi:camera
friendly_name: double_take_kalitka
[
{
"name": "andrey",
"confidence": 99.82,
"match": true,
"box": {
"top": 282,
"left": 1002,
"width": 489,
"height": 594
},
"type": "mqtt",
"duration": 0.46,
"detector": "compreface",
"filename": "8ad68add-d664-427d-bdca-376f73e12690.jpg",
"base64": null
}
]
Troon
(Troon)
July 26, 2023, 7:48am
10
So it’s a list. This is why supplying all the relevant information up front is so important .
value_template: "{{ state_attr('sensor.double_take_kalitka','matches')[0]['name'] == 'andrey' }}"
1 Like
I don’t use DoubleTake, so this may not be a big enough issue to bother with, but that condition may fail if multiple matches occur at the same time and “andrey” isn’t in the first position.
If this is an issue you experience, you can try the following:
{{ state_attr('sensor.double_take_kalitka', 'matches')
| map(attribute='name') | list is search('andrey')}}
If you need to check multiple names use a pipe (|
) between names (no spaces) in the last function.
{{ .... is search('andrey|person2') }}
1 Like