HI,
for my speech engine I am trying to use my weekday and weekend alarm sensors to create a subsidiary sensor for the time to next alarm.
All goes well when either on weekdays, or weekends. But how to calculate that from friday (being a workday) to alarm on saturday (non workday with other alarmtime)…
these are my current sensors:
sensor:
- platform: template
sensors:
alarmclock_wd_time:
friendly_name: 'Time wD'
value_template: >
{{ '%0.02d:%0.02d' | format(states('input_number.alarmclock_wd_hour') | int,
states('input_number.alarmclock_wd_minute') | int) }}
alarmclock_we_time:
friendly_name: 'Time wE'
value_template: >
{{ '%0.02d:%0.02d' | format(states('input_number.alarmclock_we_hour') | int,
states('input_number.alarmclock_we_minute') | int) }}
next_alarm_wd:
friendly_name: Seconds untill next wD alarm
value_template: >
{% set relative_time = (states('input_number.alarmclock_wd_hour')|float|multiply(60) +
states('input_number.alarmclock_wd_minute')|float) -
(now().hour|float|multiply(60) + now().minute) %}
{% if relative_time < 0 %} {{23*60 + relative_time}}
{% else %} {{ relative_time - 60}}
{%- endif %}
next_alarm_ww:
friendly_name: Seconds untill next wE alarm
value_template: >
{% set relative_time = (states('input_number.alarmclock_wd_hour')|float|multiply(60) +
states('input_number.alarmclock_wd_minute')|float) -
(now().hour|float|multiply(60) + now().minute) %}
{% if relative_time < 0 %} {{23*60 + relative_time}}
{% else %} {{ relative_time - 60}}
{%- endif %}
time_until_next_alarm:
friendly_name: Time untill next alarm
value_template: >
{% if is_state('binary_sensor.workday_sensor', 'on') %}
{{ (states('sensor.next_alarm_wd').split(':')[0] | int * 60 ) | timestamp_custom('%H:%M') }}
{% else %}
{{ (states('sensor.next_alarm_we').split(':')[0] | int * 60 ) | timestamp_custom('%H:%M') }}
{% endif %}
thanks for having a look.