Format individual device trackers On/Off instead of Home/Away

I have asked this question in a two other related threads but got no response - I apologize to those threads if it was considered thread hijacking - I’m new and did not mean to break any rules.

Is there a way to format the states of individual device trackers to read something other than home or away?

I tried to follow the template section’s example but I got very confused. If someone could show me an example, I’d really appreciate the help.

It’s not possible directly but you’re right that indeed you can use a template sensor to publish a state in a different way.

For value_template use:

{% if is_state('device_tracker.rpitera', 'home') %}on{% else %}off{% endif %}
1 Like

Thank you so much for this answer - and thanks so much for HA. I’m really trying to learn as much as I can and get involved. I even started taking an introductory Python class!

This isn’t working for me. I tried putting the following in my configuration.yaml file:

sensor 8:
  platform: template
  sensors:
    device_tracker.epson3e7694fiosrouterhome:
      value_template: {% if is_state('device_tracker.epson3e7694fiosrouterhome', 'home') %}on{% else %}off{% endif %}`

and I got the error:

Config directory: C:\Users\rpitera\AppData\Roaming\.homeassistant ERROR:homeassistant.util.yaml:while scanning for the next token found character '%' that cannot start any token in "C:\Users\rpitera\AppData\Roaming\.homeassistant\configuration.yaml", line 126, column 24

Following the format in the template example, I then tried this:

sensor 8:
  platform: template
  sensors:
    device_tracker.epson3e7694fiosrouterhome:
      value_template: >-
          {%- if is_state('device_tracker.epson3e7694fiosrouterhome', 'home') %}
             on
          {% else %}
             off
          {%- endif %}

which didn’t produce the error, but also didn’t change the state labels. Not sure what I am missing…

Ok, discovered one part of the error: Executing this template creates a new instance of a sensor named sensor.device_trackerORIGNALNAMEOFDEVICETRACKER, in this case sensor.device_trackerepson3e7694fiosrouterhome. So in my group, I had to change the device_tracker to the sensor. So now it shows, but it shows as “Off” only. I checked the state of the device tracker and it is indeed ‘home’. Stranger still, if I change:

{% else %}
   off

to any other value, like “not on” and restart HA, it still shows “Off”. This is really driving me nuts.

I’ve tried every possible setup and I’m convinced there’s a bug somewhere. No matter what I do, the value never changes from Off. Also, only one sensor value gets templated even though I am using the very same values and format exactly like the example.

The top instance is the value templated sensor. below that are the two device tracker instances:

Sensors entry:

#
# Sensor Value Templating
#
sensor 8:
  platform: template
  sensors:
    device_tracker.epson3e7694fiosrouterhome:
      value_template: '{% if is_state('device_tracker.epson3e7694fiosrouterhome', 'home') %}on{% else %}WTF{% endif %}'
    device_tracker.19216819:
      value_template: '{% if is_state('device_tracker.19216819', 'home') %}on{% else %}WTF{% endif %}'

How the hell can this be showing up as “off” if that isn’t even a valid value??? The correct state should be either “on” or “WTF”. I think something else is going on here. And why isn’t the other value template sensor ever even created? It’s not that it’s missing from the group; it doesn’t show in the entities list.

Resolved: Need to use double instead of single quotes to surround the value in value_template

See this thread