Calculate sleep time

I would like to use these two sensors to show the mean time in one sensor, how long until the alarm (sleep time)

How can I best do that?
Can someone help me?

Do you mean you want another sensor to show the amount of time between the current time and the next alarm time? If so, then maybe try this:

sensor:
- platform: template
  sensors:
    time_to_wakeup:
      value_template: >
        {% set t = states('sensor.time').split(':') %}
        {% set t = t[0]|int*60 + t[1]|int %}
        {% set a = states('sensor.wakeup_alarm_time').split(':') %}
        {% set a = a[0]|int*60 + a[1]|int %}
        {% if a < t %}
          {% set a = a + 24*60 %}
        {% endif %}
        {{ ((a - t)*60)|timestamp_custom('%H:%M', false) }}
1 Like

what can I say you are great! Thank you very much and a happy new year!

1 Like