how can I add the now() time to the time next alarm, to see if they are <24:00 meaning still this day?
I have
now().time().strftime('%H:%M')
states('sensor.time_until_next_alarm')
or
I have a related sensor:
now_master_bedroom_schedule_day:
friendly_name: 'Now Master bedroom schedule day'
entity_id: sensor.time
value_template: >
{{now().time().strftime('%H:%M') == states('sensor.master_bedroom_schedule_day')}}
which works just fine…
had a go with timestamps (setting it to the time_until_next_alarm) but it either shows nothing, or this outcome (see screenshots)
another way calculating this woud be to see if alarmtime< now ( in which case it would have to be next day…
seems to be simple but is it correct?
use that like:
next_alarm_today:
friendly_name: Next alarm today
value_template: >
{% set alarm = states('sensor.alarmclock_wd_time') if now().weekday() in range(4)
else states('sensor.alarmclock_we_time') %}
{% set now = now().time().strftime('%H:%M')%}
{% if alarm < now %} Tomorrow
{% elif alarm == 'Not set' %} Not set
{% else %} Today
{% endif %}
but I’d need it to use the time_until_next_alarm, to have it take all logic in to account of the weekdays and weekend days…
so, hopefully (need to see what will happen around the weekend) made it with another(…) sensor using the above:
next_alarm_day:
icon_template: >
{% if not is_state('sensor.next_alarm_day','Not set') %} mdi:calendar-clock
{% else %} mdi:alarm-off
{% endif %}
friendly_name: Next alarm day
value_template: >
{% set offset = states('sensor.next_alarm_offset')|int %}
{% if not is_state('sensor.next_alarm_offset','Not set') and
not is_state('sensor.next_alarm_today','Not set') %}
{% if is_state('sensor.next_alarm_today','Today')%}
{{states('sensor.next_alarm_today')}}, {{ as_timestamp(now().replace(day=now().day)) | timestamp_custom('%A')|lower }}
{% else %}
{{states('sensor.next_alarm_today')}}, {{ as_timestamp(now().replace(day=now().day + offset)) | timestamp_custom('%A')|lower }}
{% endif %}
{% elif not is_state('sensor.next_alarm_offset','Not set') %}
{{ as_timestamp(now().replace(day=now().day + offset)) | timestamp_custom('%A') }}
{% else %} Not set
{% endif %}
which give me the option to have TTS say the alarm to me as you suggested, via an extra intermediary sensor, which state is used as a variable in the speech script:
next_alarm_text:
friendly_name: Next alarm text
entity_id:
- sensor.time_until_next_alarm
- sensor.next_alarm_day
icon_template: >
{% if is_state('sensor.next_alarm_text','Alarm is not set, relax') %} mdi:alarm-off
{% else %} mdi:alarm
{% endif %}
value_template: >
{% set time = states('sensor.time_until_next_alarm_full') %}
{% set next_alarm = states('sensor.next_alarm_day')|lower %}
{% set pickup = 'Next alarm will be ' + next_alarm + ' in ' %}
{% if time == 'Not set, relax' %} Alarm is {{time|lower}}
{% elif (time.split(':')|length - 1) > 1 %}
{{pickup}}
{% set day = 'day' if time.split(':')[0]== '1' else 'days' %}
{% set hour = 'hour' if time.split(':')[1]== '1' else 'hours' %}
{% set minute = 'minute' if time.split(':')[2]== '1' else 'minutes' %}
{% if time.split(':')[1] == '0' %} {{time.split(':')[0] }} {{day}} {{time.split(':')[2] }} {{minute}}
{% elif time.split(':')[2] == '0' %} {{time.split(':')[0] }} {{day}} and {{time.split(':')[1] }} {{hour}} exactly
{% else %} {{time.split(':')[0] }} {{day}}, {{ time.split(':')[1] }} {{hour}} and {{time.split(':')[2] }} {{minute}}
{% endif%}
{% else %}
{{pickup}}
{% set hour = 'hour' if time.split(':')[0]== '1' else 'hours' %}
{% set minute = 'minute' if time.split(':')[1]== '1' else 'minutes' %}
{% if time.split(':')[0] == '0' %} {{time.split(':')[1] }} {{minute}}
{% elif time.split(':')[1] == '0' %} {{time.split(':')[0] }} {{hour}} exactly
{% else %} {{time.split(':')[0] }} {{hour}} and {{time.split(':')[1] }} {{minute}}
{% endif%}
{% endif %}