Get attribute from sensor

Hello Guys.
I am trying to get an attribute from an attribute. I have no problem getting the “normal” attributes from the sensor.


“pinned” I can get like that;
'{{states.sensor.google_keep_XXXXXXXX.attributes.pinned}}'
without any trouble, but how do I get “lines”?
'{{states.sensor.google_keep_XXXXXXXX.attributes.notes.lines}}'
That doesnt work…

Thank you

'{{states.sensor.google_keep_XXXXXXXX.attributes.notes[0].lines}}'

I am getting this error message:

"Error rendering data template: UndefinedError: ‘homeassistant.helpers.template.TemplateState object’ has no attribute ‘notes’ "

https://www.home-assistant.io/docs/configuration/templating/#states

Try this in the template editor:

"{{ state_attr('sensor.google_keep_XXXXXXXX', 'notes') }}"
"{{ state_attr('sensor.google_keep_XXXXXXXX', 'notes')[0].lines }}"
1 Like

The second option worked, but only in the template editor. I am trying to put the Attribute into the message body of a notify message, which then doesnt work.

service: notify.mobile_app_emils_s21
data:
  title: Test
  message: '{{ state_attr('sensor.google_keep_XXXXXXXX', 'notes')[0].lines }}'

For that I am getting this error message:
“Failed to call service notify.mobile_app_emils_s21. template value should be a string for dictionary value @ data[‘message’]. Got None”

Do I have to get the array into a string? Is it not possible to use arrays as message?

Use double quotes outside your template (like in my examples) or all you get is this for the open and close quotes:

message: '{{ state_attr('
service: notify.mobile_app_emils_s21
data:
  title: Test
  message: "'{{ state_attr('sensor.google_keep_137b49fc8e', 'notes')[0].lines }}'"

Yes, works. Kinda. Thank you!

The output is: ‘[‘Kamera’,"]’.
Can you think of any way to remove the brackets and quotes?

1 Like
message: "'{{ state_attr('sensor.google_keep_137b49fc8e', 'notes')[0].lines[0] }}'"

The brackets are gone, but the quotes still remain.

Like this:
‘Kamera’

Because you added them there in your template

1 Like

Oh yea… now its working.
Thank you guys!