Creating a single alarm clock button with a template

My goal is to create a single alarm clock button that as a tap action, toggles a boolean helper and when held, calls up the more info for the time. I have the triggers working but I cannot for the life of me to get it to display the time with a template. I’m using the Mushroom template card but in theory I should be able to use the default entities card to get the same result.

Here’s the code for the card:

type: custom:mushroom-template-card
primary: ''
secondary: ''
icon: mdi:home
entity: input_datetime.jeffalarm
tap_action:
  action: call-service
  service: input_boolean.toggle
  target:
    entity_id: input_boolean.jeff_alarm_toggle
  data: {}
hold_action:
  action: more-info
layout: horizontal
icon_color: |-
  {% if is_state('input_boolean.jeff_alarm_toggle', 'on') %}
  green
  {% else %}
  orange
  {%endif%}

Here’s the code for the template that I want to put in the primary information spot
{{ state_attr('input_datetime.jeff_alarm', 'timestamp') | as_datetime }}

It should display a datetime of 6:30am but instead no matter what I plug into the developer templating test, it just shows null. I’m clearly missing something but I’ve been staring at that last piece for about an hour and just cannot seem to get it to work. Anybody with more experience with templates see what I’m missing?

Oh, so there’s some related topics to this that get close to what I want. Here’s a two button variation that’s a lot simpler (and one I’m willing to settle for if I can’t get this to work)

Here’s an alarm clock with a snooze button

Here’s a thread on using the input_datetime helper within a template to trigger an alarm 24h before within an automation (not as the primary attribute to pull the desired time as a readable input). This is the closest to what I had in mind.

I solved it - the code can be found here:
https://community.home-assistant.io/t/multi-stage-alarm-clock-with-mushroom-cards/

1 Like