mirror of
				https://github.com/thorsten-gehrig/alexa-remote-control.git
				synced 2025-10-31 05:57:36 +01:00 
			
		
		
		
	PR #77 from adn77/master
Routines can now be triggered by either name or utterance
This commit is contained in:
		| @@ -45,6 +45,7 @@ | |||||||
| #               (thanks to rich-gepp https://github.com/rich-gepp) | #               (thanks to rich-gepp https://github.com/rich-gepp) | ||||||
| # 2019-08-05: v0.14 added Volume setting via routine, and $SPEAKVOL | # 2019-08-05: v0.14 added Volume setting via routine, and $SPEAKVOL | ||||||
| # 2019-11-18: v0.14a download 200 routines instead of only the first 20 | # 2019-11-18: v0.14a download 200 routines instead of only the first 20 | ||||||
|  | # 2019-12-23: v0.14b Trigger routines by either utterance or routine name | ||||||
| # | # | ||||||
| ### | ### | ||||||
| # | # | ||||||
| @@ -573,12 +574,15 @@ if [ -n "${SEQUENCECMD}" ] ; then | |||||||
| 		 "https://${ALEXA}/api/behaviors/automations?limit=200" > "${TMP}/.alexa.automation" | 		 "https://${ALEXA}/api/behaviors/automations?limit=200" > "${TMP}/.alexa.automation" | ||||||
|  |  | ||||||
| 		AUTOMATION=$(jq --arg utterance "${UTTERANCE}" -r '.[] | select( .triggers[].payload.utterance == $utterance) | .automationId' "${TMP}/.alexa.automation") | 		AUTOMATION=$(jq --arg utterance "${UTTERANCE}" -r '.[] | select( .triggers[].payload.utterance == $utterance) | .automationId' "${TMP}/.alexa.automation") | ||||||
|  | 		if [ -z "${AUTOMATION}" ] ; then | ||||||
|  | 			AUTOMATION=$(jq --arg utterance "${UTTERANCE}" -r '.[] | select( .name == $utterance) | .automationId' "${TMP}/.alexa.automation") | ||||||
| 			if [ -z "${AUTOMATION}" ] ; then | 			if [ -z "${AUTOMATION}" ] ; then | ||||||
| 				echo "ERROR: no such utterance '${UTTERANCE}' in Alexa routines" | 				echo "ERROR: no such utterance '${UTTERANCE}' in Alexa routines" | ||||||
| 				rm -f "${TMP}/.alexa.automation" | 				rm -f "${TMP}/.alexa.automation" | ||||||
| 				exit 1 | 				exit 1 | ||||||
| 			fi | 			fi | ||||||
| 		SEQUENCE=$(jq --arg utterance "${UTTERANCE}" -r -c '.[] | select( .triggers[].payload.utterance == $utterance) | .sequence' "${TMP}/.alexa.automation" | sed 's/"/\\"/g' | sed "s/ALEXA_CURRENT_DEVICE_TYPE/${DEVICETYPE}/g" | sed "s/ALEXA_CURRENT_DSN/${DEVICESERIALNUMBER}/g" | sed "s/ALEXA_CUSTOMER_ID/${MEDIAOWNERCUSTOMERID}/g") | 		fi | ||||||
|  | 		SEQUENCE=$(jq --arg automation "${AUTOMATION}" -r -c '.[] | select( .automationId == $automation) | .sequence' "${TMP}/.alexa.automation" | sed 's/"/\\"/g' | sed "s/ALEXA_CURRENT_DEVICE_TYPE/${DEVICETYPE}/g" | sed "s/ALEXA_CURRENT_DSN/${DEVICESERIALNUMBER}/g" | sed "s/ALEXA_CUSTOMER_ID/${MEDIAOWNERCUSTOMERID}/g") | ||||||
| 		rm -f "${TMP}/.alexa.automation" | 		rm -f "${TMP}/.alexa.automation" | ||||||
|  |  | ||||||
| 		ALEXACMD='{"behaviorId":"'${AUTOMATION}'","sequenceJson":"'${SEQUENCE}'","status":"ENABLED"}' | 		ALEXACMD='{"behaviorId":"'${AUTOMATION}'","sequenceJson":"'${SEQUENCE}'","status":"ENABLED"}' | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user