自定义设备操作无法在带有嵌入式助手

时间:2018-05-04 17:42:58

标签: json google-assistant-sdk

我有一个运行在树莓派上的谷歌家庭助理,我试图为它做自定义设备操作。

我想要做的是:"嘿谷歌分析这个对象",它只是拍摄我持有的任何东西。我出于某种原因无法使用"拍照"因为它只是响应"抱歉我还不能拍照!"

我无法让这个工作,我不明白为什么。闪烁的示例有效,但此命令更简单,甚至没有参数。我已经更新了操作并获得了一个正常(您的项目XXXX助理的应用程序已成功更新您的操作)。但每当我说"嘿谷歌分析这个对象",它只是chrips"抱歉!我不明白"。

我在这里做错了什么?

动作文件中的JSON:

    {
    "manifest": {
        "displayName": "Office Controller",
        "invocationName": "Office Controller",
        "category": "PRODUCTIVITY"
    },
    "actions": [
            {
            "name": "com.acme.actions.analyze_object",
            "availability": {
                "deviceClasses": [
                    {
                        "assistantSdkDevice": {}
                    }
                ]
            },
            "intent": {
                "name": "com.acme.intents.analyze_object",
                "trigger": {
                    "queryPatterns": [
                        "analyze this object"
                    ]
                }
            },
            "fulfillment": {
                "staticFulfillment": {
                    "templatedResponse": {
                        "items": [
                            {
                                "simpleResponse": {
                                    "textToSpeech": "Ok. Analyzing."
                                }
                            },
                            {
                                "deviceExecution": {
                                    "command": "com.acme.commands.analyze_object"
                                }
                            }
                        ]
                    }
                }
            }
        },
        {
            "name": "com.acme.actions.blink_light",
            "availability": {
                "deviceClasses": [
                    {
                        "assistantSdkDevice": {}
                    }
                ]
            },
            "intent": {
                "name": "com.acme.intents.blink_light",
                "parameters": [
                    {
                        "name": "number",
                        "type": "SchemaOrg_Number"
                    },
                    {
                        "name": "light_target",
                        "type": "LightType"
                    }
                ],
                "trigger": {
                    "queryPatterns": [
                        "blink the $LightType:light_target $SchemaOrg_Number:number times"
                    ]
                }
            },
            "fulfillment": {
                "staticFulfillment": {
                    "templatedResponse": {
                        "items": [
                            {
                                "simpleResponse": {
                                    "textToSpeech": "Blinking the $light_target.raw $number times"
                                }
                            },
                            {
                                "deviceExecution": {
                                    "command": "com.acme.commands.blink_light",
                                    "params": {
                                        "lightKey": "$light_target",
                                        "number": "$number"
                                    }
                                }
                            }
                        ]
                    }
                }
            }
        }
    ],
    "types": [
        {
            "name": "$LightType",
            "entities": [
                {
                    "key": "LIGHT",
                    "synonyms": [
                        "LED",
                        "light",
                        "bulb",
                        "light bulb"
                    ]
                }
            ]
        }
    ]
}

python程序中的事件代码

if event.type == EventType.ON_DEVICE_ACTION:
        for command, params in process_device_actions(event, device_id):
            print('Do command', command, 'with params', str(params))

            if command == "com.acme.commands.blink_light":
                number = int( params['number'] )
                for i in range(int(number)):
                    print('Device is blinking.')
                    GPIO.output(25, 1)
                    time.sleep(1)
                    GPIO.output(25, 0)
                    time.sleep(1)

            elif command == "com.acme.commands.analyze_object":
                camera = picamera.PiCamera()
                camera.capture('photo.jpg')
                print('Took a photo')

1 个答案:

答案 0 :(得分:0)

呃发现了。您必须更新您的操作,然后针对您的操作进行测试。我忘了推测试。