How to use next alarm sensor

I make use of the alarm data in multiple automations and templates, so for me it made sense to create a template sensor that gives the minutes until the next alarm.

  - platform: template
    sensors:
      minutes_next_alarm:
        friendly_name: "Minutes until Next Alarm"
        unit_of_measurement: 'm'
        entity_id: sensor.time
        value_template: "{{((states('sensor.moto_g_5_plus_next_alarm')|as_timestamp|int - now()|as_timestamp|int)/60)|int}}"
        availability_template: "{{ not is_state('sensor.moto_g_5_plus_next_alarm','unavailable') }}"
        attribute_templates:
          time: "{{ state_attr('sensor.moto_g_5_plus_next_alarm','Local Time') }}"
19 Likes