Echo Devices (Alexa) as Media Player - Testers Needed

@alandtse

Yep same here, my email and password are right in the logs, but I’m still in an endless captcha loop. :frowning:

Stealing this - works great for my dark sky sensor, but how would I edit to to read the state of a light.lamp, to see if it is off or on?

I tried using

{{states.state.light.lamp}} nothing happens
or {{states.light.lamp}} (it reads out all attributes of the lamp, but not off/on state at all?

when i do something like that it will only tell me the name of sensor never tells me is value is there something i have to enable?

try {{ states.light.lamp.state }}

1 Like

@boxgrove, @vMeph

I have this, and it’s working fine:

entity_id: media_player.batman
message: “ Hello! Michael, Living lights are {{ states.light.fibaro_system_fgd212_dimmer_2_level_6.state }}, and current brightness is set at {{ states.light.fibaro_system_fgd212_dimmer_2_level_6.attributes.brightness }} percent !  ... You asked how many lights are on ?! ... {{ states.sensor.number_of_lights_on.state }} ! ...

Feel free to replace light.fibaro_system_fgd212_dimmer_2_level_6 with your light device and for brightness, you just add the attribute part. You can see what attributes your device supports and shows, in your states panel:

Here, … :slight_smile: … take this:

… and as a bonus, this is my “how many lights are ON” sensor:

- platform: template
  sensors:
    number_of_lights_on:
      value_template: >-
        {% for state in states if ( 'light' in state.entity_id and state.domain in ['light','switch'] and state.state == 'on' ) -%}
              {% if loop.last -%}
              {{ loop.index }}
              {%- endif %}
              {% else %}
                  0
        {%- endfor %}
      entity_id: sensor.time

Pro tip: If you make all, and I mean ALL of your sensors dependent of the time sensor, you will never get that Timer Out of Sync error in your logs ever … took me at least 2 years to figure it out … that is why all my sensors have entity_id: sensor.time at the end of their template statement … :slight_smile:

Here it is :

- platform: time_date
  display_options:
    - 'time'

Have a hell of a good time friends … :slight_smile:

8 Likes

I have written an Audit program using Appdeamon nick the code from that :slight_smile:

(I only have Echo Dots) I saw the media_player offers a source selection and wanted to try to switch from the connected receiver to the built in speaker but couldn’t get it to work. I changed the source from “Local Speaker” to “Proprietaire” but nothing happened.

Basically I want the Echo Dot to switch to its own speaker when the receiver is on another input e.g. “Gaming” so I can still hear Alexa.

Is this currently supported?

I have not set it up fully yet, but had a great idea using this and IFTTT. I already have an IFTTT trigger for alexa timers, Just sends me an IFTTT notification when any timer goes off. It would be super easy to do this
if - ALEXA TIMER then webhook. The webhook would be something like this

Then just create a script that sends a simple message to all alexa devices. - Your timer is going off.

I know you cant stop the timer from another echo, but would be nice if you got a reminder if you were away from a kitchen timer, or whatever.

Super cool. can you give a few more details on the sensor.time addition? I dont think I’ve every had timer out of sync errors, but maybe I just dont have enought stuff going on yet, and will run into this in the future, :slight_smile:

Thank you sooo much - very helpful!

Awesome - thank you

I think I might have had a out dated alexa.py file.
make sure you are using the most current version.

Everything has been working perfectly since I did this even with restarts and best of all no more captcha!!

is there a way to change the time and date format this way so I can have a 12 hour clock and the date be Month/day/year?

Oh, oh, … I know this one !! … :slight_smile: … let me open the Golden Book of sensors just for you … :slight_smile:

No.1 = Time sensors (conventional & AM/PM formats)

I have a file called time_sensors.yaml, in my ha_dir/includes/sensors directory.
Here … have a look inside:

  # Time sensor (as we know it)
- platform: time_date
  display_options:
    - 'time'
#    - 'date'

  # Time sensor (as I want it)
- platform: template
  sensors:
    time_templated_am_pm:
      friendly_name: 'Time AM/PM'
      value_template: "{{ now().strftime('%I:%M %p') }}"
      entity_id: sensor.time

That content will give you this:

No.2 = Date sensor (European format, and with “Months” in your native languge … Romanian in my case)

I have a file called date_sensors.yaml, in my ha_dir/includes/sensors directory.
Here … have a look inside:

- platform: template
  sensors:
    date_european_format:
      friendly_name: 'Data Completa'
      value_template: >
        {% set months = ["Ianuarie", "Februarie", "Martie", "Aprilie", "Mai", "Iunie", "Iulie", "August", "Septembrie", "Octombrie", "Noiembrie", "Decembrie"] %}
        {% set month = months[now().strftime('%m') | int -1] %}
        {{ now().strftime('%d') + ' ' + month + ' '+ now().strftime('%Y') }}
      entity_id: sensor.time

You can change the order of these parameters …
{{ now().strftime('%d') + ' ' + month + ' '+ now().strftime('%Y') }}
…to make it appear as you wish (in what order you like/use to see it).

That content will give me this (the date in my native language and in the format that I’m most used to see it):

NOTE: For you, maybe it’s easy just to template like this: {{ now().strftime('%b %d, %Y') }}
The result is this:

date_templated_us:
  friendly_name: 'Date US Style'
  value_template: "{{ now().strftime('%b %d, %Y') }}"
  entity_id: sensor.time

No.3 = PRO bonus sensors … :slight_smile:
3.1 = Time since last OS restart, templated
3.2 = Time since last HA restart, templated

Remember that file called time_sensors.yaml ? from No.1, above, in my ha_dir/includes/sensors directory.
Here … have deeper look inside … :slight_smile: :

3.1 = OS time since last boot

- platform: template
  sensors:
    since_last_boot_templated:
      value_template: >-
        {%- set slb = states.sensor.since_last_boot.state.split(' ') -%}
        {%- set count = slb | length -%}
        {%- set hms = slb[count - 1] -%}
        {%- set hms_trimmed = hms.split('.')[0] -%}
        {%- set hms_split = hms_trimmed.split(':') -%}
        {%- set hours = hms_split[0] | int -%}
        {%- set minutes = hms_split[1] | int -%}
        {%- set seconds = hms_split[2] | int -%}
        {%- if count == 3 -%}
          {{ slb[0] ~ ' ' ~ slb[1] ~ ' ' }}
        {%- endif -%}
        {%- if hours > 0 -%}
          {%- if hours == 1 -%}
            1 hour
          {%- else -%}
            {{ hours }} hours
          {%- endif -%}
        {%- endif -%}
        {%- if minutes > 0 -%}
          {%- if hours > 0 -%}
            {{ ', ' }}
          {%- endif -%}
          {%- if minutes == 1 -%}
            1 minute
          {%- else -%}
            {{ minutes }} minutes
          {%- endif -%}
        {%- endif -%}
        {%- if seconds > 0 -%}
          {%- if hours > 0 or minutes > 0 -%}
            {{ ', ' }}
          {%- endif -%}
          {%- if seconds == 1 -%}
            1 second
          {%- else -%}
            {{ seconds }} seconds
          {%- endif -%}
        {%- endif -%}
      friendly_name: "Uptime OS Detaliat"
      entity_id: sensor.time

That content, will give you this, OS time since restart:

3.1 = HA time since last boot

- platform: command_line
  name: "HA Uptime"
  command: echo "$(($(date +%s) - $(date -d "$(head -n1 /config/home-assistant.log | cut -d' ' -f-2)" +%s)))"
  scan_interval: 60
  value_template: >-
    {% set uptime = value | int %}
    {% set seconds = uptime % 60 %}
    {% set minutes = ((uptime % 3600) / 60) | int %}
    {% set hours = ((uptime % 86400) / 3600) | int %}
    {% set days = (uptime / 86400) | int %}
    {%- if days > 0 -%}
      {%- if days == 1 -%}
        1 day
      {%- else -%}
        {{ days }} days
      {%- endif -%}
      {{ ', ' }}
    {%- endif -%}
    {%- if hours > 0 -%}
      {%- if hours == 1 -%}
        1 hour
      {%- else -%}
        {{ hours }} hours
      {%- endif -%}
      {{ ', ' }}
    {%- endif -%}
    {%- if minutes > 0 -%}
      {%- if minutes == 1 -%}
        1 minute
      {%- else -%}
        {{ minutes }} minutes
      {%- endif -%}
    {%- endif -%}
  entity_id: sensor.time

That content, will give you this, HA time since restart:

Have a lovely day … I know you will use some of this … :slight_smile:

2 Likes

Timer out of sync. Resetting.

It’s a well known issue from the beginnings of HA. Some components in some setups throw this in your log, sometime every few seconds. Can you imagine what is like to have your log full of this and I mean full … hundreds of rows of log just screaming … timer out of sync … :slight_smile:

It all starts differently for all of us and the problem is that it’s a bitch of an error to diagnose.
Sometimes disabling the last thing you enabled, works to get rid of it and bring your setup to a “normal state”, but what if you really want/need that feature which throws the error for your setup ? … you learn to live with it. I did … for 2 years.
Some of us have slow hardware platforms, some of us just have poorly configured components, some of us just ask too much to happen in a small time frame … if you haven’t heard of it by now, good for you … other lives have been touched … :slight_smile: … see here: Google search

All in all, if you configure all your sensors to relate to time by the sensor.time sensor, you are all good to go.

See how to create it (sensor.time), here: Time/Date Sensor or in my post right above this one, at No.1

3 Likes

Thanks for this very useful post. I have never had this issue, but it might be because I’m running on an older repurposed HTPC. i3 processor, 4gb ram, 256 SSD. But with that said, it looks like an easy thing to so, and could save me future issues. I already have the date time sensor set up, so it’s almost a no brainer.

I sometimes sit back and look at where I am today only 3 months or so after moving to HA, and am amazed. I love this system.

Corey,
Can you call this script in a automation?

If so would this be correct?
{ “entity_id”: “family_room_2”,
“message”: “This is a test”
}

This would be the script

alexa_notify:
  alias: 'Test Notification'
  sequence: 
    - service: media_player.alexa_tts
      data_template:       
        entity_id: media_player.family_room_2
        message: "This is a test"

and this would be the action part of your automation

 action:
  - service: script.turn_on
    entity_id: script.alexa_notify
2 Likes

Does anyone have any devices showing up that are not part of your echo ecosystem anymore. By that I mean I’ve given away a few echos over the years, when I upgraded. Anyway, I have one device that shows up as available, that does not show up in alexa.amazon.com and I’ve tried testing playing music on it, and walking around the house. Nothing came up. Lastly I called the people I had given an echo to and asked them if their echo’s were playing music suddenly. Nope.

It’s not a big deal, I just renamed it to _unused, but curious, if anyone had seen anything similiar

1 Like

Any change to use alexa TTS in a Notify Group?

- name: fullhouse
platform: group
services:
  - service: telegram
  - service: media_player.alexa_tts
    data:
    - entity_id: media_player.dot

does not work, it fails the configuration check :frowning: