Echo Devices (Alexa) as Media Player - Testers Needed

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:

I think I may LOVE you! lol Thank You!!

This is great! I have just installed this - and outside of the horrible capchas (thanks, Amazon…), it went well. I did a search through the thread, and I couldnt find this, so I will request this here: Is there any way to just import specific Echos?

I ask because, this imported Alexa enabled devices that are bound to my account, but I dont want in HASS - for example, some Fire tablets and an echosim… I can of course hide them, but would be nicer to just not import them :wink:

Thanks

1 Like

This passes my configuration check, have a look:

- name: zapacitii
  platform: group
  services:
    
    - service: alexa_tts
      data_template:
        entity_id: media_player.batman
    
    - service: ios
      data:
        target: "alien_hunter"

No. The device setup just enumerates everything Amazon returns from the API. You’ll see the same devices in the Alexa app.

Got EXACTLY the same issue and in my case worse as I’ve renamed them, have Sonos with Alexa in and old fire TV devices. They all show up and I’ve done the same as you and named unused but it took me ages to identify them all as I had quite a few (my own fault, early adopter :grin:)

I’d love to clean them up and get rid of them but no clue how. I’ve even tried renaming them in the entity register but no joy.

Feel your pain!

I see more in HA than shows in the app. It’s a bit of a pain

If those devices no longer exist or they aren’t associated with you then you can deregister them on the Alexa website. it’s under “settings” on the left.

They are not in my alexa app to deregister, haha. Thats the issue. I did deregister them before I gave them away. For me it’s only one., but it looks like others have a few. Weird.

1 Like

Has anyone tried to directly call the media_player.alexa_tts service from IFTTT. I was just thinking I could skip having to create a script or automation for a couple things I use IFTTT for.

I have had good success with calling a script. The simple IFTTT trigger when an alexa timer goes off, has been nice. Just useful if you set a kitchen timer and then happen to be away from the kitchen and get distracted/forget.

Just started thinking if I could just call the service directly, I could save some scripting, and some time, just passing the json for what I wanted to say for those kinds of things

Actually, I think this should work. Might be a nice way to add some TTS notifications to things that are not currently integrated into HA, without having to create scripts, automations, input_booleans, etc.

I’ve been doing exactly that for a few weeks now. When I have an incoming landline call on my Ooma, Ooma tells IFTTT and IFTTT sends a voice string directly to my Alex media player service with who is calling. Works fantastic with very little delay.

1 Like

I think this could be a really good feature request…