Device_tracker "Online" instead of "Home" - How to template a sensor?

Hi there,

I’m new to HA, and I’m struggling to understand how to work with the configuration.yaml. I’m trying to convert some of my device_tracker.device devices (via Unifi Integration) from saying “Home” to “Online”, or another arbitrary string.

I’ve found a few topics on this forum about binary sensors, templates and so on, but I can’t get any of it to work. The below is taken from the HA site, it looks like what I want to do but it doesn’t change anything.

    - sensor:
        - name: "frontcam"
          state: >
            {% if is_state('device_tracker.device', 'home') %}

Could anyone help me?

Got there. It’s probably my lack of understanding on yaml formatting, it looks sort of similar to the example.

I did:

    - platform: template
            friendly_name: "Camera"
            value_template: "{% if is_state('', 'home') %}Online{% else %}Offline{% endif %}"

Do you mean sensor.frontcam fails to be created or it is created but its state never changes?

If it fails to be created, you have to execute Configuration > Server Controls > Reload Template Entities in order to load it.


Functionally, there’s no difference between the two versions you posted except that the first one is in the new ‘modern’ format and the second one is in ‘legacy’ format. Going forward, the emphasis will be on using the ‘modern’ format.

Thanks for your help!