How can I use the JSON input that Amazon Alexa passes to HA Intents?
Background:
I’ve got the Amazon Developer Skills side setup with a TurnOn and TurnOff intent along with a switch slot and a light slot. The switch slot has my various zwave switches as values and some synonyms configured. I can successfully get Alexa to turn on a single switch using the following code:
TurnOn:
action:
service: switch.turn_on
data:
entity_id: switch.garage_switch
speech:
type: plain
text: OK
Unfortunately with my current understanding/experience I would need to create a separate intent per switch in the Amazon Developer area similar to TurnOnGarage and TurnOnBedroom. When I try to use a variable HA errors out with not being able to use “extra keys” in the entity_id. What I’ve tried to do is just use a variable of some kind to substitute for the entity_id such as:
TurnOn:
action:
service: switch.turn_on
data_template:
entity_id: {{ value_json.resolutionsPerAuthority[].values[].value.name }}
speech:
type: plain
text: OK
where the entity_id is what is in the JSON that Alexa is sending to my HA.
"request": {
"type": "IntentRequest",
"requestId": "amzn1.echo-api.request.REDACTED",
"timestamp": "2019-03-10T17:15:43Z",
"locale": "en-US",
"intent": {
"name": "TurnOn",
"confirmationStatus": "NONE",
"slots": {
"light": {
"name": "light",
"confirmationStatus": "NONE"
},
"switch": {
"name": "switch",
"value": "garage",
"resolutions": {
"resolutionsPerAuthority": [
{
"authority": "amzn1.er-authority.echo-sdk.amzn1.ask.skill.REDACTED.switch",
"status": {
"code": "ER_SUCCESS_MATCH"
},
"values": [
{
"value": {
"name": "switch.garage_switch",
"id": "REDACTED"
}
}
]
}
]
},
"confirmationStatus": "NONE",
"source": "USER"
}
}
}
}
}
Is what I’m trying to do possible/practical or is there a better way to accomplish getting Alexa to turn on individual switches without hard coding an Alexa intent for each one?