I am trying to create a custom sensor to pull back some game data from the Xbox - I can see the data I want to pull back in my dev-state - however, there is a space in the attribute:
- platform: template
sensors:
xxxxxx_xbox_playing:
friendly_name: xxxxxx is playing
value_template: '{{ states.sensor.xxxxxx.attributes.XboxOne full }}'
I have tried to quote around “states.sensor.xxxxxx.attributes.XboxOne full” but then I just see the entire line in dev-state - what is the easiest way to escape the space between XboxOne and full? - I have also tried %20 - but I still get an error.
Thanks Pete, I’ve tried that, but I get the following error:
Invalid config for [sensor.template]: invalid template (TemplateSyntaxError: expected name or number) for dictionary value @ data['sensors']['xxxxxx_xbox_playing']['value_template']. Got '{{ states.sensor.xxxxxx.attributes.["XboxOne full"] }}'. (See ?, line ?). Please check the docs at https://home-assistant.io/components/sensor.template/
I’ve tried removing the ‘.’ between attributes and [“XboxOne full”] but then it just returns a blank value.
OK I just noticed that in your log the error is showing that the part it doesn’t like is {{ states.sensor.xxxxxx.attributes.[“XboxOne full”] }}.
just clarify you are actually putting in a valid sensor that actually exists on your system correct? If you’re really putting in {{ states.sensor.xxxxxx.attributes.[“XboxOne full”] }} do you have a sensor that is actually called “sensor.xxxxxx” that has an attribute of “XboxOne full”? Also capitalization matters, too.
I just tried with one of my sensors in the template editor using the format I posted above and it works fine for me.
After a deep search and without any good results, I’ve finally decided to ask for some help. I’m also having an attribute with a space and I’m trying to just create a new senssor using this attribute (in my configuration file). I’ve trying several combination but I get all the time an unknown value.
Here is the original senssor and attribute with “space”:
Ok I found the answer to my own question, so I will post it here just in case it can help some one else.
In my case what was wrong all the time was: in my attributes with “space” there is already an unit of measurment and in my template I was forcing to use another unit of measurement “GB”. So this was leading to a crash and I will find it later how to force a unit of measurment.
So the following 2 codes did work for me:
qnap_djeev_memory_used_gb:
friendly_name: "Qnap TS-453A used memory in GB rounded"
value_template: "{{ (state_attr('sensor.qnap_djeev_memory_usage', 'Memory Size')) }}"
or
qnap_djeev_memory_used_gb:
friendly_name: "Qnap TS-453A used memory in GB rounded"
value_template: '{{ states.sensor.qnap_djeev_memory_usage.attributes["Memory Size"] }}'