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

[question] Multiple timers from Alexa? #49

Open
njsaunders opened this issue Jul 1, 2022 · 10 comments
Open

[question] Multiple timers from Alexa? #49

njsaunders opened this issue Jul 1, 2022 · 10 comments

Comments

@njsaunders
Copy link

Hi!

Firstly - Thank you for this card - It's excellent! I've added my Echo show as a timer, and it displays the last timer I've set perfectly.

My question is what's the recommended way of showing all timers set on a specified Echo device? I have a show in the kitchen and set multiple timers when cooking - It would be great to show all of them automatically.

Thanks in advance,

Neil

@rianadon
Copy link
Owner

rianadon commented Jul 9, 2022

Hello! I'm not familiar with how the echo timers are created, but might something like the auto-entities card work for selecting all the timers?

See #19 (comment) for an example of using the timer bar card with auto-entities.

@njsaunders
Copy link
Author

I don't think so - The next_timer sensor contains the data in a "sorted_active" list

recurrence: Never Repeat
process_timestamp: '2022-07-13T12:16:45.859951+01:00'
prior_value: '2022-07-13T12:21:35+01:00'
total_active: 2
total_all: 2
sorted_active: >-
  [["XXX", {"alarmLabel": null, "alarmTime": 0,
  "assigner": null, "automationId": null, "createdDate": 1657710995487,
  "deferredAtTime": null, "deliveryType": null, "deviceName": null,
  "deviceSerialNumber": "XXX", "deviceType": "XXX",
  "extensibleAttribute": null, "followUpMetadata": null,
  "geoLocationTriggerData": null, "id":
  "XXX",
  "lastOccurrenceTimeInMilli": 0, "lastTriggerTimeInUtc": null,
  "lastUpdatedDate": 0, "loopCount": null, "mrmGroupContext": null,
  "musicAlarmId": null, "musicEntity": null, "notificationIndex":
  "XXX", "originalDate": null,
  "originalDurationInMillis": 300000, "originalTime": null, "personProfile":
  null, "primaryDeviceState": null, "provider": null, "rRuleData": null,
  "recurrenceEligibility": false, "recurringPattern": null, "remainingTime":
  289000.0, "reminderAppLabel": null, "reminderLabel": null, "reminderSubLabel":
  null, "showDeregisteredWarning": null, "skillInfo": null,
  "sleepTrackingAlarmProperties": null, "snoozedToTime": null, "sound":
  {"displayName": "Simple Timer", "folder": null, "id":
  "system_alerts_melodic_02", "isChildDirected": false, "numAssets": 0,
  "pricing": null, "providerId": "ECHO", "sampleUrl":
  "https://s3.amazonaws.com/deeappservice.prod.notificationtones/system_alerts_melodic_02.mp3",
  "sampleVideoUrl": null, "skillUrl": null}, "status": "ON",
  "targetPersonProfiles": null, "timeZoneId": null, "timerLabel": null,
  "tmwNotificationProperties": null, "triggerTime": 1657711295477, "type":
  "Timer", "version": "3"}], ["6a7a76aa-3f7f-3d67-8a27-2300109335b1",
  {"alarmLabel": null, "alarmTime": 0, "assigner": null, "automationId": null,
  "createdDate": 1657711004536, "deferredAtTime": null, "deliveryType": null,
  "deviceName": null, "deviceSerialNumber": "G0B1GB0410850037", "deviceType":
  "AIPK7MM90V7TB", "extensibleAttribute": null, "followUpMetadata": null,
  "geoLocationTriggerData": null, "id":
  "XXX",
  "lastOccurrenceTimeInMilli": 0, "lastTriggerTimeInUtc": null,
  "lastUpdatedDate": 0, "loopCount": null, "mrmGroupContext": null,
  "musicAlarmId": null, "musicEntity": null, "notificationIndex":
  "XXX", "originalDate": null,
  "originalDurationInMillis": 600000, "originalTime": null, "personProfile":
  null, "primaryDeviceState": null, "provider": null, "rRuleData": null,
  "recurrenceEligibility": false, "recurringPattern": null, "remainingTime":
  598000.0, "reminderAppLabel": null, "reminderLabel": null, "reminderSubLabel":
  null, "showDeregisteredWarning": null, "skillInfo": null,
  "sleepTrackingAlarmProperties": null, "snoozedToTime": null, "sound":
  {"displayName": "Simple Timer", "folder": null, "id":
  "system_alerts_melodic_02", "isChildDirected": false, "numAssets": 0,
  "pricing": null, "providerId": "ECHO", "sampleUrl":
  "https://s3.amazonaws.com/deeappservice.prod.notificationtones/system_alerts_melodic_02.mp3",
  "sampleVideoUrl": null, "skillUrl": null}, "status": "ON",
  "targetPersonProfiles": null, "timeZoneId": null, "timerLabel": null,
  "tmwNotificationProperties": null, "triggerTime": 1657711604523, "type":
  "Timer", "version": "3"}]]

@7ooL
Copy link

7ooL commented Dec 18, 2023

I'm also trying to figure this out. Its easy enough to get a list of each timer from the sorted active data

{% for timer in state_attr('sensor.kitchen_echo_next_timer','sorted_active') | from_json %}
  {% set milliseconds = timer[1].remainingTime %}
  {% set seconds = (milliseconds / 1000) | int %}
  {% set minutes = (seconds / 60) | int %}
  {% set hours = (minutes / 60) | int %}
  {% set seconds_remainder = seconds % 60 %}
  {% set minutes_remainder = minutes % 60 %}

  Timer ID: {{ timer[0] }}
  Timer Label: {{ timer[1].timerLabel }}
  Remaining Time: {{ hours }}h {{ minutes_remainder }}m {{ seconds_remainder }}s
  Status: {{ timer[1].status }}
{% endfor %}

Now using the timer card, I can get it to render the next timer, but not all active ones. My other question is how to pull the timerLabel and use that is the name.

type: custom:timer-bar-card
entities:
  - sensor.kitchen_echo_next_timer
name: 
  attribute: timerLabel
bar_foreground: '#eee'
bar_direction: rtl
bar_background: 'var(--mdc-theme-primary, #6200ee)'
start_time:
  attribute: process_timestamp
end_time:
  attribute: prior_value
bar_width: 35%
layout: full_row  # hides the name and icon, but not time remaining
#text_width: 0px # hide the time remaining
guess_mode: true
filter: false
debug: true

@rianadon
Copy link
Owner

This is the first use case I've seen for making the name configurable. You could create a template entity through Home Assistant that has the name set to the timerLabel attribute. Alternatively, this should be possible with the config-template-card card wrapping the timer bar card:

type: custom:config-template-card
variables:
  TIMER: "JSON.parse(states['sensor.kitchen_echo_next_timer'].attributes.sorted_active)[0]"
entities:
  - sensor.kitchen_echo_next_timer
card:
  type: custom:timer-bar-card
  entities:
    - sensor.kitchen_echo_next_timer
  name: "${TIMER[1].timerLabel}"
  bar_foreground: '#eee'
  bar_direction: rtl
  bar_background: 'var(--mdc-theme-primary, #6200ee)'
  start_time:
    attribute: process_timestamp
  end_time:
    attribute: prior_value
  bar_width: 35%
  layout: full_row  # hides the name and icon, but not time remaining
  #text_width: 0px # hide the time remaining
  guess_mode: true
  filter: false
  debug: true

You might even be able to use the template card to render all the timers. Here's my attempt at setting that up. I haven't tested it, so it may need some debugging to make it work.

type: custom:config-template-card
variables:
  cards: |
    () => {
      const timers = JSON.parse(states['sensor.kitchen_echo_next_timer'].attributes.sorted_active)
      return timers.map(timer => {
        return {
          "type": "custom:timer-bar-card"
          "entities": ["sensor.kitchen_echo_next_timer"],
          "name": timer[1].timerLabel,
          "bar_foreground": "#eee",
          "bar_direction": "rtl",
          "bar_background": "var(--mdc-theme-primary, #6200ee)",
          "duration": {
            "fixed": timer[1].originalDurationInMillis/1000,
            "units": "seconds",
          },
          "remain_time": {
            "fixed": timer[1].remainingTime/1000,
            "units": "seconds"
          },
          "bar_width": "35%",
          "layout": "full_row",
          "guess_mode": true,
          "filter": false,
          "debug": true
        }
      })
    }
entities:
  - sensor.kitchen_echo_next_timer
card:
  type: entities
  entities: "${cards()}"

@7ooL
Copy link

7ooL commented Dec 19, 2023

while name: "${TIMER[1].timerLabel}" works it, is putting it in the Title of the Card and not replacing the the entity name.

image

This example is using the auto-entities to list timers on Mutiple echo devices.
image
however, as you see It's not the timers name but the entity's name.

Neither of these two examples show that there are multiple timers on a single entity.

Using the untested code to use the template card to render all the timers isn';t working. I'm not sure how I can debug it to see where its breaking down. No errors in the card configuration appear and no cards are rendering. Any thoughts on how i can trace the code to see what's not working?

@rianadon
Copy link
Owner

Right I forgot the name property assigns the title of the card. Instead follow these directions to rename the timer so the name property goes under the entities.

I'll have to look into the second block of code I wrote some more. There might be an error in the browser console, or I could be wrong that it's possible to pass an entire config in this template card. You could try editing the cards function to return something static instead of parsing the timers and dynamically configuring them.

@7ooL
Copy link

7ooL commented Dec 19, 2023

Thanks, I got the name working right now, I didn't notice the indentation issue before either.

type: custom:config-template-card
variables:
  TIMER: >-
    JSON.parse(states['sensor.kitchen_echo_next_timer'].attributes.sorted_active)[0]
entities:
  - sensor.kitchen_echo_next_timer
card:
  type: custom:timer-bar-card
  entities:
    - entity: sensor.kitchen_echo_next_timer
      name: ${TIMER[1].timerLabel}
  bar_foreground: '#eee'
  bar_direction: rtl
  bar_background: 'var(--mdc-theme-primary, #6200ee)'
  start_time:
    attribute: process_timestamp
  end_time:
    attribute: prior_value
  bar_width: 35%
  guess_mode: true
  filter: false
  debug: false

Thanks for the debug guidance, looking in the browser console I found a missing ',' after "type": "custom:timer-bar-card". and that it needs to be entity not entities.

These are coming from a single entity:
image

type: custom:config-template-card
variables:
  cards: |
    () => {
      const timers = JSON.parse(states['sensor.kitchen_echo_next_timer'].attributes.sorted_active)
      return timers.map(timer => {
        return {
          "type": "custom:timer-bar-card",
          "entity": "sensor.kitchen_echo_next_timer",
          "name": timer[1].timerLabel,
          "bar_foreground": "#eee",
          "bar_direction": "rtl",
          "bar_background": "var(--mdc-theme-primary, #6200ee)",

          "duration": {
            "fixed": timer[1].originalDurationInMillis/1000,
            "units": "seconds",
          },
          "remain_time": {
            "fixed": timer[1].remainingTime/1000,
            "units": "seconds"
          },
          "bar_width": "35%",
          "guess_mode": true,
          "filter": false,
          "debug": false
        }
      })
    }
entities:
  - sensor.kitchen_echo_next_timer
card:
  type: entities
  entities: ${cards()}

however, the bar is not working, and I will still try to wrap this is an auto-entities to list all echo devices and multiple timers on each.

