CallerID and TTS - how to say each number individually in the phone number?

I’m a brand new HA user (about two weeks). I’m using HA on a generic x86-64 box.

Some of the automations that I want to do revolve around using CallerID. I do have a notification automation going for pushing a message to my iPhone, and that is working great.

I also have an automation using TTS (via Google Translate) to speak the message to my HomePod. This also is working, but the TTS does one thing that I want to do differently - it speaks the numbers as a group, and not individually. For instance, it speaks 8001234567 as “8 billion, 1 million, 2 hundred 34 thousand, 5 hundred 67”.
Since people don’t think of phone numbers in this way, I want to change it to say this number as “eight zero zero one two three four five six seven”.
The yaml for this automation is:

service: tts.speak
target:
  entity_id: tts.google_en_com
data:
  cache: false
  media_player_entity_id: media_player.living_room_homepod
  message: >-
    Incoming call from {{
    state_attr('sensor.modem_callerid_55ff3d54501b4d361c7abf6327d7405d',
    'cid_name') }} at {{
    state_attr('sensor.modem_callerid_55ff3d54501b4d361c7abf6327d7405d',
    'cid_number') }} 

In playing around in the developer tools with TTS, I have found that if I insert a space between each number (so it is “8 0 0 1 2 3 4 5 6 7”), it will speak it as I desire.

In playing around at W3Schools Tryit Editor, I was able to create this simple python code to accomplish what I’m trying to do:

Value=str(8001234567)
Result=""
for x in Value:
  Result = Result + " " + x
print (Result)
print (Result[1:])

I’ve also looked into whether there is an option in the API to speak each number, but I don’t see anything like this (of course not, that would make sense, right?).

I’ve been running into issues trying to implement this in HA. When using the UI, I switch to YAML to type the code in, and then it disappears on me after saving and closing it.

Can anyone give this newby a helping hand?

Thanks!
Wayne

try:

{{ state_attr(‘sensor.modem_callerid_55ff3d54501b4d361c7abf6327d7405d’,
‘cid_number’) | replace(‘’,’ ') }}

That is so beautifully simple, and it works.
I had found several similar posts on the internet, but never a solution.
Thanks, Brian!