Format slack notifications with jinja for device tracker / person component

Hi, I am trying to format a slack notification in an automation. I have implemented the device tracker, person and slack component. They all work as expected.

My configuration:

The idea is to send a slack notification ones someone leaves or enters a zone.
I am able to send a slack notification and this message already contains:

See code & screenshot below:

   # tracking notifications
   - alias: name entered zone
       platform: state
       entity_id: person.ted, person.annelies, person.stijn, person.naud
       service: notify.slack
               message: '{{now().strftime("%Y-%m-%d %H:%M:%S")}}: {{ }} is in zone {{ 
   trigger.to_state.state }}'
               target: '#zones'
               data: {
       "attachments": [
               "color": "#36a64f",
               "title": "latitude: {{ trigger.to_state.attributes.latitude }}, longitude: {{ 
   trigger.to_state.attributes.longitude }}.",
               "title_link": "{{ trigger.to_state.attributes.latitude }},{{ 
   trigger.to_state.attributes.longitude }}",

This is how it currently looks like:

I am working on some improvements. I have the following questions:

  1. I would like to change the color of the attachment, depending on the state (home or not_home or some other zone). How can I do that withing the json data message?

  2. I would like to leave out the attachment from the slack message in case there is no latitude/longitude available. How can I do that?

  3. I would like to add a secret default latitude value {{ trigger.to_state.attributes.latitude or 99.99999 }} like this: {{ trigger.to_state.attributes.latitude or !secret latitude }}. The example with 99.99999 works, but with the !secret latitude does not:

Invalid config for [automation]: invalid template
(TemplateSyntaxError: unexpected char '!' at 53) 
for dictionary value @ data['action'][0]['data_template']['data']. 
Got None. (See /config/configuration.yaml, line 2). 
Please check the docs at

Would a secret value inside a jinja value possible? How can I do that?

  1. Notifications keep coming in, even when a person stays in the same zone (see screenshot). What can I do to prevent that?

Any suggestions are welcome!