Hi @rlkoshak
ive been struggling with this one for a few days, perhaps you can give me some guidance. Im trying to use Alexa alerts when home (presense = ON) and broadcasts when I’m away.
I have this, but it just fails to send the commands to the amazon echo group, so I can only assume ive got something wrong. Initially I thought it was the ‘!’ so i removed that but the issue remains - it wont send any alerts to the echos
Any suggestions?
rule "Keep track of the last time a door was opened or closed"
when
Member of gDoorSensors changed
then
if(previousState == NULL) return;
val name = triggeringItem.name
val state = triggeringItem.state
// Update the time stamp
postUpdate(name+"_LastUpdate", now.toString)
// Set the timer if the door is open, cancel if it is closed
if(state == OPEN) sendCommand(name+"_Timer", "ON")
else postUpdate(name+"_Timer", "OFF")
// Set the message
val msg = new StringBuilder
msg.append(transform("MAP", "en.map", name) + " was ")
msg.append(if(state == OPEN) "opened" else "closed")
var alert = false
if(vTimeOfDay.state.toString == "NIGHT" || vTimeOfDay.state.toString == "BED" || vTimeOfDay.state.toString == "EVENING") {
msg.append(" and it is Night")
alert = true
}
if(gPresenceSensors.state == OFF) {
msg.append(" and no one is Home")
alert = true
}
// Alert if necessary
if(alert && gPresenceSensors.state == ON) {
gAllEchoAlerts.sendCommand(msg.toString)
}
// Alert if necessary
if(alert && gPresenceSensors.state == OFF) {
sendBroadcastNotification(msg.toString)
}
// Log the message if we didn't alert
else {
logInfo("Door Sensor", msg.toString)
}
end
Thanks!