Alexa TTS/Announcement from Lovelace UI and without Nabu Casa (Alexa Media Player)

Send a notification via the Lovelace-UI to your Alexa-Devices. You can create an elements card with an input select and a input text like shown in the picture below. You can specify if the messages should be delivered via “TTS” or “Announce” an which devices should be selectable for the notifications. No Nabu Casa or exposing your HA-Instance to the internet required.

Screenshot 2020-12-26 144026

Requirements

  • Alexa Media Player must be installed. It can be installed from the Home Assistant Community Store (HACS)
  • Input text must be created. This contains the message.
  • Input select must be created. This contains the target. The options contain the alexa devices which should be allowed to be selected to play the notification. The options can contain the friendly Name, Serial Number, entity_id, or Home Assistant Group.

How to use

  1. Select the target (or left the right one if already selected)
  2. Type the message in
  3. Hit enter! After this the automation is fired.

Blueprint:

blueprint:
  name: Alexa Media Player TTS/Announce from Lovelace UI
  description: Send a notification (TTS/Announcment) via the Lovelace-Ui with the help of a input select and input text. Uses the TTS component from Alexa Media Player which can be installed from the Home Assistant Community Store (HACS).
  domain: automation
  input:
    message:
      name: Message of the notification (Input Text)
      description: Input text where the message comes from
      selector:
        entity:
          domain: input_text
    target:
      name: Target of the notification (Input Select)
      description: The alexa device where the notification should be played. Must be in a input select. Options can be the Friendly Name, Serial Number, entity_id, or Home Assistant Group.
      selector:
        entity:
          domain: input_select
    announce:
      name: Is announcment
      description: Specify if announce-feature should be used. If not, the notification will be a standart text-to-speech.
      default: false
      selector:
        boolean:

mode: queued
max_exceeded: silent

variables:
  message_to_say: !input message
  target_for_message: !input target
  is_announce: !input announce

trigger:
  - platform: event
    event_type: state_changed
    event_data:
      entity_id: !input message

condition: []
action:
  - service: notify.alexa_media
    data:
      message: "{{ states(message_to_say) }}"
      data:
        type: >
          {% if is_announce %}
            announce
          {% else %}
            tts
          {% endif %}
      target:
        - "{{ states(target_for_message) }}"

Changelog

  • 2021-01-10: Set default value to the announce input
9 Likes

Sounds interesting, but I don’t get it…

How do you create the requirements. I have Alexa installed via HAS (and it works fine)… but the input text and input selection is a big mystery to me. When selecting them, no choices are available?

I think you forgot to set up the input text and input select. To create them via UI you have to navigate to settings --> helpers. See the next missing steps below.

  • Input text must be created. You have not to put any specifiy in, just make shure to name it properly so you can find it.
  • Input select must be created. The options contain the alexa devices which should be allowed to be selected to play the notification. The options can be named with the friendly Name, Serial Number, entity_id, or Home Assistant Group. Make shure to make this right, cause a simple misspell or something similiar can break the blueprint
  • Put the created input text and input select anywhere in your lovelace UI from where you can access it. I have done it via a elements card
  • Now set up the blueprint and make a automation with it.

If you have created the helpers, it should be pickable in the blueprint, but like above mentioned it only works right if you put the right options in the input select.

Fantastic… it works! thank you :smiley:

Edit: Sending from a desktop browser works fine… upon hitting the return/enter key, the message is sent… but I can’t seem to make them send from a mobile… pressing the return key on the mobile ‘iOS Safari’ doesn’t seem to send anything?

Just add a button and call a service, see How can I execute an automation from a Lovelace button?. Mine looks like

type: vertical-stack
cards:
  - type: entity
    entity: input_text.swa_alexa_text
  - type: button
    tap_action:
      action: call-service
      service: automation.trigger
      service_data:
        entity_id: automation.alexa_media_player_tts_announce_from_lovelace_ui
    show_icon: true
    show_name: false
    show_state: false

I’m not too happy with the result, yet. The button is just a rectangle that can be pressed, not yet an icon…

just add icon: 'mdi:account-voice' into your card (or another icon) and you’re good to go

1 Like

Thank you, that got me thinking… I’ve used your idea and put together this!

type: grid
columns: 1
square: false
cards:
  - type: grid
    columns: 2
    square: false
    cards:
      - type: entities
        entities:
          - entity: input_select.alex_devices
      - type: button
        tap_action:
          action: call-service
          service: automation.trigger
          service_data:
            entity_id: automation.alexa_tts_announce_from_lovelace
        entity: zone.home
        show_icon: true
        name: Send
        icon: 'mdi:send'
        show_name: false
        icon_height: 50px
        hold_action:
          action: none
  - type: grid
    columns: 1
    square: false
    cards:
      - type: entities
        entities:
          - entity: input_select.alexa_messages


Thanks for Replying @Gav_in and @swa72. I dont use ios so I havent this problem, in Android it works fine with the shown parts. The way they showed should work perfectly fine.

Technically it should be triggerd when the state changes in the input text. This should happen when you change the text and hit the return/enter key (So if you hit enter without changing the message, it doesnt trigger). Dont know why this doesnt work on ios or safari. I would guess that Apple seems to avoid architectural standards again

geat blueprint, any chance for using with google home and nabu casa?

Sorry for the late response. Had some busy days.

I dont have nabu casa, so i dont know and cant test the services behind them. But in Theory this should be possible, just replace the service part with the service provided below. As said i cant test them, so you have to try. As a drawback you have to put the entity ids into the inoput select i think.

service: tts.cloud_say
data:
  message: "{{ states(message_to_say) }}"
  entity_id: "{{ states(target_for_message) }}"

Here’s your blueprint modified to work with Nabu Casa, as well as removed the bug that if you click anywhere in lovelace it plays the text.

blueprint:
  name: Alexa Media Player TTS/Announce from Lovelace UI - Cloud
  description: Send a notification (TTS/Announcment) via the Lovelace-Ui with the
    help of a input select and input text. Uses the TTS component from Alexa Media
    Player which can be installed from the Home Assistant Community Store (HACS).
  domain: automation
  input:
    message:
      name: Message of the notification (Input Text)
      description: Input text where the message comes from
      selector:
        entity:
          domain: input_text
    target:
      name: Target of the notification (Input Select)
      description: The alexa device where the notification should be played. Must
        be in a input select. Options can be the Friendly Name, Serial Number, entity_id,
        or Home Assistant Group.
      selector:
        entity:
          domain: input_select
    announce:
      name: Is announcment
      description: Specify if announce-feature should be used. If not, the notification
        will be a standart text-to-speech.
      default: false
      selector:
        boolean: {}
  source_url: https://community.home-assistant.io/t/alexa-tts-announcement-from-lovelace-ui-and-without-nabu-casa-alexa-media-player/259980
mode: queued
max_exceeded: silent
variables:
  message_to_say: !input 'message'
  target_for_message: !input 'target'
  is_announce: !input 'announce'
trigger:
condition: []
action:
- service: notify.alexa_media
  data:
    message: '{{ states(message_to_say) }}'
    data:
      type: tts
    target: '{{ states(target_for_message) }}'

I’ve got this all working except for the announce part. Do you know what needs to be done to make it work with Nabu Casa?

Thanks!!