Echo Devices (Alexa) as Media Player - Testers Needed

But we’re not using a skill. And the strings we send don’t support SSML. With the technique used for this media player, you can’t send arbitrary audio files, which is necessary if you want to use Polly.

I know, I wrote the post above for 3 reasons:

  1. To be the one who gets to write post No.700 … :-), I just had to (child in me hasn’t died yet)
  2. To make a point, simple question = simple answer, the question is quoted, he did not relate it in any way with alexa.tts … he just asked if you can use Polly with Alexa … technically you can … easily … :slight_smile:
  3. To entertain myself
1 Like

Well, logically you got the point.

But if you use the context of this topic, I want to use the current component with home assistant to play TTS using Polly to synthesize the words. :slight_smile:

1 Like

ok… I got it to work but seems the solution was strange based on others comment for the URL.

I changed alexa.amazon.com to just amazon.com

I discovered this by going through the alexa.py file and found the login url with the /gp/sign_in.html. I manually tried that URL in a browser and got an exception. So I took the alexa part out and got a sign in page. Made the change in configuration.yaml and --walaaa-- my echo devices show up.

Love seeing the album art and being able to play, pause, skip.

Volume controls don’t seem to work and TTS in the media card doesn’t work but does from the service (she will even tell you that if you try :slight_smile: )

Looking good so far. Look forward to this becoming more feature-ful / stable in the future.

Thanks, alandtse. I didn’t have Logger in my configuration.yaml file for some reason. I was just getting very basic messages in the log. I added the info at your link and am now seeing lots of interesting data.

I just added this to my configuration and everything appeared to be setup properly. I can send tts through the services panel and I can hear it being played on my various devices. However when I add the media player card to my Lovelace setup this is what I see. I have no control. If this correct? I was expecting it to be like all my other media player cards. All my echos seem to be in “standby” mode. Does it only appear like the screenshots in the beginning of this thread when a song is playing?

Echo_Dot_MediaCard

Sorry to ask again, you say all of your sensors, but do you mean ALL, or just all templated Sensors

Like this one Yes

      house_mode:
        value_template: '{{ states.input_select.house_mode.state }}'
        friendly_name: 'House Mode'
        icon_template: >
            {%- if is_state('input_select.house_mode', 'Home') -%}
                mdi:home-account
            {%- elif is_state('input_select.house_mode', 'Away') -%}
                mdi:run-fast
            {%- elif is_state('input_select.house_mode', 'Night') -%}
                mdi:weather-night
            {%- else -%}
                mdi:help
            {%- endif -%}
        entity_id: sensor.time

but would you also for this binary sensor template

 - platform: template
   sensors:
     garage_fridge_warm:
       value_template: "{{ states('sensor.temp_garage_fridge') | float > 40.0 }}"
       entity_id: sensor.time

Lastly, I set this up really not understanding what the purpose of adding entiry_id really was.

 - platform: template
   sensors:
     downstairs_smoke_detector_smoke:
       value_template: "{{ is_state('sensor.smoke_detector_downstairs_alarm_type', '1') }}"
       friendly_name: "Smoke Detector - Smoke"
       entity_id: sensor.smoke_detector_downstairs_alarm_type

Should I replace sensor.time, can I have two? Or is it fine as is?

Thanks again, I’ve added sensor.time to many of my sensors so far, just not sure about these last few

Edit, will adding this to battery templates cause the device to be polled every minute, draining the battery faster?

No problem asking.
So the answer is still … “all” your sensors, and to clarify, in my head, there are sensors and binary_sensors:slight_smile:

Regarding sensors = YES / ALL
Regarding binary_sensors (all flavours) = NO / you can’t (ok you can if you insist), but you should not, because, if you look HERE you’ll see that the entity_id part is already taken by the entities you want translated. When that entity changes state, you want your custom made sensor to also change state.

Here are some of my binary sensors:

Fibaro door/window Z-Wave sensor:

mc_sensor_baie_usa:
  device_class: door
  friendly_name: USA Baie
  value_template: >
    {{ states.binary_sensor.fibaro_system_fgk10x_door_opening_sensor_sensor.state != 'off' }}
  entity_id: binary_sensor.fibaro_system_fgk10x_door_opening_sensor_sensor

Fibaro door/window Z-Wave+ sensor:

mc_sensor_hol_usa_intrare:
  device_class: door
  friendly_name: USA Intrare
  value_template: >
    {{ states.sensor.fibaro_system_fgdw002_door_opening_sensor_2_access_control.state != '23' }}
  entity_id: sensor.fibaro_system_fgdw002_door_opening_sensor_2

Fibaro 3in1 motion sensor:

zwave_sensor_living_state:
  friendly_name: 'Senzor Z-Wave Sufragerie'
  value_template: >-
    {% if states.zwave.fibaro_system_fgms001_motion_sensor.state == 'initialized' %}
      Offline
    {% else %}
      Online
    {% endif %}
  entity_id: zwave.fibaro_system_fgms001_motion_sensor

Hikvision camera sensor:

camera_elind_motion_detected:
  device_class: motion
  friendly_name: IP-Camera ELIND
  value_template: "{{ is_state ( 'camera.elindintrare', 'recording' ) }}"
  entity_id: camera.elindintrare

You notice that, as stated in the HA “wiki”, the entity_id part points to the entity or the entity attribute you want to translate into your custom made sensor.

PRO Tip:
As for my battery levels, I have that handled by an automation.
Ok, there are 2 automations, but one of them is doing the heavy lifting.
NO SENSORS for me.
Long time ago, I went the sensor way for battery info … the polling killed the “target”, the battery drainage was noticeable.
So I monitor everything I want using this kind of abomination … :slight_smile: … feel free to adapt to your needs:

Automation No.1 (data collection and notification) …

- alias: battery_alert
  trigger:
   
    - platform: time
      at: '09:55:00'
    - platform: time
      at: '19:55:00'

  condition:
    - condition: template
      value_template: >
        {%- set threshold_high = 55 -%}
        {%- set threshold_low = 0 -%}
        {% macro battery_level() %}
        {% set domains = ['light', 'switch', 'zwave', 'lock'] %}
        {% for domain in domains -%}
        {% for item in states[domain] if ((item.attributes.battery_level is defined and item.attributes['battery_level'] | int < threshold_high and item.attributes['battery_level'] | int > threshold_low) or ("battery" in item.name | lower and ((item.state | int < threshold_high and item.state | int > threshold_low and item.state|int != 0) or item.state | lower == "low" or item.state | lower == "unknown"))) -%}
        {% if (item.attributes.battery_level is defined and item.attributes['battery_level'] | int < threshold_high and item.attributes['battery_level'] | int > threshold_low) -%}
        {{ item.name }}{% endif -%}
        {% if "battery" in item.name | lower and ((item.state | int < threshold_high and item.state | int > threshold_low and item.state|int != 0) or item.state | lower == "low" or item.state | lower == "unknown") -%}
        {{ item.name }}{% endif -%}
        {% endfor %}
        {%- endfor %}
        {% endmacro %}
        {{ battery_level() |trim != "" }}

  action:
    - service: persistent_notification.create
      data_template:
        title: "Low Battery Levels"
        notification_id: low-battery-alert
        message: >
          {%- set threshold_high = 55 -%}
          {%- set threshold_low = 0 -%}
          {% macro battery_level(domain) %}
          {%- for item in states[domain] if ((item.attributes.battery_level is defined and item.attributes['battery_level'] | int < threshold_high and item.attributes['battery_level'] | int > threshold_low) or ("battery" in item.name | lower and ((item.state | int < threshold_high and item.state|int != 0) or item.state | lower == "low" or item.state | lower == "unknown"))) -%}
          {% if (item.attributes.battery_level is defined and item.attributes['battery_level'] | int < threshold_high and item.attributes['battery_level'] | int > threshold_low) -%}
          {{ item.name }} ({{ item.attributes['battery_level'] }}){%- if not loop.last %}, {% endif -%}{%- endif -%}
          {%- if "battery" in item.name | lower and ((item.state | int < threshold_high and item.state | int > threshold_low and item.state|int != 0) or item.state | lower == "low" or item.state | lower == "unknown") -%}
          {{ item.name }} ({{ item.state }}){% if not loop.last %}, {% endif %}{% endif -%}
          {%- endfor -%}
          {% endmacro %}
          {%- set domains = ['light', 'switch', 'zwave', 'lock'] -%}
          {%- for domain in domains if battery_level(domain) |trim != ""-%}
          {{ battery_level(domain) }}{%- if not loop.last %}, {% endif -%}
          {%- endfor -%}
