Raspberry Pi Google Assistant上的Google自定义设备操作出错 - python

我正在Raspberry Pi 3上创建一个Google助手,并且试图创建一个自定义设备操作来最终打开我的车库门。此时,它所做的全部就是用LED播放。

这是我的actions.json文件:

{
    "manifest": {
        "displayName": "Garage door",
        "invocationName": "Garage door",
        "category": "PRODUCTIVITY"
    },
    "actions": [
        {
            "name": "me.custom.actions.GarageDoor",
            "availability": {
                "deviceClasses": [
                    {
                        "assistantSdkDevice": {}
                    }
                ]
            },
            "intent": {
                "name": "me.custom.intents.GarageDoor",
                "trigger": {
                    "queryPatterns": [
                        "open the garage door",
                        "close the garage door"
                    ]
                }
            },
            "fulfillment": {
                "staticFulfillment": {
                    "templatedResponse": {
                        "items": [
                            {
                                "simpleResponse": {
                                    "textToSpeech": "Okay"
                                }
                            },
                            {
                                "deviceExecution": {
                                    "command": "me.custom.commands.GarageDoor"
                                }
                            }
                        ]
                    }
                }
            }
        }
    ],
    "types": []
}

但是,当我运行命令时,出现此错误:

INFO:root:Transcript of user request: "open the garage door".
INFO:root:Playing assistant response.
WARNING:root:Error during command execution
Traceback (most recent call last):
  File "/home/pi/assistant-sdk-python/google-assistant-sdk/googlesamples/assistant/grpc/device_helpers.py", line 94, in dispatch_command
    self.handlers[command](**params)
TypeError: gdoor() argument after ** must be a mapping, not NoneType

这是我的处理程序:

@device_handler.command('me.custom.commands.GarageDoor')
    def gdoor(*args):
        print(args)
        global g_open
        if g_open:
            GPIO.output(18, 0)
            g_open = 0
        else:
            GPIO.output(18, 1)
            g_open = 1

我在玩* args,看看它是否可以修复任何东西-没错。我已将软件包名称更改为自定义,仅出于保密目的。我在这里很困惑。任何帮助表示赞赏!

谢谢!

参考方案

查看the sample code时,函数签名似乎有所不同,因为它直接添加了参数。

@device_handler.command('com.example.commands.BlinkLight')
def blink(speed, number):
    logging.info('Blinking device %s times.' % number)
    delay = 1
    if speed == "SLOWLY":
        delay = 2
    elif speed == "QUICKLY":
        delay = 0.5
    for i in range(int(number)):
        logging.info('Device is blinking.')
        time.sleep(delay)

看一下动作包,似乎您没有提供任何与命令执行一起进行的动作。如the sample所示:

{
    "deviceExecution": {
        "command": "com.example.commands.BlinkLight",
        "params": {
            "speed": "$speed",
            "number": "$number"
        }
    }
}

没有任何参数,它可能根本不会映射任何功能。

Raspberry Pi在python和raspistill中捕获的图像质量 - python

我正在使用覆盆子pi来检测我的猫何时在桌子上,并且我在几个图像捕获部件上遇到了一些麻烦。这是我正在运行的相关代码:from picamera.array import PiRGBArray from picamera import PiCamera import time import cv2 import subprocess #method 1 with…

在树莓派上运行python脚本 - python

我正在研究rapiberry pi 3大约3个月,开始使用它时遇到了问题。我找不到在树莓派打开时在其上运行python脚本的有效,安全的方法(没有监视器,鼠标和键盘)。此刻,我在/ etc / profile中添加了“ $ sudo run myscript.py&”但是有时候,当我打开它时,直到将显示器,鼠标和键盘连接到该脚本并使用GUI运行脚本,脚本才能…

如果一个Cron作业失败,请继续执行下一个作业 - python

我已经设置了Crontab来执行一系列Python脚本,以便查询太阳能逆变器并将结果上传到PVOutput:*/5 * * * * cd /home/Pi/; python pvout_upload.py; */5 * * * * cd /home/Pi/; python weather.py; 问题是如果Internet断开,则这些脚本将失败。因此,我创建…

Python uuid4,如何限制唯一字符的长度 - python

在Python中,我正在使用uuid4()方法创建唯一的字符集。但是我找不到将其限制为10或8个字符的方法。有什么办法吗?uuid4()ffc69c1b-9d87-4c19-8dac-c09ca857e3fc谢谢。 参考方案 尝试:x = uuid4() str(x)[:8] 输出:"ffc69c1b" Is there a way to…

Python-crontab模块 - python

我正在尝试在Linux OS(CentOS 7)上使用Python-crontab模块我的配置文件如下:{ "ossConfigurationData": { "work1": [ { "cronInterval": "0 0 0 1 1 ?", "attribute&…