Can I change the picture of a device_tracker?

I tried the following code in known_devices.yaml, but get an empty white circle, whatever the state is.

stef:
name: Stef
hide_if_away: false
icon:
mac:
picture: >-
{% if is_state(‘device_tracker.stef’, ‘Home’) %}
https://www.home-assistant.io/images/favicon-192x192.png
{% else %}
https://www.home-assistant.io/images/favicon-192x192.png
{% endif %}
track: true

best regards, Stef

sorry didn’t quote the code correctly

stef:
  name: Stef
  hide_if_away: false
  icon:
  mac: 3C:BB:FD:1F:3F:F0
  picture: >-
    {% if is_state('device_tracker.stef', 'Home') %}
      https://www.home-assistant.io/images/favicon-192x192.png
    {% else %}
      https://www.home-assistant.io/images/favicon-192x192.png
    {% endif %}
  track: true

If you are using lovelace, you can do it with a picture-entity card:

If you are using the normal UI, the easiest way to do this is with a template sensor. Hide the device tracker and make a template sensor that points to the device tracker state attribute. Then use logic in the entity_picture_template config option.

sensor:
  - platform: template
    sensors:
      stef:
        friendly_name: Stef
        value_template: "{{ states('device_tracker.stef') }}"
        entity_picture_template: >
          {% if is_state('device_tracker.stef', 'Home') %}
            https://www.home-assistant.io/images/favicon-192x192.png
          {% else %}
            https://www.home-assistant.io/images/favicon-192x192.png
          {% endif %}

Thanks very much Petro,

works great,
one small improvement: “name” should be “friendly_name”

cheers, Stef

1 Like