Help on templating with phone numbers ad SMS

Hello everybody
I need do send back an SMS to someone that send a SMS to my modem
I created this automation

trigger:
  - platform: event
    event_type: sms.incoming_sms
action:
  service: notify.sms
  data:
    target: "{{trigger.event.data.phone}}"
    message: >-
      Unknown command '{{trigger.event.data.text}}' from
      {{trigger.event.data.phone}}. Please send BASKET or TENNIS command

The problem is the modem don’t send back sms because the number don’t have the plus sign before
This is extrat from trace

params:
  domain: notify
  service: sms
  service_data:
    target: 393356026***
    message: >-
      Unknown command  'Prova 17' from +393356026***. Please send BASKET or TENNIS command
  target: {}
running_script: false
limit: 10

If I put static number instead of template the plus sign is not removed and sms is delivered
Someone can help me?

Try this:

  data:
    target: "{{'+' ~ trigger.event.data.phone}}"

Though you may still have issues with leading zeros being dropped.

So maybe try this:

  data:
    target: "{{ trigger.event.data.phone|string }}"

Can you show the (sanitised) event data?

Does not work :frowning:

First one: the output has two plus sign
Second one: no plus sign

I don’t kwon how extract sanitised eventa data

Can you help me?
Thank you
This is the output whith

data:
    target: "{{'+' ~ trigger.event.data.phone}}"
params:
  domain: notify
  service: sms
  service_data:
    target: ++393356026***
    message: >-
      Comando sconosciuto 'Prova 24' da +393356026***. I comandi ammessi sono
      BASKET PALLAVOLO SINISTRA
  target: {}
running_script: false
limit: 10

and that the output with

data:
    target: "{{ trigger.event.data.phone|string }}"
params:
  domain: notify
  service: sms
  service_data:
    target: 393356026***
    message: >-
      Comando sconosciuto 'Prova 23' da +393356026***. I comandi ammessi sono
      BASKET PALLAVOLO SINISTRA
  target: {}
running_script: false
limit: 10

Ok, try these:

  data:
    target: "{{' ' ~ trigger.event.data.phone}}"

or

  data:
    target: "{{'' ~ trigger.event.data.phone}}"

No way :frowning:

params:
  domain: notify
  service: sms
  service_data:
    target: 393356026***
    message: >-
      Comando sconosciuto 'Prova 28' da +393356026***. I comandi ammessi sono
      BASKET PALLAVOLO SINISTRA
  target: {}
running_script: false
limit: 10
service: notify.sms
data:
  target: '{{ '' '' ~ trigger.event.data.phone }}'
  message: >-
    Comando sconosciuto '{{trigger.event.data.text}}' da
    {{trigger.event.data.phone}}. I comandi ammessi sono BASKET PALLAVOLO
    SINISTRA

Seems we need an escape sequence to avoid parsing of plus sign

I found a dirty solution that works: using 00 instead of plus sign

service: notify.sms
data:
  target: "{{ trigger.event.data.phone|replace('+','00') }}"
  message: >-
    Comando sconosciuto '{{trigger.event.data.text}}' da
    {{trigger.event.data.phone}}. I comandi ammessi sono BASKET PALLAVOLO
    SINISTRA

But I suppose that’s a bug