How to get value from an Attribute with a space in it?

First time post, trying to look for some help that I can’t find an answer for.

I am trying to setup a template sensor with an attribute from inside the Xbox Live Sensor. The sensor has some attributes that have spaces in them and I can’t figure out how to get their values.

Attributes shown in the developer tools states menu are below:

XboxOne Background: Home
XboxOne Full: Plex
friendly_name: PawnyNZ
icon: mdi:xbox

I can successfully get the friendly name value via:

value_template: ‘{{ states.sensor.xbox_pawnynz.attributes.friendly_name }}’

But I can’t for the life of me find out how to get the XboxOne Full attribute which has the space in the attribute name.

Any help is appreciated.

Did you tried replacing the space by an underscore? So XboxOne_Full

Yeah, tried that but no luck in getting the value.

I found a way to do it. With the GTFS sensor, this is the template I’m using to get the Route Short Name attribute:

{{ states.sensor.tisseo_work_home.attributes['Route Short Name'] }}

Your attribute could probably be fetched with this template:

value_template: '{{ states.sensor.xbox_pawnynz.attributes["XboxOne Full"] }}'
4 Likes

Try to go to YOUR_IP::8123/dev-template and enter:
{{ states.sensor.xbox_pawnynz.attributes }}

2 Likes

Awesome!
I can confirm that the below works and realised how great the Dev Template section is for checking. And here I was restarting Home Assistant every time I wanted to change something ><

value_template: ‘{{ states.sensor.pawnynz.attributes[“XboxOne Full”] }}’

So now I can start making some automation’s based on what I am doing on the Xbox.

1 Like

If anyone is interested for using this for themselves, I ended up with the template sensor setup as the below so that the sensor shows as Offline rather than null/nothing when the Xbox is turned off.
Note: replace “pawnynz” with your xbox live ID:

  xboxapi_current:
    value_template: '{% if is_state("sensor.pawnynz", "Offline") %}Offline{% else %}{{ states.sensor.pawnynz.attributes["XboxOne Full"] }}{% endif %}'

To get some attribute values from QNAP, this did worked for me:

{{ ((states.sensor.qnap_xyz_memory_usage.attributes['Memory Size'] )) }}

Thanks a lot

That seems to work fine with strings, unfortunately I have to process a date in such an attribute.
This works fine in template editor, but when I try to put it into a template helper I get “strptime() argument 1 must be str, not TupleWrapper”

Any ideas?
Thanks

Paste in the code that is working in the template editor (formatted as code!) and a screenshot of the template helper screen.

{{states.sensor.smart_irrigation_garten.attributes['last calculated']|first}}

Sorry, I found the problem: I specified the device calss as Date and the value is string.

1 Like

Glad to hear it.

It’s always safer to use bracket format and the functions for accessing states and attributes — see here, including the warning at the bottom of the section:

So you would be safer to use:

{{ state_attr('sensor.smart_irrigation_garten', 'last calculated')|first }}

This applies to all of this recently-resurrected thread: I suspect state_attr() was not available in 2016.