HA Companion for Android - storage_sensor

Oh, I already have some templates in my configuration, so far so good. But with some “storage_sensor” attributes I don’t get along, I can’t read these attributes.

The sensor is “sensor.mymobile_storage_sensor” and one of the attributes I want to use is “Free external storage: 33GB”. Yes, written this way, including spaces…

I have tried to replace the spaces with “_” and I know the text in the documentation that says:

*When an attribute contains spaces, you can retrieve it like this: *
states.sensor.livingroom.attributes[“Battery numeric”].

Nevertheless, none of my attempts were successful.
Did any of you manage to read these attributes and what does the code look like?

Thanks for your help!

Did you try like this?

state_attr('sensor.mymobile_storage_sensor', 'Free external storage')
2 Likes

Wow, solved! Thanks a lot Burningstone!
It can be so simple… And I always thought “spaces” are strictly to be avoided. Obviously not… However, this contradicts the documentation completely, it says clearly:

When an attribute contains spaces, you can retrieve it like this:
states.sensor.livingroom.attributes[“Battery numeric”].

So

states.sensor.mymobile_storage_sensor.attributes['Free external storage']

doesn’t work?

The docs also say to avoid states.xxx.xxx notation and rather use states(xxx) notation :slightly_smiling_face:

1 Like

No, it didn’t work out that way for me…
I know, the documentation is a bit controversial in this case.

Then you must have made a typo. See below, both methods lead to the same result:

1 Like

In deed, obviously I had an error inside in my attempts. I have now checked both versions again and both work correctly as you showed. For the now, I am using the variant:

state_attr('sensor.mymobile_storage_sensor', 'Free external storage')

Simply because the documentation recommends it…
It never gets boring with HomeAssistant, isn’t it? :wink:

Thanks again for your valuable support.

1 Like

That’s good, the other method can lead to issues when entities are not loaded yet during startup when the template tries to evaluate them.