#    - service: notify.slack_notify
#    - service: notify.secret_base_mihai
    - service: notify.ios_penis_captivus
      data_template:
            title: "HOME devices have low battery levels:"
            message: >
              {%- set threshold_high = 55 -%}
              {%- set threshold_low = 0 -%}
              {% macro battery_level(domain) %}
              {%- for item in states[domain] if ((item.attributes.battery_level is defined and item.attributes['battery_level'] | int < threshold_high and item.attributes['battery_level'] | int > threshold_low) or ("battery" in item.name | lower and ((item.state | int < threshold_high and item.state|int != 0) or item.state | lower == "low" or item.state | lower == "unknown"))) -%}
              {% if (item.attributes.battery_level is defined and item.attributes['battery_level'] | int < threshold_high and item.attributes['battery_level'] | int > threshold_low) -%}
              {{ item.name }} ({{ item.attributes['battery_level'] }}){%- if not loop.last %}, {% endif -%}{%- endif -%}
              {%- if "battery" in item.name | lower and ((item.state | int < threshold_high and item.state | int > threshold_low and item.state|int != 0) or item.state | lower == "low" or item.state | lower == "unknown") -%}
              {{ item.name }} ({{ item.state }}){% if not loop.last %}, {% endif %}{% endif -%}
              {%- endfor -%}
              {% endmacro %}
              {%- set domains = ['light', 'switch', 'zwave', 'lock'] -%}
              {%- for domain in domains if battery_level(domain) |trim != ""-%}
              {{ battery_level(domain) }}{%- if not loop.last %}, {% endif -%}
              {%- endfor -%}
            target: "device/MIHAI - iPhone 7"

Automation No.2 … (the dismiss)

- alias: battery_alert_clear
  trigger:
    - platform: time
      minutes: '/30'
      seconds: 00
  condition:
    - condition: template
      value_template: >
        {%- set threshold_high = 55 -%}
        {%- set threshold_low = 0 -%}
        {% macro battery_level() %}
        {% set domains = ['light', 'switch', 'sensor', 'zwave', 'lock'] %}
        {% for domain in domains -%}
        {% for item in states[domain] if ((item.attributes.battery_level is defined and item.attributes['battery_level'] | int < threshold_high and item.attributes['battery_level'] | int > threshold_low) or ("battery" in item.name | lower and ((item.state | int < threshold_high and item.state | int > threshold_low and item.state|int != 0) or item.state | lower == "low" or item.state | lower == "unknown"))) -%}
        {% if (item.attributes.battery_level is defined and item.attributes['battery_level'] | int < threshold_high and item.attributes['battery_level'] | int > threshold_low) -%}
        {{ item.name }}{% endif -%}
        {% if "battery" in item.name | lower and ((item.state | int < threshold_high and item.state | int > threshold_low and item.state|int != 0) or item.state | lower == "low" or item.state | lower == "unknown") -%}
        {{ item.name }}{% endif -%}
        {% endfor %}
        {%- endfor %}
        {% endmacro %}
        {{ battery_level() |trim == "" }}
  action:
    - service: persistent_notification.dismiss
      data:
        notification_id: low-battery-alert

What I get from this:

  1. I hate polling, if I can avoid it, I do … even at work (electronics / microcontrollers programming)
  2. I get to choose the domains I want watched (light, switch, z-wave … whatever I need) and the automation filters through devices, based on the battery level thresholds (included in the automation … min / max) … you set those, mine are 0 and 55. … all in just one neat, sweet, lovely automation … :slight_smile:
  3. It runs on preset hours (you set those also), and it tells you the name of the entities it found and their battery levels.
  4. I just love it
  5. I can’t live without it

NOTE:
This automation IS NOT of my own doing. This is the work of a group of smart fellows on some indian forums I’m part of … (at least, that is where I found it in it’s infant form and adapted to my setup). Since then, maybe it can be found on some HA threads … I don’t know … but now I give it to you, here.

