Help with Templating for use in Automation

Hello, I’m pulling my hear out with templating so any assistance greatly appreciated!

I’m trying to grab the values from an image processing scan using deepstack to pull out all the predictions that were found in a scan so i can create a sensor for each prediction to count the number of people found and in this case number of birds found:

The closest I can get is:

{% if states.image_processing.person_detection %}
  {{ state_attr('image_processing.person_detection', 'all_predictions') }}
{% else %}
  ??
{% endif %}

which simply tells me "person": 1, "bird": 1.

Thanks

Try using template sensors:

- platform: template
  sensors:
    number_of_birds:
      friendly_name: 'Number of Birds'
      entity_id: image_processing.person_detection
      value_template: "{{ state_attr('image_processing.person_detection', 'all_predictions')['bird'] }}"
    number_of_people:
      friendly_name: 'Number of People'
      entity_id: image_processing.person_detection
      value_template: "{{ state_attr('image_processing.person_detection', 'all_predictions')['person'] }}"
1 Like

Thanks, works like a charm!

1 Like