Hello,
How to get the specific attribute from this global entity with the bellow result.
This is the result of my entity:
faces:
- name: James
confidence: 71.771
entity_id: image_processing.id_tester
total_faces: 1
friendly_name: id_tester
device_class: face
For example, I can get easely the total_faces attribute with this in my configuration.yaml :
sensor:
- platform: template
sensors:
face_recognition_id_faces:
friendly_name: "Face Recognition faces"
value_template: "{{ state_attr('image_processing.id_tester', 'total_faces') }}" `
But question is :
I want to get also name and confidence in seperate entity that are under face attribute which is an array to use automation.
Do you know how to proceed to get the state of this attribute in a particular entity ?
tom_l
April 27, 2020, 7:03pm
2
Please format your pasted code correctly. See point 11 here: How to help us help you - or How to ask a good question
Hi Tom_I, I have updated the code as request
Any update on this topic ?
tom_l
April 28, 2020, 5:36pm
4
Can you take a screenshot of the attributes of this sensor image_processing.id_tester
in the developer tools states menu?
tom_l
April 29, 2020, 5:44pm
6
I meant the right hand column in the states list.
Any idea to get only my name from this entity ?
1 Like
tom_l
May 1, 2020, 2:48pm
9
Try this in the developer tools template editor:
{{ state_attr('image_processing.id_tester', 'faces')[name] }}
I doubt it will work but give it a try.
Thanks for the suggestion, but no luck with that :(ā¦
tom_l
May 1, 2020, 4:09pm
11
Yeah I didnāt think it would. Sigh. Looks like regex to the rescue again.
Try:
value_template: >
{{ state_attr('image_processing.id_tester', 'faces')|regex_findall_index("- name:\s(.+$)") }}
Oh yeah, for the confidence level:
value_template: >
{{ state_attr('image_processing.id_tester', 'faces')|regex_findall_index("confidence:\s(.+$)") }}
If you want to know how it works you can learn regular expressions here: https://regexone.com/
Hello tom,
Thank a lot for this logical !
Regex is very powerfull. I had to modify a little bit your in order to get what I want because the output was like that:
- 'name': 'Jeremy',
'confidence': 77.498,
'entity_id': 'image_processing.id_tester'
I had put this in order to get only name and confidence as state:
face_recognition_id_name:
friendly_name: "FR - name"
value_template: >
{{ state_attr('image_processing.id_tester', 'faces')|regex_findall_index("....\s'(.+)',") }}
face_recognition_id_confidence:
friendly_name: "FR - confidence"
value_template: >
{{ state_attr('image_processing.id_tester', 'faces')|regex_findall_index(".confidence...(.+),") }}
So now it works, I can get the state:
Thanks a lot for your help man
2 Likes
ig0re4
(Igor)
May 16, 2020, 2:50am
13
Hey, I had the same problem and I solved it by using different regex:
facebox_person_detection:
friendly_name: āFacebox person detectionā
value_template: >-
{% if (state_attr(āimage_processing.facebox_sonoff_local_fileā, ātotal_facesā)|int) == 0 -%}
Nobody
{%- else -%}
{{ state_attr(āimage_processing.facebox_sonoff_local_fileā, āfacesā) | regex_findall_index(".nameā: \s+?ā([\w+#\s]+)ā?") }}
{%- endif %}
Let me know if it works for you as well.
Eddie1974
(Eddie)
February 18, 2021, 3:03am
14
vehicles:
plate: 5nn45
confidence: 0.903
region_code: eu
vehicle_type: Sedan
Can you please help to make - plate attribute a sensor? I tried the above example but no go.
safepay
(Richard Mann)
January 10, 2022, 1:44am
15
I know this is an older thread, but I had the same problem getting temperature values from a weather entity.
The entity is weather.muckleford_south with attributes:
temperature: 33.9
humidity: 19
pressure: 1016
wind_bearing: 300
wind_speed: 5
visibility: 60.2
forecast:
- condition: partlycloudy
precipitation: 0
precipitation_probability: 10
temperature: 33
templow: 14
datetime: '2022-01-09T13:00:00+00:00'
wind_bearing: 181
wind_speed: 16.9
- condition: rainy
precipitation: 3.9
precipitation_probability: 80
temperature: 30
templow: 18
datetime: '2022-01-10T13:00:00+00:00'
wind_bearing: 144
wind_speed: 22.3
- condition: rainy
precipitation: 1.3
precipitation_probability: 50
temperature: 30
templow: 17
datetime: '2022-01-11T13:00:00+00:00'
wind_bearing: 119
wind_speed: 17.3
- condition: lightning
precipitation: 17.4
precipitation_probability: 80
temperature: 29
templow: 19
I extract a condition with:
{{ state_attr('weather.muckleford_south', 'forecast')[0].condition }}
or
{{ state_attr('weather.muckleford_south', 'forecast')[1].condition }}
or
{{ states.weather.muckleford_south.attributes.forecast[0].condition }}
To the OPās original question:
{{ state_attr('image_processing.id_tester', 'faces')[0].entity_id }}
or
{{ 'sensor.' + states.image_processing.id_tester.faces[0].entity_id + '_condition' }}
should work.
For example.
I hope this helps someone.
4 Likes
lsgv
(Luis Gaivao)
March 12, 2022, 12:20pm
16
Iām trying to extract values from a complex nested attribute structure and this thread is as close as I could get to what I need but not quite yet.
Iām using Solcast integration which exposes among others
sensor.solcast_forecast_tomorrow
which has as state tomorrowās estimate in kWh and as attribute a lot of related information namely the hourly forecasts (the paste below is truncated to the first 9 hours)
resource_id: my_secret_resource_id
hourly:
- '00:00':
pv_estimate: 0
pv_estimate10: 0
pv_estimate90: 0
- '01:00':
pv_estimate: 0
pv_estimate10: 0
pv_estimate90: 0
- '02:00':
pv_estimate: 0
pv_estimate10: 0
pv_estimate90: 0
- '03:00':
pv_estimate: 0
pv_estimate10: 0
pv_estimate90: 0
- '04:00':
pv_estimate: 0
pv_estimate10: 0
pv_estimate90: 0
- '05:00':
pv_estimate: 0
pv_estimate10: 0
pv_estimate90: 0
- '06:00':
pv_estimate: 0
pv_estimate10: 0
pv_estimate90: 0
- '07:00':
pv_estimate: 125.4
pv_estimate10: 14.3
pv_estimate90: 302.3
- '08:00':
pv_estimate: 1476.3
pv_estimate10: 162.7
pv_estimate90: 4159.4
- '09:00':
pv_estimate: 4292
pv_estimate10: 525.1
pv_estimate90: 10227.4
I want to extract the pv_estimate value for a given hour using a template but after many attempts canāt figure out how to do it.
Iāve tried
{{ state_attr('sensor.solcast_forecast_tomorrow','hourly')[9] }}
which gives me for the 9th hour
{'09:00': {'pv_estimate': 4292.0, 'pv_estimate10': 525.1, 'pv_estimate90': 10227.4}}
but after that Iām lost and canāt get any further to just extract the pv_estimate value.
This is a dictionary within a dictionary and I would know how to do it if it was JSON but I canāt figure out how to do it when it is within an attribute.
Any help or pointers appreciated.
PS: I can use a REST sensor and query the solcast API directly and template the JSON output to get what I want. But that means I have both the Solcast integration which is convenient because, well, integrated, and my own REST sensor. Thatās messy and doubles the number of Solcast API calls. So Iām looking for a more elegant solution using the sensor attributes which contain the data I want
The other arrays are similar with the same attributes and different values. I am trying to fetch the name attribute from each of these objects.
.
{{ state_attr('sensor.solcast_forecast_tomorrow','hourly')[9].pv_estimate }}
[image]
I am trying to get the attribute forecast ā wind_speed (blue arrow). I can get the wind_speed (red underline) by:
{{state_attr('weather.ksgr_daynight', 'wind_speed')}}
But not sure how to get the forecast wind speed. Thanks in advanced.
lsgv
(Luis Gaivao)
March 12, 2022, 2:49pm
19
Thanks but I tried that and it doesnāt work.
From another forum, the owner of the Solcast integration, I got the working expression
{{ state_attr('sensor.solcast_forecast_today', 'hourly')[9]['09:00']['pv_estimate'] }}
The trick is in the [ā09:00ā] which moves the template further onto the data. I missed that and was trying ā09:00ā which also didnāt work.
Your solution would have worked if there wasnāt the double dictionary thing. Thanks anyhow.
Edit: Whereas in the developer tools/template the double quotes in ā09:00ā do work it throws an error when in the yaml file. I had to put single quotes as in ā09:00ā to clear the error.
bullantmm
(Chris)
January 22, 2023, 11:32am
20
@Eddie1974 Iām sure you got there but for anyone else this worked for me with Plate Recognizer:
{{ state_attr('image_processing.platerecognizer_frontyard_west_sub', 'vehicles')[0]['plate'] }}