I have been wanting for a long time now to have the ability to control all my various alarm clocks from HA, using a nice UI, and to make Alexa turn on the proper alarm every night when I go to bed.
To achieve that I have created a neat Node-Red integration (heavily based on node-red-contrib-ui-time-scheduler
):
Which provides a persistent alarm clock schedule with a simple but strong UI using node-red dashboard.
tip
If you want to show the node red dashboard in your supervised instance, use the following addon -
Here is the final result:
And the function to build the alexa TTS command to add the alarm:
const alarmsObj = msg.data.upcoming || {};
const alarms = Object.keys(alarmsObj).map((alarm) => {
return {
name: alarm,
epoch: alarmsObj[alarm]
};
});
alarms.sort((a, b) => {
return a.epoch - b.epoch;
});
const nextAlarm = alarms[0];
if (!nextAlarm) {
msg.ignoreAlarm = 'true';
return msg;
}
const timeUntilNextAlarm = nextAlarm.epoch - new Date().getTime();
if (timeUntilNextAlarm >= 24 * 60 * 60 * 1000) {
msg.ignoreAlarm = 'true';
return msg;
}
const nextAlarmDate = new Date(nextAlarm.epoch);
let hour = nextAlarmDate.getHours();
let partOfDay = 'AM';
if (hour > 12) {
partOfDay = 'PM';
hour = hour - 12;
}
let minutes = nextAlarmDate.getMinutes();
if (minutes < 10) {
minutes = `0${minutes}`;
}
msg.alarmRequest = `set alarm for ${hour}:${minutes} ${partOfDay}`;
return msg;
Any feedback is welcome