vinz486
(Vincenzo Tarricone)
February 4, 2021, 12:08am
1
Hi,
I wish to set a binary_sensor as a combination of 2 attributes in AND:
if (binarySensor.state && imageProcessing.field.subfield > 40) {
return "yes"
}
This:
and the state of another binary_sensor:
binary_sensor:
- platform: template
sensors:
vinzhere:
friendly_name: Vinz Here
device_class: motion
value_template: >-
{% if is_state('binary_sensor.fricam_person_motion', 'on') %}
{{ state_attr('image_processing.facebox_faccia', 'matched_faces.Vinz') | float > 40 }}
{% else %}
no
{% endif %}
I cannot get how to reference âmatched_facesâ object that contain âVinzâ key with a numeric value.
faces:
- name: Vinz
image_id: sette
confidence: 78.53
matched: true
bounding_box:
top: 92
left: 44
width: 107
height: 107
entity_id: image_processing.facebox_faccia
total_faces: 1
matched_faces:
Vinz: 78.53
total_matched_faces: 1
hostname: 0942f4949d6b
friendly_name: facebox_faccia
device_class: face
NB: This template syntax is confusing many people. Iâm a software engineer with 20 year of experience and just spent 3 hours without getting a working simple stupid âifâ condition
Please try this template.
{{ state_attr('image_processing.facebox_faccia', 'matched_faces')['Vinz'] }}
1 Like
Binary sensors can only be on(true)/off(false), not yes/no.
You donât need if/else here, just a single expression that evaluates to true or false is enough.
Try this:
binary_sensor:
- platform: template
sensors:
vinzhere:
friendly_name: Vinz Here
device_class: motion
value_template: >
{{ is_state('binary_sensor.fricam_person_motion', 'on') and state_attr('image_processing.facebox_faccia', 'matched_faces')['Vinz'] | float > 40 }}
This binary_sensor will be on
when motion is detected and the image processing value is above 40, otherwise it will be off
. In tje frontend you will see some other states depending on your language.
1 Like
vinz486
(Vincenzo Tarricone)
February 4, 2021, 10:12am
4
Ended on this string:
{{ (is_state('binary_sensor.fricam_person_motion', 'on')) and (state_attr('image_processing.facebox_faccia', 'matched_faces')['Vinz'] != None) and (state_attr('image_processing.facebox_faccia', 'matched_faces')['Vinz'] | float > 40) }}
But, when sensor is âoffâ it says me âUnavailableâ in gray and not âAwayâ.
I think that the problem is that [âVinzâ] can be present or not (itâs Facebox image_processing).
1 Like
vinz486
(Vincenzo Tarricone)
February 4, 2021, 1:43pm
5
No, itâs not working.
I get this when âVinz:â key doesnt exists:
UndefinedError: 'dict object' has no attribute 'Vinz'
Any suggestion?
Try
state_attr('image_processing.facebox_faccia', 'matched_faces')['Vinz'] is defined
1 Like