Help with a template

I have a sensor, and want to create a template to show the charging state in my dashboard

    jono_hunt_battery_charging_true:
      value_template: "{{ states.device_tracker.jono_hunt.attributes.battery_charging }}

"

I had to create another template in order to show ‘Charging’ or ‘Not Charging’ in my dashboard, instead of ‘True’ or ‘False’.

    jono_hunt_battery_charging:
      value_template: "{% if is_state('sensor.jono_hunt_battery_charging_true', 'True') %}Charging{% else %}Not Charging{% endif %}"

I’m guessing it can be done from the original sensor without having to create another one, but my templating skills aren’t great. How could I create one sensor that returns ‘Charging’ or ‘Not Charging’ from this?

states.device_tracker.jono_hunt.attributes.battery_charging

:thinking:

{{ 'Charging' if states.device_tracker.jono_hunt.attributes.battery_charging else 'Not Charging' }}

{% if states.device_tracker.jono_hunt.attributes.battery_charging %}Charging{% else %}Not Charging{% endif %}
1 Like

Can you please show the complete original sensor configuration.

That’s great, thanks!

And it shows me how to format them for some other templates I’m going to use :slightly_smiling_face:

Sorted, thanks.