Obihai - Announce caller ID on google home (confirmed working 2024)

This is an update of Xelloss99’s Obihai announce caller id (which no longer works due to changes in tts)

From original post (Obihai - Announce caller id on Google Home): Here is a blueprint to announce caller ID (name and number) on a Google Home media player device whenever a phone on port 1 of an Obihai device rings.

Requires Obihai integration, Google Home media player device (uses tts.google_translate_say service)
This will only announce calls on port 1 of the Obihai device!

You can specify the media player of a Google Home device (or a Google Home group) to play on.
Optionally, you can specify an entity name and condition in order to announce the caller id.
This can be used to only announce the caller ID when a person (or person group) is home, when a presence sensor detects someone in the room, or when a privacy mode or quiet mode input_boolean is off.

The phone number format announced is only for 10 digit North American phone numbers.

  name: Obihai - Caller ID on Google Home
  description: Announce incoming caller ID on Google Home
  domain: automation
      name: Google Home media player
      description: Google Home media player device to announce caller ID on
          - media_player
          multiple: false
      name: Condition entity (optional)
      description: 'Entity checked for condition in order to announce Caller ID. Examples:

        person.person_name for person presence,

        binary_sensor.presence_sensor for sensor presence,

        input_boolean.privacy_mode for privacy or quiet mode, etc.

        Leave blank for no conditions.

        entity: {}
      name: Condition state (optional)
      description: 'State that the above entity must be in order to announce Caller
        ID. Examples:

        ''home'' for person entity, ''on'' for presence sensor, ''off'' for privacy
        or quiet mode

        (don''t enter the quotes). Leave blank for no conditions.

mode: restart
max_exceeded: silent
  condition_entity: !input condition_entity
  condition_state: !input condition_state
- entity_id: sensor.obihai_phone1_port
  for: '1'
  platform: state
  to: Ringing
- condition: template
  value_template: '{{ (condition_entity == none) or (states[condition_entity].state
    == condition_state) }}

- service: tts.speak
    entity_id: tts.google_en_com
    language: en
    #you can put more than one media player below with a comma and space
    media_player_entity_id: media_player.kitchen_speaker
    message: '{% set callerid = states(''sensor.obihai_phone1_port_last_caller_info'')
      %} {% if callerid == ''--'' %} {{ "Incoming call from unknown number" }} {%
      else %} {% set name = callerid[0:-12] %} {% set num = callerid[-10:] %} {% set
      numstring = num[0]+" "+num[1]+" "+num[2]+","+num[3]+" "+num[4]+" "+num[5]+","+num[6]+"
      "+num[7]+" "+num[8]+" "+num[9] %} {{ "Incoming call from "+ name + "," + numstring
      }} {% endif %}'