Here’s one to get you started.
When my gate is opened, it sends an ‘alert’ followed by a voice message, to 3 different Alexas in the house. Note the inclusion of the openhab rules tools, which you will need.
I have a few extra bits in there to stop the notifications if the alarm is set (and therefore in theory, no one at home to hear it!!)
Hope this helps.
var {TimerMgr} = require('openhab_rules_tools');
var timers = cache.shared.get('alexa_tm', () => TimerMgr());
var tmexpire = function(iname,speakVolume,speakText) {
return () => {
//console.info(`Night Control: Enable Timer "${iname}" Now turning off ${pwritem}`);
//Stop Alarm Sound
items[iname+"_AlarmSound"].sendCommand('');
//Announce Entry
//Set TTS Volumes on Echo units
items[iname+"_SpeakVolume"].sendCommand(speakVolume);
//Send TTS message to echo units
items[iname+"_Speak"].sendCommand(speakText);
};
}
var gateNotifyAlexa = function(alexaItemName,alexaAlarmSound,alexaNotificationVolume,alexaAlarmDuration,alexaSpeakVolume,alexaNotificationMessage)
{
// Set Alert Volume and Start Alarm Sound
items[alexaItemName+"_NotificationVolume"].sendCommand(alexaNotificationVolume);
items[alexaItemName+"_AlarmSound"].sendCommand(alexaAlarmSound);
//Set a timer to stop the alarm sound, and play message
schedtime = time.ZonedDateTime.now().plusSeconds(alexaAlarmDuration);
timers.check(alexaItemName+"_notify",schedtime.toString(),tmexpire(alexaItemName,alexaSpeakVolume,alexaNotificationMessage),true,null,'alexa_tm_'+alexaItemName+"_notify");
}
//Notify all Alexa Echo's in house, if the Alarm is not set, and the Disable flag is not set
if((items["ZelioAlarmArmed"].state === "OFF")&&(items["DisableNotification_Echo"].state === "OFF"))
{
gateNotifyAlexa("EchoDotBedroom1","ECHO:system_alerts_soothing_01",25,12,25,"Gate Opened");
gateNotifyAlexa("EchoDotLivingRoom","ECHO:system_alerts_soothing_01",35,12,35,"Gate Opened");
gateNotifyAlexa("EchoDotLounge","ECHO:system_alerts_soothing_01",35,12,35,"Gate Opened");
}