Join Two Strings in Value Template

I have searched to no avail. I just want to join two strings together in a template. I want to display the lat and long of my tracker in one line.

Here is what I put for displaying latitude only:
value_template: “{{ state_attr(‘device_tracker.brett_pixel’, ‘latitude’) }}”

That outputs my latitude: -21.8691608

What I want is: -24.8691608, 153.3360765
Combining Latitude and Longitude with a comma separating them.

It would be like this:

value_template: “{{ state_attr(‘device_tracker.brett_pixel’, ‘latitude’) }}, {{ state_attr(‘device_tracker.brett_pixel’, ‘longitude’) }}”

You can use the Template Editor in Developer Tools to see how the output will look. Just paste the whole line and it will show the parsed result on the right-hand side. :nerd_face:

So simple! Thank you. Now I understand how it works. The code errored in the Template Editor, but I have never used it. I will look into it. Appreciate the reply.

1 Like

Oops! You were using backquotes (`) and I just copied/pasted without testing it in the Template Editor (as I recommended to you :sweat_smile:). Try it this way (with single quotes ('):

value_template: “{{ state_attr('device_tracker.brett_pixel', 'latitude') }}, {{ state_attr('device_tracker.brett_pixel', 'longitude') }}”

Also, if you’re using this to generate a map URL you may want to remove the spaces after the commas for better browser/web-site compatibility.

1 Like