restructure intents to make alexa happy

This commit is contained in:
Emil Lerch 2026-02-03 15:12:36 -08:00
parent c1a5720eb5
commit 31c940ef15
Signed by: lobo
GPG key ID: A7B62D657EF764F8
2 changed files with 80 additions and 25 deletions

View file

@ -30,17 +30,9 @@
{
"name": "HomeAssistantIntent",
"slots": [
{
"name": "action",
"type": "DEVICE_ACTION"
},
{
"name": "device",
"type": "AMAZON.SearchQuery"
},
{
"name": "value",
"type": "AMAZON.NUMBER"
}
],
"samples": [
@ -54,15 +46,6 @@
"turn {device} off",
"switch off {device}",
"switch off the {device}",
"set {device} to {value}",
"set {device} to {value} percent",
"set the {device} to {value}",
"set the {device} to {value} percent",
"set {device} to {value} degrees",
"set the {device} to {value} degrees",
"dim {device} to {value}",
"dim the {device} to {value}",
"dim {device} to {value} percent",
"is {device} on",
"is the {device} on",
"is {device} off",
@ -77,12 +60,40 @@
"check the {device}",
"check on {device}",
"check on the {device}",
"{action} {device}",
"{action} the {device}",
"toggle {device}",
"toggle the {device}"
]
},
{
"name": "SetDeviceValueIntent",
"slots": [
{
"name": "target",
"type": "DEVICE_NAME"
},
{
"name": "value",
"type": "AMAZON.NUMBER"
}
],
"samples": [
"set {target} to {value}",
"set {target} to {value} percent",
"set the {target} to {value}",
"set the {target} to {value} percent",
"set {target} to {value} degrees",
"set the {target} to {value} degrees",
"dim {target} to {value}",
"dim the {target} to {value}",
"dim {target} to {value} percent",
"change {target} to {value}",
"change the {target} to {value}",
"make {target} {value}",
"make the {target} {value}",
"make {target} {value} percent",
"make the {target} {value} degrees"
]
},
{
"name": "AMAZON.HelpIntent",
"samples": []
@ -135,6 +146,31 @@
}
}
]
},
{
"name": "DEVICE_NAME",
"values": [
{"name": {"value": "bedroom light"}},
{"name": {"value": "kitchen light"}},
{"name": {"value": "living room light"}},
{"name": {"value": "bathroom light"}},
{"name": {"value": "hallway light"}},
{"name": {"value": "office light"}},
{"name": {"value": "garage light"}},
{"name": {"value": "porch light"}},
{"name": {"value": "front porch"}},
{"name": {"value": "back porch"}},
{"name": {"value": "bedroom lamp"}},
{"name": {"value": "desk lamp"}},
{"name": {"value": "floor lamp"}},
{"name": {"value": "thermostat"}},
{"name": {"value": "downstairs thermostat"}},
{"name": {"value": "upstairs thermostat"}},
{"name": {"value": "bedroom fan"}},
{"name": {"value": "ceiling fan"}},
{"name": {"value": "living room fan"}},
{"name": {"value": "kitchen fan"}}
]
}
]
}

View file

@ -113,7 +113,9 @@ fn handleIntentRequest(allocator: std.mem.Allocator, request_obj: json.Value, co
if (std.mem.eql(u8, intent_name, "RecirculateWaterIntent")) {
return handleRecirculateWater(allocator, config);
} else if (std.mem.eql(u8, intent_name, "HomeAssistantIntent")) {
} else if (std.mem.eql(u8, intent_name, "HomeAssistantIntent") or
std.mem.eql(u8, intent_name, "SetDeviceValueIntent"))
{
return handleHomeAssistantIntent(allocator, intent_obj, config);
} else if (std.mem.eql(u8, intent_name, "WeezTheJuiceIntent")) {
return handleWeezTheJuice(allocator, config);
@ -264,9 +266,12 @@ const IntentParams = struct {
/// Parse the action, device name, and value from Alexa slots.
/// Returns null if device_name is missing (required field).
/// Supports both HomeAssistantIntent (device slot) and SetDeviceValueIntent (target slot).
fn parseHomeAssistantSlots(slots: ?json.Value) ?IntentParams {
// Get device name (required)
const device_name = extractSlotValue(slots, "device") orelse return null;
// Get device name (required) - try "device" first, then "target"
const device_name = extractSlotValue(slots, "device") orelse
extractSlotValue(slots, "target") orelse
return null;
// Get action (optional - may be inferred from utterance)
const action_slot = extractSlotValue(slots, "action");
@ -385,16 +390,30 @@ fn printHelp() !void {
\\
\\Local mode options (when not running in Lambda):
\\ --type=TYPE Request type: launch, intent, session_ended (default: intent)
\\ --intent=NAME Intent name (e.g., HomeAssistantIntent, RecirculateWaterIntent)
\\ --device=NAME Device name for HomeAssistantIntent
\\ --intent=NAME Intent name (see below)
\\ --device=NAME Device name for HomeAssistantIntent/SetDeviceValueIntent
\\ --action=ACTION Action: "turn on", "turn off", "toggle"
\\ --value=NUM Numeric value (brightness %, temperature)
\\
\\Intent types:
\\ RecirculateWaterIntent Start hot water recirculation
\\ HomeAssistantIntent Control devices (on/off/toggle/query)
\\ SetDeviceValueIntent Set device to a specific value
\\ WeezTheJuiceIntent Easter egg - toggles bedroom light
\\ AMAZON.HelpIntent Show help message
\\ AMAZON.StopIntent Stop/goodbye
\\ AMAZON.CancelIntent Cancel/goodbye
\\
\\Examples:
\\ bootstrap --type=launch
\\ bootstrap --intent=RecirculateWaterIntent
\\ bootstrap --intent=HomeAssistantIntent --device="bedroom light" --action="turn on"
\\ bootstrap --intent=HomeAssistantIntent --device="thermostat" --value=72
\\ bootstrap --intent=HomeAssistantIntent --device="bedroom light" --action="turn off"
\\ bootstrap --intent=HomeAssistantIntent --device="bedroom light" --action="toggle"
\\ bootstrap --intent=HomeAssistantIntent --device="bedroom light"
\\ (no action = query state)
\\ bootstrap --intent=SetDeviceValueIntent --device="bedroom light" --value=50
\\ bootstrap --intent=SetDeviceValueIntent --device="thermostat" --value=72
\\ bootstrap --intent=WeezTheJuiceIntent
\\
\\Environment variables (or .env file in current directory):