Confused with templating

Hi all,

Am a bit confused with a simple problem and was hoping someone would be able to explain it to me. I am using the life360 platform and looking at a way to show the “battery_charging” attribute as either “charging” or “not charging|” instead of the “true/false” (sounds simple right?).

Testing on the dev template I set this:

{{ states.device_tracker.life360_avani.attributes.battery_charging }}
Which evaluates as “False” which matches what I see in dev-states, though am not sure why it capitalises the first letter.

So to test my logic I set the following (again on the template editor)

{% if is_state('states.device_tracker.life360_avani.attributes.battery_charging', 'false') %}
  not charging
{% else %}
  charging 
{% endif %}

the output I get is “charging” no matter to what I put as the state to test against. What am I doing wrong?

Actually, I’ve managed to answer this one, I really do need to RTFM more often. In case someone else comes across this issue, I highly suggest reading Home Assistant template extensions

Its easier to evaluate the attributes using:

{{ state_attr('device_tracker.life360_avani', 'battery_charging') }}

And also remember that true/false is acutally 1/0, so that the test would be:

{% if is_state_attr('device_tracker.life360_avani', 'battery_charging',0 ) %}
  not charging
{% else %}
  charging
{% endif %}

Which yields the correct status of “Not Charging”