Echo Devices (Alexa) as Media Player - Testers Needed

script.yaml

say_greeting:
  sequence:
    service:
      - media_player.alexa_tts
    data_template:
      entity_id: "{{ entity_id }}"
      message: "{{ message.replace('PERSON',person) }}"

automation.yaml

- id: family_greeting
  alias: Family Greeting
  trigger:
    platform: state
    entity_id:
      - binary_sensor.cameron_home
      - binary_sensor.corey_home
      - binary_sensor.courtney_home
      - binary_sensor.mom_home
      - binary_sensor.morgan_home
      - binary_sensor.wendy_home
      - binary_sensor.andy_home
      - binary_sensor.jasmine_home
      - binary_sensor.brandon_home
    from: 'off'
    to: 'on'
    for: '00:00:05'
  action:
    - wait_template: "{{ is_state('script.say_greeting', 'off') }}"
    - service: script.say_greeting
      data_template:
        entity_id:
          - "media_player.livingroom,media_player.bedroom,media_player.courtneys_room"
          - media_player.fire_speaker
        person: >
          {{ trigger.to_state.name }}
          {%- for s in states.binary_sensor
                |rejectattr('entity_id','eq',trigger.entity_id)
                |selectattr('state','eq','on')
                if '_home' in s.entity_id and
                   (now() - s.last_changed).total_seconds() < 60 -%}
            {{ (' and ' if loop.last else ', ') ~ s.name }}
          {%- endfor %}
        message: >
          {{ ["Welcome back home PERSON",
              "Guess who is home PERSON is!",
              "PERSON is now in the house.",
              "Welcome Home PERSON  We have missed you Or at least I did.",
              "Attention Everybody PERSON is home I repeat PERSON is home Welcome home PERSON",
              "Our home is now complete, Rest your head and relax your feet, Welcome Back PERSON",
              "Life is like a song, you’re back where you belong, Welcome home PERSON",
              "Hey there PERSON Welcome Home!",
              "Knock Knock. Who is There? PERSON is!",
              "PERSON, you are home!",
              "I know a secret. PERSON is home!",
              "PERSON it's nice to see you again. Right where you belong. Welcome home PERSON",
              "O M G it's PERSON. Oh how I missed your face. Welcome home",
              "Welcome back to the best house in th 3 3 0 PERSON",
              "Oh Goodie PERSON is home. Welcome back",
              "When PERSON is here we are complete. Its nice to see you PERSON"
              "Its not the same when PERSON isn't here, so from the MAXIM's welcome home"
             ] | random }}

[/quote]

This is what I use to welcome my family home, Feel free to change it based on your needs.

9 Likes

Here is one of the automation that calls the script and pass the appropriate variables

#Automation - Announce garage status changed
- alias: Garage State Notification
  trigger:
    platform: state
    entity_id: cover.left_garage, cover.right_garage
  action:
    - service: script.audio_notify
      data_template:
        tts_msg: "The {{ trigger.to_state.attributes.friendly_name }} is: {{ trigger.to_state.state }}"
        mplayer: "kitchen"

And here is the script

#TTS Script		
audio_notify:
  sequence: 
    - service: media_player.alexa_tts
      data_template:       
        entity_id: media_player.{{ mplayer }}         
        message: "{{ tts_msg }}"
5 Likes

This is awesome, Thanks for sharing!

OK, since I couldn’t get my question above answered I just gave it a shot…

I put the alexa.py script in the custom_components/media_player/ directory and I put the entry into the configuration.yaml with no quotes.

restarted HA.

Here is what I got:

the configurator window pops up and when I click on “configure” I get the captcha box. After I put in the captcha code the captcha box closes but the configurator box remains.

I don’t see any of my echo dots in my entities.

If I click the configure button again the new captcha pops up and says failed to login. I’ve tried a few times to re-enter the different captcha’s just to make sure I didn’t enter them wrong.

I get the following error in the log:

2018-08-09 09:36:28 ERROR (SyncWorker_8) [custom_components.media_player.alexa] Error loading pickled cookie to /config/alexa_media.pickle: An exception of type FileNotFoundError occurred. Arguments:
(2, ‘No such file or directory’)

Anything else I need to check or do differently?

With the latest release after a reboot I was presented with the capthca. It kept saying that I’d typed it in wrong so I entered nothing and submitted it, after that I was presented with another captcha and I DID enter it. That worked.

Hello Corey,

It looks like your say_greeting script is very similar to my audio_notify script. My problem is that I don’t know a good way to determine when the script is off or when my echo has finished playing the dynamic content in short TTS bursts. For example, I come home there are several TTS announcements that occurs back to back.

  1. Random welcome message
  2. Temperature report and setting for two different thermostat
  3. Announce that it is about to turn on the TV
  4. etc…

This message is only to report that the addon no longer shows in the hassio panel as of the most recent HA upgrade to 0.75.2. Yay!

image

Confirm you don’t have 2FA enabled and you can log into amazon without needing anything other than the password. I disabled 2FA to test this component and after you make a change to your amazon account the subsequent log-on can require an additional verification step (enter code from text/e-mail). After I sorted my normal amazon log-in the component work flawlessly.

I’ve never used 2FA on my amazon account so I’m sure that’s not the problem. And I haven’t gotten any warning emails from Amazon about any failed login attempts.

Could a special character in the password cause issues? I have a # buried in there.

I believe if you have #, that you’ll need to surround it in quotes " or ’

Even with 2FA off they can ask to receive a code to verify your new login.

The # is likley the issue. In Yaml a # is interpreted as everything after (including the #) is ignored. I would try putting ‘quotes’ or “quotes” around your password. HA can be picky about quotes so be sure to try both if the first doesn’t work.

I tried putting both " and ’ around the whole password but it’s still failing.

However I never thought about the # in the password being seen as a comment. Duh… I’ve been commenting yaml files for a year and until just now I never thought about that being a problem!

Unfortunately in this case it didn’t seem to work.

I even tried to delete the pycache folder in the custom component directory and still no luck.

Are you using secrests.yaml for your password? I’m often wondered if you used secrets and had a # if you quote like this

!secret "amazonpassword"

or this

!secret amazonpassword

Secrets yaml
amazonpassword: "this#isatext#"

And with that question I need to amend my above post…

I use !secrets and in my secrets file I have the passwords with special characters written with no quotes:

mqtt:
  broker: 192.168.1.11
  port: 1883
  client_id: home-assistant-3
  username: !secret MQTT_user  
  password: !secret MQTT_password

secrets.yaml:

MQTT_password: AbcDef#567

So I guess using the # in passwords without quotes should work in a yaml file. At least it does everywhere else in HA that I’ve used the same form of password.

I’m also getting an error about pickled cookies, saying alexa_media_pickle doesn’t exist. Does anyone know anything about this?

How would you do multiple echos? Group or just multiple actions?

Something else I noticed is that when the pycache directory gets created it is created by root. I’m not sure why that is.

My HA and docker user are both finity and the alexa.py file is owned by finity.

Could a permissions issue be causing the login failure problem I’m having? and why is the pycache folder created and owned by root?

I am as well.

You can ignore it. It should stop appearing in the next version. A check for file existence was removed so it’s always assuming the file was there even if it wasn’t.