Countdown timer on dashboard

I’ve installed the Alexa Media Player add-on from HACS and I can display the timer, that I’ve set up with Alexa, in my HA dashboard. However, it shows the time the timer will stop, it’s not showing an actual countdown.

I figured I could do a calculation based on that time and the current time so I started messing around in the developer tools:

{% set my_test_json = {
  "current_time": (as_timestamp(now()) | float),
  "timer": (as_timestamp("2020-10-28 16:44:42.721871+01:00") | float)
} %}

The current time is {{ my_test_json.current_time | timestamp_custom("%H:%M:%S") }}.
The timer is set at {{ my_test_json.timer | timestamp_custom("%H:%M:%S") }}.
Timer will end in {{ (my_test_json.timer -  my_test_json.current_time) | timestamp_custom("%H:%M:%S") }}.

(The hardcoded “timer” value above is just for testing, it will be replaced with the actual Alexa timer)
This indeed outputs:

The current time is 16:42:20.
The timer is set at 16:44:42.
Timer will end in 01:02:22.

However, two problems:

  • As you can see, the timer is off by 1 hour even though both times show the correct one (both timestamps have the +01:00 timezone). What could be the cause of this?
  • How do I display this timer as a “countdown” on my dashboard? I added it as a sensor to my configuration.yaml but I just get a static value and it’s not counting down. (I’m pretty new to HA)
sensor:
  - platform: template
    sensors:
      timer_display:
        friendly_name: "Alexa Timer"
        value_template: >
          {% set my_test_json = {
            "current_time": (as_timestamp(now()) | float),
            "timer": (as_timestamp("2020-10-28 16:44:42.721871+01:00") | float)
          } %} 
          {{ (my_test_json.timer -  my_test_json.current_time) | timestamp_custom("%H:%M:%S") }}

Many thanks.

– EDIT –

I’ve tried to create a timer (https://www.home-assistant.io/integrations/timer/) but even if I create a simple timer and add it to an entity card on my dashboard, it shows “active”. I can select the “remaining” attribute to show the remaining time but it doesn’t update, it’s static. I have to actually press the card and there I can see the actual remaining time, live.

What happens if you add the second argument to timestamp_custom to true?

That indeed fixed the issue, thanks! Any idea on displaying the timer?

You can set it to an input text with an automation and have that displayed on Lovelace.
But I’m not sure if it will update live or if you need to refresh to update the time.

I believe there is a topic regarding this if you search for it.
I haven’t bothered reading it though since I have no use of it (yet)

I just updated HA Core to 0.117.0 and automagically it started working for some reason! The only strange this is that the countdown timer only works when I use the entities (plural) card, and it doesn’t work in the entity (single) card.