Enable/Disable Alexa Voice Control

I have been using an Echo outside for 3 years now, same Echo Dot v1, this entire time.

Here’s how I handle the different scenario’s:

  1. When leaving the house or at night, I set volumes to zero.
                    var EchoThing = getThingStatusInfo("amazonechocontrol:account:account1")
					if ((EchoThing !== null) && (EchoThing.getStatus().toString() == 'ONLINE')) {
					
						logInfo("ECHO","Alexa Outside Volume set to 0.") 
						createTimer(now().plusSeconds(5), [ | Echo_BackYard_Volume.sendCommand('0') ])
							Thread::sleep(2000)
						createTimer(now().plusSeconds(5), [ | Echo_BackYard_textToSpeechVolume.sendCommand('0') ])
							Thread::sleep(2000)	
						Echo_BackYard_doNotDisturb.sendCommand(ON)	
					}
  1. Amazon likes to change volumes sometimes (not sure when/why):
rule "Echo BackYard Volume Changed by Amazon"
	when
		Item Echo_BackYard_Volume changed
	then

		var EchoThingBackYard = getThingStatusInfo("amazonechocontrol:echo:account1:echobackyard")
		if ((systemStarted.state != ON && EchoThingBackYard !== null) && (Alexa_Status.state == 'ONLINE' && gInternet.state == ON && Echo_BackYard_Volume.state > 0 && Echo_BackYard_Volume.state <= 30)) {

			logInfo("ECHO","Setting Echo_BackYard_Volume to 0 since its set under 30.")
			logInfo("ECHO","Prior Echo_BackYard_Volume set to " + Echo_BackYard_Volume.state)
			createTimer(now().plusSeconds(5), [ | Echo_BackYard_Volume.sendCommand('0') ])
				Thread::sleep(2000)
			createTimer(now().plusSeconds(5), [ | Echo_BackYard_textToSpeechVolume.sendCommand('0') ])	
				Thread::sleep(2000)	
			createTimer(now().plusSeconds(5), [ | Echo_BackYard_doNotDisturb.sendCommand(ON) ])				
			logInfo("ECHO","After Echo_BackYard_Volume set to " + Echo_BackYard_Volume.state)
		} 
end
  1. When the Echo device is used, it sends an email and takes a picture of who is in the back yard. If the house alarm system is ON or it’s past X hours at night, then I call an Alexa routine that kills whatever is asked of it.

Echo_BackYard_StartRoutine.sendCommand(‘kill use backyard echo’)

rule "Echo BackYard Last Command Heard Audit"
	when
		Item Echo_BackYard_LastVoiceCommand changed
	then

		var EchoThingBackYard = getThingStatusInfo("amazonechocontrol:echo:account1:echobackyard")
		if ((systemStarted.state != ON && EchoThingBackYard !== null) && (Alexa_Status.state == 'ONLINE' && gInternet.state == ON)) {

			if (Echo_BackYard_LastVoiceCommand.state.toString() == 'amazon' && PatioDoor_Status.state != OPEN && gPart1Zone3Fault.state != ON && (currHour.state >= 22 || currHour.state <= 6)) {

				logInfo("ECHO","Prior Echo_BackYard_Volume set to " + Echo_BackYard_Volume.state)

				Echo_BackYard_StartRoutine.sendCommand('kill use backyard echo')
					Thread::sleep(1500)

				logInfo("ECHO","After Echo_BackYard_Volume set to " + Echo_BackYard_Volume.state)
				logInfo("ECHO","Echo_BackYard_StartRoutine --> kill use backyard echo <-- executed.")
				return;
			} 

			if (gInternet.state == ON && (Echo_BackYard_LastVoiceCommand.state.toString() == 'amazon' || Echo_BackYard_LastVoiceCommand.state === null || Echo_BackYard_LastVoiceCommand.state == NULL)) { return; }

			if (gInternet.state == ON && gPort25.state == ON && PatioDoor_Status.state != OPEN && gPart1Zone3Fault.state != ON) {
			
				logInfo("ECHO","Echo_BackYard_LastVoiceCommand heard was --> " + Echo_BackYard_LastVoiceCommand.state.toString())
				
				extract_date_time_formatted = now.format(java.time.format.DateTimeFormatter.ofPattern("MM_dd_yyyy_HH_mm"))
				val string PatioDoorCam = "PatioDoor"+ extract_date_time_formatted +".jpg"
				
				if (DVR.state == ON) {	
				
					executeCommandLine(Duration.ofSeconds(5), "wget", "-O", "/var/lib/openhab/pics/"+ PatioDoorCam,  "http://user:pass@192.168.0.11:81/ISAPI/Streaming/channels/501/picture" )
				}
				
				var MailBinding = getThingStatusInfo("mail:smtp:4228b22a33")
				if ((MailBinding !== null) && (MailBinding.getStatus().toString() == 'ONLINE' && gInternet.state == ON && gPort25.state == ON)) {	

					val	mailActions = getActions("mail","mail:smtp:4228b22a33")
					val String subjectemailEchoBackyard	= "openHAB3 - Echo Backyard Used"	
					val String bodyemailEchoBackyard 	= "Echo_BackYard_LastVoiceCommand heard was --> " + Echo_BackYard_LastVoiceCommand.state.toString() + "."
					val String attachment				= "/var/lib/openhab/pics/" + PatioDoorCam
					val String attachmentUrlListPushOver = attachment				
					val List<String> attachmentUrlList  = newArrayList("file://" + attachment)
					val String bodyemailEchoBackyardSMS = ''
					mailActions.sendMail(JaygMail, subjectemailEchoBackyard, bodyemailEchoBackyard, attachmentUrlList)
					logInfo("EMAIL",subjectemailEchoBackyard)			

					if (gInternet.state == ON) {

						var String PushOverMessage = "Echo Used"
						var String PushOverTitle   = "Echo Backyard"
						val pushOverActions 	   = getActions("pushover","pushover:pushover-account:account")
						pushOverActions.sendAttachmentMessage(PushOverMessage, PushOverTitle, attachmentUrlListPushOver, PushOverMIME)
						logInfo("PUSHOVER",PushOverMessage)	
					}
						
					if (gInternet.state == ON && gPort25.state == ON && UnifiPhones.state == OFF) {
					
						val	mailActions = getActions("mail","mail:smtp:4228b22a33")
						logInfo("ECHO","Echo BackYard was used by someone other than our family members.")		
						mailActions.sendMail(JaySMS, subjectemailEchoBackyard, bodyemailEchoBackyardSMS)
						logInfo("EMAIL",subjectemailEchoBackyard)
					}
				}	
			}
		}	
end

Best, Jay