Help! I’m literally at my wits end trying to figure out something that I thought would be relatively simple. I am using Frigate’s frigate/reviews MQTT topic as an automation trigger to send out a notification. I am trying to build logic to only pull certain objects detected in a review topic.
You didn’t mention how it fails (error message or unexpected result), so I can only suggest basic troubleshooting.
I would try getting each part of the JSON in the dev tools area. That will give you a clearer picture of the issue. I’m wondering if there is a parent object you are missing in the JSON call.
Apologies, “failed” isn’t the right word. The evaluation {{ ns.count > 0 }} always evaluates to false because the {% if items.in detect_list %} never matches, even though car is in the list.
If I hardcode the “car” the evaluation evaluates correctly.
{% set ns = namespace(count=0,items='') %}
{% set objects = ['car'] %}
{% set detections = ["car", "truck", "bus", "person"] %}
{% for items in objects %}
{{ items }}
{% if items|string in detections %}
{% set ns.count = ns.count + 1 %}
{{ ns.count }}
{% endif %}
{% endfor %}
{{ ns.count > 0 }}
I think it would be good to see the entire YAML that you’re using to create the template. I pasted your stuff into the template area of the dev tool and got back True when I tried it. Here specifically is what I used to test:
I would remove the offending condition and then edit the automation that will send you trigger.payload_json as the notification so you can see what it is. Or maybe set it to an input text so you can see it in the state. Something so you can see what that is.
Looks like for some reason, if I do string comparisons by going through each list element, it didn’t work. I’m using this logic comparison, and somehow it worked: