Alexa alarm

Is the only way to get alexa to do stuff with OH2 items when the alarm goes of to use IFTTT?

No, you don’t have to use IFTTT at all.

Take a look here on how to use the Alexa skill with myopenhab:

or take a look at the hue emulation service if you don’t want to use the skill and myopenhab:

http://docs.openhab.org/addons/io/hueemulation/readme.html

Yes, I use those, but as far as I know they can not trigger a switch in openhab when the Alexa alarm/timer goes off or did I miss something?

Okay, now I think I understand: you want to use the internal Alexa timer to trigger a switch in openHAB?
I have not tested that yet, but when I go to the setup of that IFTTT sketch I get:

so I assume this would only work with HUE lights. But I’m not sure …

Well it works fine, with IFTTT. I just wanted it to run without being dependent of IFTTT and was wondering if this was possible, but it looks like it isnt.

With generic openHAB items or just with HUE?

I am setting the openhab item vTimeOfDay to MORNING

1 Like

Here’s an Alexa alarm rule tied to HUE lights that has been modified for OH 3.

// Settting HUE lighting 20, 15 and 10 minutes away from the Guest Bedroom Echo Alarm going off
// https://community.openhab.org/t/released-openhab2-amazon-echo-control-binding-controlling-alexa-from-openhab2/37844/859

rule "Guest Bedroom Echo Alarm controlling HUE bed side table light"
	when
		Time cron "45 0/3 5-7 * * ?"		// 45 secs every 3 minutes between 5 - 7 am
	then
	
		if (systemStarted.state != ON && Home_Away.state == ON && gInternet.state == ON && OH_Uptime_HumanReadable.state != NULL && OH_Uptime_HumanReadable.state !== null && OH_Uptime_HumanReadable.state.toString() != 'UNDEF') {

			var EchoThing  = getThingStatusInfo("amazonechocontrol:account:account1")
			if ((systemStarted.state != ON && EchoThing !== null) && (EchoThing.getStatus().toString() == "ONLINE" )) {
				
				// read Alexa notifications - alarm, reminders, timers	
				var String AlexaHTTP  = "http://192.168.0.32:8080/amazonechocontrol/account1/PROXY/api/notifications"
				var String json		  = AlexaHTTP.sendHttpGetRequest(7000) 
					Thread::sleep(1500)
				json = AlexaHTTP.sendHttpGetRequest(7000)			// 2nd attempt since the 1st attempt seems to fail often
					Thread::sleep(1500)		
				// logInfo("ECHO","Alexa json is " + json)			
												
				var String length = transform("JSONPATH", "$.notifications.length()", json)
				// logInfo("ECHO","Length is " + length)
				
				var int count 	  = Integer::parseInt(length)
				// logInfo("ECHO","Notifications found for Guest Room is " + count)
				
				if (json === null || json == NULL || json.toString() == '' || length === null || length == NULL || length.toString() == '' || count == UNDEF || count == NULL) { return; }
						 
				var Number i = 0
				var String status = "NULL"
				var String deviceSerialNumber = "NULL"
				var String type = "NULL"
				var String alarmtime = "NULL"
				var String alarmdate = "NULL"
				var CurrentDT = now							

				logInfo("ECHO","CurrentDT is " + CurrentDT)				
				  
				// for all notifications, identify ...
				while (i <= (count - 1)) {
				
					status = transform("JSONPATH", "$.notifications[" + i +"].status", json)
						Thread::sleep(200)
					// logInfo("ECHO","Notification status is " + status)
					
					deviceSerialNumber = transform("JSONPATH", "$.notifications[" + i + "].deviceSerialNumber", json)
						Thread::sleep(200)
					// logInfo("ECHO","Device serial number is " + deviceSerialNumber)
					
					type = transform("JSONPATH", "$.notifications[" + i + "].type", json)
						Thread::sleep(200)
					// logInfo("ECHO","Type is " + type)	

					// logInfo("ECHO","Count is " + i)
					// An ALARM that is ACTIVE and belongs to the GUEST BEDROOM echo device
				
					if (systemStarted.state != ON && Home_Away.state == ON && gInternet.state == ON && type == "Alarm" && status == "ON" && deviceSerialNumber == "G8M0XG1114XXXXXXX") {
				
						alarmtime = transform("JSONPATH", "$.notifications[" + i + "].originalTime", json)
							Thread::sleep(200)
						alarmdate = transform("JSONPATH", "$.notifications[" + i + "].originalDate", json)
							Thread::sleep(200)		
					
						// logInfo("ECHO","Guest Bedroom Alarm found is " + alarmtime + " " + alarmdate)
					
						i = count 	// only the first one is considered - exit while loop
					} 
	
					i = i + 1
				}
				
				if (alarmtime === null || alarmtime.toString() == "NULL" || alarmdate === null || alarmdate.toString() == "NULL") { return; }			
			
				// An active alarm has been found
				if (systemStarted.state != ON && Home_Away.state == ON && gInternet.state == ON && alarmtime.toString() != "NULL" && alarmdate.toString() != "NULL") {
				
					var setAlarmTime = ZonedDateTime.parse(alarmdate + "T" + alarmtime + "000-06:00[America/Chicago]")
					logInfo("ECHO","Guest Bedroom Alexa alarm time used for Hue control is " + setAlarmTime)		// uncomment this one to determine what alarm time was used
				
					if (CurrentDT.isBefore(setAlarmTime) && CurrentDT.plusMinutes(20).isAfter(setAlarmTime)) {
					
						logInfo("ECHO","Guest Bedroom Alarm is within 20 minute range.")
						if (CurrentDT.isBefore(setAlarmTime) && CurrentDT.plusMinutes(15).isAfter(setAlarmTime)) {
					
							logInfo("ECHO","Guest Bedroom Alarm is within 15 minutes range.")
							if (CurrentDT.isBefore(setAlarmTime) && CurrentDT.plusMinutes(10).isAfter(setAlarmTime)) {
					
								logInfo("ECHO","Guest Bedroom Alarm is within 10 minute range.")
								GuestBedLamp_Dimmer.sendCommand(new PercentType(80))			// 80%
									Thread::sleep(1500)
								GuestBedLamp_ColorTemp.sendCommand(new PercentType(100))		// Full White
					
							} else {

								GuestBedLamp_Dimmer.sendCommand(new PercentType(50))			// 50%
									Thread::sleep(1500)
								GuestBedLamp_ColorTemp.sendCommand(new PercentType(100))		// Full White
							}
	
						} else {
	
							GuestBedLamp_Dimmer.sendCommand(new PercentType(30))				// 30%
								Thread::sleep(1500)
							GuestBedLamp_ColorTemp.sendCommand(new PercentType(100))			// Full White
								Thread::sleep(200)
							GuestBedLamp_Switch.sendCommand(ON)	
						}
					} 
				}
            }
	    }
end