Have a nice day fellows !

3 Likes

Thank you! It works perfect. Have not used scripts like this below and will now crreate more fun scripts for all my sensors.

I’m not getting out of the loop to enter the captcha. This is with v0.9.1 of the component on HA version 0.66.1 running under docker.

Any ideas ?

Lars

Be more specific please. We need details, small things, does it come up with something like this ?

image

I mean, do you encounter that Failed to login, please try again. message ? or is just a simple “little loop” ?

I’m asking because some of us have encountered “little loops” meaning that we entered the captcha once, the box containing the captcha went away but the alexa component was still showing UNCONFIGURED, so we clicked CONFIGURE again, got a new box, containing a new captcha, entered that one, the box went away again, but the component was still unconfigured … so we clicked again on configure … and in the end, after 4…5 captcha boxes, the component agreed to configure and the message went away. … little loop … :slight_smile:
It is worth mentioning that while we entered those captcha, the message Failed to login … never appeared … the captcha was always accepted … still we had to do it multiple times, until finally it was configured.

Also, your logs contain some useful messages regarding the login status / attempts / retries / captcha uses / 2FA errors ?

Hi,

thanks for your ideas. Indeed, the attempt to enter the captcha looks successful on the web UI. The captcha dialog display and after entering it goes away without any meaningful message (except service called popup).

Afterwards, the configurator item is still in the UI and I can select it once more, but again without success.

The only (possibly) meaningful log entry is

2018-08-22 22:45:17 ERROR (MainThread) [homeassistant.core] Timer got out of sync. Resetting

Not sure if this is pointing to anything. This message does not seem to come directly from alexa.py.

Lars

Ohh, that sweet Timer out of sync. Resseting … error … :slightly_smiling_face:
Me and @ptdalen have a long talk about it but we have to get you out of this first.

You may be able to get out the easy way:

No.1
Go to https://www.amazon.com/ or your amazon (uk,de,etc) and login.

No.2
Logout, login, click switch acounts, sign out there too, login there again (check that keep me signed in checkbox)

No.3
Go to your_ha_directory/custom_components/media_player/__pycache__ folder and delete that alexa.cpython-36.pyc file.
Restart HA

Come back here with some news and we’ll get out the big guns if you don’t succeed … :slight_smile:

1 Like

I’m having the same Timer got out of sync error every time I fill in the captcha box. I’ve deleted the pycache folder, but no luck.

Timer out of sync. Resetting error is not caused by this alexa component.
The deletion of that file/directory is related/for capcha/login errors fix purposes only.
If your alexa component manages to configure properly, that error is another subject.

I don’t get that error for anything else though. I literally only get it when I fill in the captcha, and I’ve been running home assistant for well over a year now and never seen it before this week. I’m sure it’s not caused by the component but it seems related. Any advice is much appreciated.

Why do you need to enter the capcha anyway ? Since alexa.py v0.8.0, the captcha is saved/persistent.
You only need to enter it once and after that, you can restart HA as many times as you need and the alexa component stays configured. I think the last alexa.py version is now 0.9.1 … try it.
You only need the captcha once … so … based on your words … the error will not come back (if nothing else on your system is causing it). Keep us posted.

I’m stuck in some kind of captcha loop where I got login failed every time. I’ve turned on debugging and the login details being sent to amazon are correct. But the configurator continues to reappear and the only error that shows in the logs is Timer got out of sync.

Edit: I am using 0.9.1. I didn’t discover the component until 0.8.0 and have tried updating every time a new version has come out as I’ve been having this error since then.

The only way I managed to get round that was to make sure my alexa url was correct, so for me it was amazon.co.uk - having said that nothing else works my echo remain in standby and my fire tab also is in standby and nothing will wake either up :frowning:

Yeah, nice … took me half of day to figure it out …
If @keithh666 is right and you don’t have your credentials sent to the right domain … correct that.
The right/correct amazon url is the one where your devices are registered.
If you do have the right “amazon” … :slight_smile: but still “fail to login” … I sent you an invite to a discution where on Post No.7 you’ll have the answer. Worked for me anyway. Try it … let us now the results.