I want to alter some attributes shown in Home Assistant, and need a little help.
For ‘device_tracker.jonos_iphone’ it shows me as ‘home’ when I’m home, but I want to capitalise it (Home). I guess that’s the OCD in me
I’m guessing I can do it with a value template, but I’m not sure how.
Also, I use this to show my battery level ‘sensor.jonos_iphone_battery_level’.
It shows the battery level as a number, but I want to add the percent sign (%) to the end. Again, I’m guessing I can do it with a value template, but I’m not sure how.
Thanks a lot, I forgot about overriding the default home zone
I’ve tried it but for some reason it didn’t alter the name. Do you know if I should remove the latitude and longitude from above (under homassistant:), of if I should leave that there?
I tried battery percentage thing but that doesn’t work at the moment either (doesn’t show up as a sensor under Current Entities in the Dev Tools).
I looked at the Template Sensor page on Home Assistant’s website and the code seems right. I guess I’ll need to play around a little to get that working.
The only way to over-ride the home zone is to call it home.
I have lat and lon both in the main config file and also in the zone file.
In my zones section I have
> - name : HOMe
> latitude: !secret latitude
> longitude: !secret longitude
> radius: 250
> icon: mdi:account-multiple
Thanks, I got the code working for adding the percent sign (needed to add step of indentation)
If I use this code, when someone is in another zone I’ve setup in HA (e.g. my wife’s in the ‘Work’ zone or my son’s in the ‘School’ zone would HA still show this, or just ‘Not Home’ when they’re not at home?
…so I added both the ‘regular’ one (device_tracker.wifes_iphone) and the value_template one from here to my HA config.
My wife went to work and the regular one says she’s at ‘Work’ (work zone) and the value_template one says she’s ‘Away’. So I guess it doesn’t change to reflect the zone with this value_template version
I don’t suppose there’s a way of changing ‘home’ to ‘Home’ with a value_template, without specifying an ‘{%else%}Not Home’ part is there?
You are correct, looking at the argument specified, we are telling HA she’s either Home or Not Home, I’m not sure of if you can specify without the else effect.
Try the following: add an elif for each zone
Sensor:
- platfor: template
sensor
device_tracker.jonos_iphone:
friendly_name: 'Jonos'
value_template: >-
{%- if is_state("device_tracker.jonos_iphone", "home") %}
Home
{%- if is_state("device_tracker.jonos_iphone", "work") %}
Work
{%- if is_state("device_tracker.jonos_iphone", "school") %}
School
{% else %}
Not Home
{% endif %}
If you are just trying to change the first letter to upercase, could you not use the title() function that jinja provides?
I am not very good at templating and can’t test it right now, but something like this: