Multi-stage alarm clock with Mushroom cards

I think I finally solved my one-button alarm idea! For the alarm automation you’ll need the standard date/time helper (set to just time) and a toggle - I wanted to create a card that pulled both of those functions into a single card. Tap on the card to turn on/off, long press to adjust time.

On
image
Off
image

Here’s the code for the template for the card - note I used the mushroom template card, but you can use a standard Lovelace card for this if you’re not into the mushroom card look.

type: custom:mushroom-template-card
entity: input_datetime.YOURALARMTIME
primary: >-
  {{ state_attr('input_datetime.YOURALARMTIME', 'timestamp')|timestamp_custom('%-H:%M', false) }}
secondary: ''
icon: mdi:alarm
icon_color: |-
  {% if is_state('input_boolean.YOURALARMTOGGLE', 'on') %}
  green
  {% else %}
  grey
  {%endif%}
tap_action:
  action: call-service
  service: input_boolean.toggle
  target:
    entity_id: input_boolean.YOURALARMTOGGLE
  data: {}
hold_action:
  action: more-info
double_tap_action:
  action: none
3 Likes

Well stupid likely but brute force (better to make the hours, minutes into a time) …
Just a sample tested only with strings and not your entity. you may not need the |string if they are really strings

{%set min = state_attr('input_datetime.YOURALARMTIME', 'minute') %}
{%if min | string | length == 1 %}
0{{min | string}}
{% else %}
{{min | string }}
{% endif %}

Or as a one liner (you plug in your entity) …

{{ min | string if (min | string | length > 1) else "0" + (min | string) }}

And …

What I mean by one liner (immediate if) without testing, this should be it:

{{ (state_attr('input_datetime.YOURALARMTIME', 'minute') | string) if (state_attr('input_datetime.YOURALARMTIME', 'minute') | string | length > 1) else ("0" + (state_attr('input_datetime.YOURALARMTIME', 'minute') | string)) }}

I hadn’t thought of using an if statement that way to check the length of the minutes string. Well played. I will test this out tonight and update the original post if I can successfully make it work.

Did you try this:

primary: >-
  {{ state_attr('input_datetime.YOURALARMTIME', 'timestamp')|timestamp_custom('%-H:%M', false) }}

It took me some time to figure out that timestamp_custom has a flag to disable the conversion to local timezone, but then it worked for me.

1 Like

That is what I had said, it would be better to handle it as a timestamp. I would always go that route before doing the “brute force” hack I suggested.

This worked perfectly!! Updating the original post to include this formatting.