MQTT Message Data Count

I have cameras that are sending the following MQTT data…


I would like to get the number of class 0 ID’s that are in that message. In the above example I would like to setup an mqtt sensor that displays / returns the number 6.

Here is what I have now in my configuration.yaml sensor but it is not returning anything

value_template: '{{ len(value_json.outputs) }}'
  unit_of_measurement: "class"

I would really appreciate some help or some advice on how to extract that data.


value_template: "{{ value_json.outputs | selectattr('class', 'eq', 0) | list | count }}"

Thank you so much. This works great!

1 Like