I’m trying to work a template sensor for tensorflow. Bottom line, when an object is detected it can have car, truck, person, etc in the attributes, but when nothing is detected there are no attributes. This causes the template to fail. I could create a template for each situation, but that ends up being a lot of templates.
Anyway
This template works (still errors when nothing is detected, but turns on when a person is detected)
person_in_driveway:
friendly_name: Person in Drivway
value_template: "{{ (states.image_processing.tensorflow_front_door.attributes.matches.person[0].score) | float >= 80 }}"
entity_id: image_processing.tensorflow_front_door
This one does not work (unless a truck is detected)
vehicle_in_driveway:
friendly_name: Vehicle in Driveway
value_template: "{{ (states.image_processing.tensorflow_front_door.attributes.matches.truck[0].score) | float >= 80 or (states.image_processing.tensorflow_front_door.attributes.matches.car[0].score) | float >= 80 or (states.image_processing.tensorflow_front_door.attributes.matches.bike[0].score) | float >= 80 }}"
entity_id: image_processing.tensorflow_front_door
I guess I need to parse, but not sure how to do so.
What does states.image_processing.tensorflow_front_door.attributes look like when a person, truck, etc. are not detected? Does states.image_processing.tensorflow_front_door.attributes.matches still exist? Do states.image_processing.tensorflow_front_door.attributes.matches.person, states.image_processing.tensorflow_front_door.attributes.matches.truck still exist, and if so, are they still lists, etc.???
person_in_driveway:
friendly_name: Person in Drivway
value_template: >
{% set m = state_attr('image_processing.tensorflow_front_door', 'matches') %}
{{ m.person is defined and (m.person[0].score) | float >= 80 }}
entity_id: image_processing.tensorflow_front_door
Nice, that does work. thanks. Using your template I built this one too
vehicle_in_driveway:
friendly_name: Vehicle in Driveway
value_template: >
{% set m = state_attr('image_processing.tensorflow_front_door', 'matches') %}
{{ m.truck is defined and (m.truck[0].score) | float >= 80 or m.car is defined and (m.car[0].score) | float >= 80 or m.bike is defined and (m.bike[0].score) | float >= 80 }}
entity_id: image_processing.tensorflow_front_door