Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Link to more instructions for Alexa #166

Merged
merged 3 commits into from
Sep 12, 2024
Merged

Link to more instructions for Alexa #166

merged 3 commits into from
Sep 12, 2024

Conversation

SLaks
Copy link
Contributor

@SLaks SLaks commented Sep 8, 2024

Use the following YAML, with lovelace-auto-entities, to render a card with a separate bar for every timer in every Alexa device in Alexa Media Player.

This renders identically to #140 (except without dismiss buttons, which Alexa does not support).

type: custom:auto-entities
filter:
  template: |
    {%- set results = namespace(timers = []) -%}
    {%- set state_map = {
      "ON": "active",
      "PAUSED": "paused",
    } -%}
    {%- set icon_map = {
      "ON": "mdi:timer",
      "ringing": "mdi:timer-alert",
      "PAUSED": "mdi:timer-pause",
    } -%}
    {%- for entity_id in integration_entities('alexa_media') if entity_id
          is contains 'next_timer' -%}
      {%- set multiple = not loop.first or not loop.last -%}
      {%- set suffix = '' if not multiple
                  else ' – ' + state_attr(entity_id, 'friendly_name')
                      | replace(' timers', '') -%}
            
      {%- for kvp in state_attr(entity_id, 'sorted_all') | from_json if kvp[1].status != "OFF" -%}
        {%- set t= kvp[1] -%}
        {%- set label  = t.timerLabel if t.timerLabel else 
            timedelta(milliseconds = t.originalDurationInMillis) | string | regex_replace('^0:0*', '') + ' timer' -%}   
        {%- set results.timers = results.timers + [{
          'icon': icon_map[t.status],
          'duration': {'fixed': t.originalDurationInMillis | int / 1000, 'units': 'seconds'},
          'end_time': {'fixed': (t.triggerTime | int / 1000) | timestamp_local },
          'name': label + suffix,
          'state': {'fixed': state_map[t.status] | default(t.status)},
        }] -%}
      {%- endfor -%}
    {%- endfor -%}
    {{ results.timers }}
card:
  type: custom:timer-bar-card
show_empty: false

@rianadon
Copy link
Owner

So cool you have this working!

@rianadon rianadon merged commit f7d61ab into rianadon:main Sep 12, 2024
1 of 2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants