插件默认保存在~/.config/QSmartAssistant/plugins
中,首次启动需要mv Data/plugins_order_default.txt Data/plugins_order.txt
这里以quitrobot
为例
-
在Plugins中添加
CMakeLists.txt
文件内容为cmake_minimum_required(VERSION 3.14) project(QuitRobot VERSION 0.1.0) # 项目名称自己定义,最终plugins_order.txt中使用的名称就是项目名称 set(CMAKE_INCLUDE_CURRENT_DIR ON) set(CMAKE_AUTOMOC ON) find_package(QT NAMES Qt5 Qt6 REQUIRED COMPONENTS Core) find_package(Qt${QT_VERSION_MAJOR} REQUIRED COMPONENTS Multimedia) PLUGIN_COMMON() target_link_libraries(${PROJECT_NAME} Qt5::Core Qt5::Multimedia lpcommon)
-
在目录中新建一个文件,格式为
#include "../Plugin.h" #include <QObject> // 头文件必须集成 class QuitRobot : public QObject, Plugin { // 下面三行必须要有 Q_OBJECT Q_INTERFACES(Plugin) Q_PLUGIN_METADATA(IID QSmartAssistant_PLUGIN_ID) public: QuitRobot(); QString getName() override; bool handle(const QString& text, const ParsedIntent& parsedIntent, bool& isImmersive) override; void setPluginHelper(IPluginHelper* helper) override; void recvMessage(const PluginMessage& message) override; signals: void sendMessage(PluginMessage message) override; private: IPluginHelper* helper; };
-
编写完成之后重新运行cmake然后make便会自动在插件文件夹下生成新的插件
说明: homeassistant交互插件,可以触发脚本及开关命令
选项: hass
选项 | 默认值 | 含义 |
---|---|---|
url | http://127.0.0.1:8123 | homeassistant api服务器地址 |
key | xxx | 长期访问令牌的key,注意Bearer不能少 |
services | xxx | 触发的服务,具体配置可以参照下文 |
services配置方式:
"services": [
{
"intent": "OPEN_FURNITURE",
notify: true,
"slots": [
{
"slotName": "furniture",
"slotValue": "热水器"
}
]
"path": "/api/services/switch/turn_on",
"params": {
"entity_id": "switch.cuco_cp2d_46fc_switch"
}
},
{
"intent": "OPEN_FURNITURE",
"notify": true,
"params": {
"entity_id": "script.cuco_cp2d_46fc_switch_timer",
"variables": {
"duration": "{time|--}"
}
},
"path": "/api/services/script/turn_on",
"pattern": ".*热水器.*"
}
]
当遇到intent时开始进行匹配
匹配可以根据nlu提取出来的slotName和slotValue进行匹配,也可以使用正则表达式pattern进行匹配
path是调用api的路径,具体可以参考https://developers.home-assistant.io/docs/api/rest/
params是传递给homeassistant的参数,注意其中可以使用{slotName}引用slot的内容
notify: 执行完成之后是否提示执行成功
参数可以按照{slotName|defaultValue}的样式使用槽中的值,
如果defaultValue为--则匹配失败时不添加该参数
调用样例:
- 开灯
- 光灯
- 打开热水器
- 关闭热水器
- 热水器开20分钟
homeassistant中脚本编写样例:
alias: 定时热水器
sequence:
- type: turn_on
device_id: 23403927ea9d0ff1c17a44871a1c75ee
entity_id: 6afa4b81894ad5ac9e212a9b742150e6
domain: switch
- condition: template
value_template: "{{duration is defined }}"
- delay: "{{ duration }}"
- type: turn_off
device_id: 23403927ea9d0ff1c17a44871a1c75ee
entity_id: 6afa4b81894ad5ac9e212a9b742150e6
domain: switch
description: ""
说明: 网易云音乐插件
选项: netease_cloud
选项 | 默认值 | 参数 |
---|---|---|
phone | xxx | 登录的手机号 |
password | xxx | 登录的密码 |
volumeStep | 10 | 每次调节音量的大小 |
homeDir | xxx | js api的路径地址 |
port | 34932 | js api所使用的端口 |
目前支持qt版的api和js版的api,如果要使用qt版的api可以运行scripts/install_QCloudMusicApi.sh
。但是目前qt版由于登录存在问题很多api无法调用,目前推荐使用js的api。
想要启用js的api可以运行cmake -DNETEASE_USE_JS=ON ..
调用样例:
- 播放音乐
- 放首歌
- 播放孤勇者
- 播放张杰的三国
说明: 天气插件,使用和风天气api
选项: weather
选项 | 默认值 | 含义 |
---|---|---|
key | xxx | 和风天气api |
home | xxx | 家的位置,用于默认的天气预报。例如可以填北京市朝阳区 |
调用样例:
- 明天的天气
- 未来三天的天气
- 今天晚上的天气怎么样