@rianadon
Copy link
Owner

Almost there! Nice work fixing some of the issues through the browser console.

I would have expected the bar to show with this configuration. If you send the output with debug turned on maybe I can spot the issue. I also saw there's a triggerTime in the configuration that looks like an end time, so you could replace the remain_time configuration with:

"end_time": {
  "fixed": timer[1].triggerTime
}

That will be a little more accurate than using the remaining time.

@7ooL
Copy link

7ooL commented Dec 20, 2023

With the debug, mode is idle

State: 2023-12-20T19:14:15+00:00 (state mode = idle)
Mode: idle (auto mode = N/A, used)
Duration: 21600 second
Time remaining: 21582
Counter: 21582

I made the change to end time. There is still no bar when extracting multiple timers from a single entity. With debug turned on, it appears that time remaining, and counter are NaN, and the mode is Idle

State: 2023-12-20T19:14:15+00:00 (state mode = idle)
Mode: idle (auto mode = N/A, used)
Duration: 21600 second
Time remaining: NaN
Counter: NaN
Attr: {"recurrence":"Never Repeat","process_timestamp":"2023-12-20T08:14:33.595961-05:00","prior_value":"2023-12-20T14:14:16-05:00","total_active":2,"total_all":2,"sorted_active":"[[\"b0171dde-8b8c-3a74-bc4d-5dcac65a11c3\", {\"alarmLabel\": null, \"alarmTime\": 0, \"assigner\": null, \"automationId\": null, \"createdDate\": 1703078056480, \"deferredAtTime\": null, \"deliveryMetadata\": null, \"deliveryType\": null, \"deviceName\": null, \"deviceSerialNumber\": \"G090VC098453149F\", \"deviceType\": \"A32DOYMUN6DTXA\", \"extensibleAttribute\": null, \"followUpMetadata\": null, \"geoLocationTriggerData\": null, \"id\": \"A32DOYMUN6DTXA-G090VC098453149F-b0171dde-8b8c-3a74-bc4d-5dcac65a11c3\", \"lastOccurrenceTimeInMilli\": 0, \"lastTriggerTimeInUtc\": null, \"lastUpdatedDate\": 1703078056949, \"loopCount\": null, \"mrmGroupContext\": null, \"musicAlarmId\": null, \"musicEntity\": null, \"notificationIndex\": \"b0171dde-8b8c-3a74-bc4d-5dcac65a11c3\", \"originalDate\": null, \"originalDurationInMillis\": 21600000, \"originalTime\": null, \"personProfile\": null, \"primaryDeviceState\": null, \"provider\": null, \"rRuleData\": null, \"recurrenceEligibility\": false, \"recurringPattern\": null, \"remainingTime\": 21582000.0, \"reminderAppLabel\": null, \"reminderLabel\": null, \"reminderSubLabel\": null, \"showDeregisteredWarning\": null, \"skillInfo\": null, \"sleepTrackingAlarmProperties\": null, \"snoozedToTime\": null, \"sound\": {\"displayName\": \"Simple Timer\", \"folder\": null, \"id\": \"system_alerts_melodic_02\", \"isChildDirected\": false, \"numAssets\": 0, \"pricing\": null, \"providerId\": \"ECHO\", \"sampleUrl\": \"https://s3.amazonaws.com/deeappservice.prod.notificationtones/system_alerts_melodic_02.mp3\", \"sampleVideoUrl\": null, \"skillUrl\": null}, \"status\": \"ON\", \"targetPersonProfiles\": null, \"timeZoneId\": null, \"timerLabel\": \"Bambi\", \"tmwNotificationProperties\": null, \"triggerTime\": 1703099656466, \"type\": \"Timer\", \"version\": \"3\"}], [\"c3ffb311-ae1a-36b3-80d3-bdf86024c323\", {\"alarmLabel\": null, \"alarmTime\": 0, \"assigner\": null, \"automationId\": null, \"createdDate\": 1703078068843, \"deferredAtTime\": null, \"deliveryMetadata\": null, \"deliveryType\": null, \"deviceName\": null, \"deviceSerialNumber\": \"G090VC098453149F\", \"deviceType\": \"A32DOYMUN6DTXA\", \"extensibleAttribute\": null, \"followUpMetadata\": null, \"geoLocationTriggerData\": null, \"id\": \"A32DOYMUN6DTXA-G090VC098453149F-c3ffb311-ae1a-36b3-80d3-bdf86024c323\", \"lastOccurrenceTimeInMilli\": 0, \"lastTriggerTimeInUtc\": null, \"lastUpdatedDate\": 1703078069270, \"loopCount\": null, \"mrmGroupContext\": null, \"musicAlarmId\": null, \"musicEntity\": null, \"notificationIndex\": \"c3ffb311-ae1a-36b3-80d3-bdf86024c323\", \"originalDate\": null, \"originalDurationInMillis\": 43200000, \"originalTime\": null, \"personProfile\": null, \"primaryDeviceState\": null, \"provider\": null, \"rRuleData\": null, \"recurrenceEligibility\": false, \"recurringPattern\": null, \"remainingTime\": 43195000.0, \"reminderAppLabel\": null, \"reminderLabel\": null, \"reminderSubLabel\": null, \"showDeregisteredWarning\": null, \"skillInfo\": null, \"sleepTrackingAlarmProperties\": null, \"snoozedToTime\": null, \"sound\": {\"displayName\": \"Simple Timer\", \"folder\": null, \"id\": \"system_alerts_melodic_02\", \"isChildDirected\": false, \"numAssets\": 0, \"pricing\": null, \"providerId\": \"ECHO\", \"sampleUrl\": \"https://s3.amazonaws.com/deeappservice.prod.notificationtones/system_alerts_melodic_02.mp3\", \"sampleVideoUrl\": null, \"skillUrl\": null}, \"status\": \"ON\", \"targetPersonProfiles\": null, \"timeZoneId\": null, \"timerLabel\": \"Thumper\", \"tmwNotificationProperties\": null, \"triggerTime\": 1703121268830, \"type\": \"Timer\", \"version\": \"3\"}]]","sorted_all":"[[\"b0171dde-8b8c-3a74-bc4d-5dcac65a11c3\", {\"alarmLabel\": null, \"alarmTime\": 0, \"assigner\": null, \"automationId\": null, \"createdDate\": 1703078056480, \"deferredAtTime\": null, \"deliveryMetadata\": null, \"deliveryType\": null, \"deviceName\": null, \"deviceSerialNumber\": \"G090VC098453149F\", \"deviceType\": \"A32DOYMUN6DTXA\", \"extensibleAttribute\": null, \"followUpMetadata\": null, \"geoLocationTriggerData\": null, \"id\": \"A32DOYMUN6DTXA-G090VC098453149F-b0171dde-8b8c-3a74-bc4d-5dcac65a11c3\", \"lastOccurrenceTimeInMilli\": 0, \"lastTriggerTimeInUtc\": null, \"lastUpdatedDate\": 1703078056949, \"loopCount\": null, \"mrmGroupContext\": null, \"musicAlarmId\": null, \"musicEntity\": null, \"notificationIndex\": \"b0171dde-8b8c-3a74-bc4d-5dcac65a11c3\", \"originalDate\": null, \"originalDurationInMillis\": 21600000, \"originalTime\": null, \"personProfile\": null, \"primaryDeviceState\": null, \"provider\": null, \"rRuleData\": null, \"recurrenceEligibility\": false, \"recurringPattern\": null, \"remainingTime\": 21582000.0, \"reminderAppLabel\": null, \"reminderLabel\": null, \"reminderSubLabel\": null, \"showDeregisteredWarning\": null, \"skillInfo\": null, \"sleepTrackingAlarmProperties\": null, \"snoozedToTime\": null, \"sound\": {\"displayName\": \"Simple Timer\", \"folder\": null, \"id\": \"system_alerts_melodic_02\", \"isChildDirected\": false, \"numAssets\": 0, \"pricing\": null, \"providerId\": \"ECHO\", \"sampleUrl\": \"https://s3.amazonaws.com/deeappservice.prod.notificationtones/system_alerts_melodic_02.mp3\", \"sampleVideoUrl\": null, \"skillUrl\": null}, \"status\": \"ON\", \"targetPersonProfiles\": null, \"timeZoneId\": null, \"timerLabel\": \"Bambi\", \"tmwNotificationProperties\": null, \"triggerTime\": 1703099656466, \"type\": \"Timer\", \"version\": \"3\"}], [\"c3ffb311-ae1a-36b3-80d3-bdf86024c323\", {\"alarmLabel\": null, \"alarmTime\": 0, \"assigner\": null, \"automationId\": null, \"createdDate\": 1703078068843, \"deferredAtTime\": null, \"deliveryMetadata\": null, \"deliveryType\": null, \"deviceName\": null, \"deviceSerialNumber\": \"G090VC098453149F\", \"deviceType\": \"A32DOYMUN6DTXA\", \"extensibleAttribute\": null, \"followUpMetadata\": null, \"geoLocationTriggerData\": null, \"id\": \"A32DOYMUN6DTXA-G090VC098453149F-c3ffb311-ae1a-36b3-80d3-bdf86024c323\", \"lastOccurrenceTimeInMilli\": 0, \"lastTriggerTimeInUtc\": null, \"lastUpdatedDate\": 1703078069270, \"loopCount\": null, \"mrmGroupContext\": null, \"musicAlarmId\": null, \"musicEntity\": null, \"notificationIndex\": \"c3ffb311-ae1a-36b3-80d3-bdf86024c323\", \"originalDate\": null, \"originalDurationInMillis\": 43200000, \"originalTime\": null, \"personProfile\": null, \"primaryDeviceState\": null, \"provider\": null, \"rRuleData\": null, \"recurrenceEligibility\": false, \"recurringPattern\": null, \"remainingTime\": 43195000.0, \"reminderAppLabel\": null, \"reminderLabel\": null, \"reminderSubLabel\": null, \"showDeregisteredWarning\": null, \"skillInfo\": null, \"sleepTrackingAlarmProperties\": null, \"snoozedToTime\": null, \"sound\": {\"displayName\": \"Simple Timer\", \"folder\": null, \"id\": \"system_alerts_melodic_02\", \"isChildDirected\": false, \"numAssets\": 0, \"pricing\": null, \"providerId\": \"ECHO\", \"sampleUrl\": \"https://s3.amazonaws.com/deeappservice.prod.notificationtones/system_alerts_melodic_02.mp3\", \"sampleVideoUrl\": null, \"skillUrl\": null}, \"status\": \"ON\", \"targetPersonProfiles\": null, \"timeZoneId\": null, \"timerLabel\": \"Thumper\", \"tmwNotificationProperties\": null, \"triggerTime\": 1703121268830, \"type\": \"Timer\", \"version\": \"3\"}]]","status":"ON","dismissed":"2023-12-19T17:13:22.200708-05:00","device_class":"timestamp","icon":"mdi:timer-outline","friendly_name":"Kitchen Echo next Timer"}

My attempts to change the mode have not worked. I appreciate you working and talking me through this.

@rianadon
Copy link
Owner

Taking a look through the code, there's a subtle bug with using guess_mode together with remain_time. I'll have to think about how I fix that.

As for the NaN values, I realized the code expects the time to be in string-format instead of using the timestamps that are given, so try this instead:

"end_time": {
  "fixed": new Date(timer[1].triggerTime).toISOString()
}

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

No branches or pull requests

3 participants