Native template problem

In 0.118 my notification automation got broken by the native template introduction.
When disabling native templating in the configuration, it works again flawless.

The script produces a notification to my IOS device with a Title, Message and Map.

With native template active, the title and message come through, the map shows (on the ios device) no map but an error: “Latitude wasn’t found or couldn’t be casted to string”.

How to reconfigure it to work with native templating?

- id: '4000000000004'
  alias: 'P2000'
  initial_state: 'on'
  mode: queued
  trigger:
  - platform: state
    entity_id: sensor.p2000
  action:
  - service: notify.mobile_app_iphone_van_richard
    data_template:
      title: {{ trigger.to_state.attributes.friendly_name }}
      message: |
        {{ trigger.to_state.state }}
        {{ trigger.to_state.attributes.capcodes | replace ('<br/>','') }}
      data:
        push:
          thread-id: "p2000"
          category: map
        action_data:
          latitude: | 
                    {% if trigger.to_state.attributes.latitude == 0 %} 50.710413
                    {% else %}
                    {{ trigger.to_state.attributes.latitude }}
                    {% endif %}
          longitude: | 
                    {% if trigger.to_state.attributes.longitude == 0 %} 2.405231
                    {% else %}
                    {{ trigger.to_state.attributes.longitude }}
                    {% endif %}

Not sure why you are using the ‘keep newlines’ block style indicator. Feel like your output is going to be

  latitude: 
                50.12345

https://yaml-multiline.info/

Try replacing the ‘|’ with ‘>’ maybe?

Not sure how the native types would have changed this behavior though. I’m just kind of guessing. Everything else seems fine.

Tried, but sadly it did not help…

Also tried to do it from a dedicated attribute approach…

          latitude: "{{ state_attr('sensor.p2000','latitude') }}"
          longitude: "{{ state_attr('sensor.p2000','longitude') }}"

same result as the original automation…

I pasted your automation into my system and it fails Check Configuration.

This template:

      title: {{ trigger.to_state.attributes.friendly_name }}

is missing quotes (either single or double).

It passes when quotes are added:

      title: '{{ trigger.to_state.attributes.friendly_name }}'

There may be other issues but this should be fixed first.

Thanx, they were there, but after making the automation simpler, to test, I accidentely removed them.

Can you post a copy of the exact error message that is reported?

FWIW, prior to 0.118, the type of this template’s result is string:

          latitude: | 
                    {% if trigger.to_state.attributes.latitude == 0 %} 50.710413
                    {% else %}
                    {{ trigger.to_state.attributes.latitude }}
                    {% endif %}

In 0.118, the result’s type is float.

The result’s appearance is what determines its type. This looks like a floating-point number, 50.710413, so that is the type it is assigned.

The problem may be due to the latitude option expecting a string but it gets a float.

As far as I know, there is no way to force a numeric string to be treated as a string and not as a number.

The only way to prevent it from being interpreted as a number is to alter it so it isn’t a pure number (z50.710413). Of course, this isn’t a useful solution in this case because it ceases to be a valid longitude value.

I suggest you open a new Issue in the GitHub repository and provide this as an example to the development team of a situation where automatic type conversion poses a problem.

Exact error message:

Also created an Issue like you suggested