Time sensor (Android phone alarm clock from the app) formatted output

I want to output a sensor (sensor.toni_handy_next_alarm) as a pure time and a second entity that outputs the date to it.
The sensor looks like this:

So the alarm is set to 18:11 and also only that I want to display. The following code in template.yaml does not work:

-   sensor:
      time_formatted:
        friendly_name: Toni's Wecker
        value_template: "{{ states('sensor.toni_handy_next_alarm') | timestamp_custom('%I:%M') }}"
        icon_template: mdi:calendar-clock

In addition, I would like to create an entity from the millisecond count that also shows in mm:hh format how much time is left until the next alarm clock

I hope someone can help create the three sensors.
Thank you and best regards

Basti

1 Like

Do yourself a favor, and use Petros excellent macros for all time related:

Really, it isn’t worth the hassle, if you can do that easy (my opinion). :slight_smile: :+1:

2 Likes
template:
  - sensor:
      - name: Toni's Wecker
        state: |
          {% if states('sensor.toni_handy_next_alarm') not in ['unavailable', 'None'] %}
          {{ (states('sensor.toni_handy_next_alarm')|as_datetime|as_local).strftime('%H:%M') }}
          {% else %} No Next Alarm{% endif %}
        icon: mdi:calendar-clock
      - name: Next Alarm Date
        state: |
          {% if states('sensor.toni_handy_next_alarm') not in ['unavailable', 'None'] %}
          {{ (states('sensor.toni_handy_next_alarm')|as_datetime|as_local).strftime('%m-%d') }}
          {% else %} No Next Alarm{% endif %}
        icon: mdi:calendar-clock
2 Likes

in which file is this located? template.yaml?

It should go in configuration.yaml or any file in which you have included the template integration… If you already have a template.yaml file then, yes, it can likely go there.

works great! Is it possible to display the weekdays/months in German?

You should take @paddy0174 's advice and set up the Easy Time Macros, since it has translations built-in.

Other options include:

1 Like