Getting an attribute from an entity

Hi

So I succeeded doing a full setup for face recognition (with Deepstack) and it all works well.
When the camera recognizes me I get this -

You can see that my name “Tzahi” appears.

My question is how do I trigger an automation based on this? What do I need to write under attributes?
I tried this, but it didn’t work -

alias: Face recognition - Tzahi
description: ''
trigger:
  - platform: state
    entity_id: image_processing.face_counter
    attribute: faces
    to: Tzahi
condition: []
action:
  - service: media_player.play_media
    data:
      media_content_id: 'file:///media/welcome_tzahi.mp3'
      media_content_type: music
    target:
      entity_id: media_player.mopidy_pi
mode: single

Yea, I know this is stupid that I managed to do this super complex setup but I don’t understand the basics…

Thanks

Please share the state attribute as code than screenshot. It would be helpful

faces:
  - name: Tzahi
    confidence: 60.603
    bounding_box:
      height: 0.911
      width: 0.369
      y_min: 0.023
      x_min: 0.359
      y_max: 0.934
      x_max: 0.729
    prediction:
      confidence: 0.6060312
      userid: Tzahi
      y_min: 25
      x_min: 690
      y_max: 1009
      x_max: 1399
    entity_id: image_processing.face_counter
total_faces: 1
total_matched_faces: 1
matched_faces:
  Tzahi: 60.6
last_detection: 2021-03-13_17-37-41
friendly_name: face_counter
device_class: face

Thanks

Please try this as automation.

alias: Face recognition - Tzahi
description: ''
trigger:
  - platform: template
    value_template: >-
      {{ state_attr('image_processing.face_counter', 'faces')['name'] == "Tzahi"
      }}
condition: []
action:
  - service: media_player.play_media
    data:
      media_content_id: 'file:///media/welcome_tzahi.mp3'
      media_content_type: music
    target:
      entity_id: media_player.mopidy_pi
mode: single

If this doesnot work we may need to make some tweaks

Thanks. I tried the template trigger in the developer tools and it always returns false

I would have thought it would be something like this:

value_template: >-
  {{ states.image_processing.face_counter.attributes.faces[0].name == "Tzahi" }}

I think… :thinking:

{{ state_attr('image_processing.face_counter', 'faces')[0]['name'] == "Tzahi" }}

Bingo! That works!
Many thanks!! :hugs:

1 Like

That also worked. Thank you