目的:Homeassistant 的Node-red插件之小爱同学语音功能开通,实现播报任意带变量的文本
视频部分效果可见:https://www.bilibili.com/video/BV1id4y1r78d
【Homeassistant 的Node-red插件之小爱同学语音功能开通】
1. 实验环境:
首先需要你安装Node-red插件和小米MIoT设备,我自己根据esp8266采用esphome开发了对应设备,下面列举了部分传感器和执行器
部分传感器显示
执行器显示
我把对应设备进行分区域管理,小爱音箱接入正常
摄像头也接入进来了
安装对于插件亲参照
【小米MIoT设备接入HomeAssistant通用插件教程】
智能家居home assistant之常用插件
ESPHome
2. 实验过程
配置过程:在流程中绘制正确的逻辑控制节点流,部署验证
2.1 打开Node-red
首先说明一下node-red中心思想:条件触发+信号处理+展示动作
2.2 安装node-red-contrib-xiaoai-tts
节点
点击右上角菜单按钮
选择节点管理,然后控制板安装搜索node-red-contrib-xiaoai-tts
节点
双击流程1编辑其中的内容
我们来命名小爱同学
2.3 添加控制节点流
点击共通的Inject触发器,拖拽到控制流面板中
修改名称为触发器,然后点击完成,单个节点完成对应配置。
在小米菜单中选择音量设置(这一个节点可以省略),接在触发器后面
双击编辑内容
根据提示去ioBroker注册,
然后填写账号密码
呼叫设备
正常联通,会触发小爱语音,小爱设备设置如下,Domain选择xiaoai_miot,智能语音以及合适的设备实体,如果Data不会填可以直接Load案列,我配置的json如下
{"text":"你好鸭!欢迎来到智慧实验室,我是小助手"}
添加调试提示,最后完成小爱节点的配置
不正常联通,则会触发QQ邮箱故障提示,Data配置json如下
{
"message":"<b>当前智慧实验室小助手失效,请重新检测设备</b>",
"title":"消息来自HomeAssistant",
"email":"3126171871@qq.com"
}
添加调试提示,最后完成QQ邮箱节点的配置
为了方便调试选择debug调试
默认配置就好
将他们以此首尾连接,部署所有控制流
我的控制流完整json如下
[
{
"id": "6f0969d5e2f09623",
"type": "api-call-service",
"z": "37ac4d80dffc96b7",
"name": "我是智慧实验室助手提示音",
"server": "41ef4b78.2e2ab4",
"version": 5,
"debugenabled": false,
"domain": "xiaomi_miot",
"service": "intelligent_speaker",
"areaId": [],
"deviceId": [],
"entityId": [
"sensor.xiaomi_lx04_5e02_conversation"
],
"data": "{\"text\":\"你好鸭!欢迎来到智慧实验室,我是小助手\"}",
"dataType": "jsonata",
"mergeContext": "",
"mustacheAltTags": false,
"outputProperties": [
{
"property": "payload",
"propertyType": "msg",
"value": "智慧实验室助手连接成功",
"valueType": "str"
}
],
"queue": "none",
"x": 820,
"y": 140,
"wires": [
[
"cdf9b42ee3b909ee"
]
]
},
{
"id": "6f985e77ba2239d8",
"type": "inject",
"z": "37ac4d80dffc96b7",
"name": "触发器",
"props": [
{
"p": "payload"
},
{
"p": "topic",
"vt": "str"
}
],
"repeat": "",
"crontab": "",
"once": false,
"onceDelay": 0.1,
"topic": "",
"payload": "",
"payloadType": "date",
"x": 250,
"y": 180,
"wires": [
[
"c87ec627c3d65acc"
]
]
},
{
"id": "cdf9b42ee3b909ee",
"type": "debug",
"z": "37ac4d80dffc96b7",
"name": "打印调试",
"active": true,
"tosidebar": true,
"console": false,
"tostatus": false,
"complete": "payload",
"targetType": "msg",
"statusVal": "",
"statusType": "auto",
"x": 1060,
"y": 180,
"wires": []
},
{
"id": "c87ec627c3d65acc",
"type": "xiaoai-volume",
"z": "37ac4d80dffc96b7",
"name": "",
"xiaoai": "b0dd4ba55e81b093",
"volume": "43",
"device": "",
"x": 420,
"y": 180,
"wires": [
[
"6f0969d5e2f09623"
],
[
"710be66d9ae5fa19"
]
]
},
{
"id": "710be66d9ae5fa19",
"type": "api-call-service",
"z": "37ac4d80dffc96b7",
"name": "小助手故障提醒",
"server": "41ef4b78.2e2ab4",
"version": 5,
"debugenabled": false,
"domain": "smtp",
"service": "notify",
"areaId": [],
"deviceId": [],
"entityId": [],
"data": "{\t \"message\":\"<b>当前智慧实验室小助手失效,请重新检测设备</b>\",\t \"title\":\"消息来自HomeAssistant\",\t \"email\":\"3126171871@qq.com\"\t}",
"dataType": "jsonata",
"mergeContext": "",
"mustacheAltTags": false,
"outputProperties": [
{
"property": "payload",
"propertyType": "msg",
"value": "小助手故障提醒",
"valueType": "str"
}
],
"queue": "none",
"x": 820,
"y": 200,
"wires": [
[
"cdf9b42ee3b909ee"
]
]
},
{
"id": "41ef4b78.2e2ab4",
"type": "server",
"name": "Home Assistant",
"version": 4,
"addon": true,
"rejectUnauthorizedCerts": true,
"ha_boolean": "y|yes|true|on|home|open",
"connectionDelay": true,
"cacheJson": true,
"heartbeat": false,
"heartbeatInterval": "30",
"areaSelector": "friendlyName",
"deviceSelector": "friendlyName",
"entitySelector": "friendlyName",
"statusSeparator": "at: ",
"statusYear": "hidden",
"statusMonth": "short",
"statusDay": "numeric",
"statusHourCycle": "h23",
"statusTimeFormat": "h:m"
},
{
"id": "b0dd4ba55e81b093",
"type": "xiaoai-tts-configurator",
"name": "测试"
}
]
大家可以直接导入到自己的控制中
2.4 验证结果
点击触发器,正常连接小爱音箱会自动播报,并答应输出
失败就会收到邮件提示
3. 分享带变量的语音播报
3.1 自动播报温度
json配置如下,修改对应报错和设备就可实现
[
{
"id": "217b64a92d993c3b",
"type": "api-call-service",
"z": "37ac4d80dffc96b7",
"name": "小爱播放",
"server": "41ef4b78.2e2ab4",
"version": 5,
"debugenabled": false,
"domain": "xiaomi_miot",
"service": "intelligent_speaker",
"areaId": [],
"deviceId": [],
"entityId": [
"sensor.xiaomi_lx04_5e02_conversation"
],
"data": "",
"dataType": "jsonata",
"mergeContext": "",
"mustacheAltTags": false,
"outputProperties": [],
"queue": "none",
"x": 860,
"y": 1080,
"wires": [
[
"a6425ddb4648c012"
]
]
},
{
"id": "dc13e2873b6afa8b",
"type": "inject",
"z": "37ac4d80dffc96b7",
"name": "触发器",
"props": [
{
"p": "payload"
},
{
"p": "topic",
"vt": "str"
}
],
"repeat": "",
"crontab": "",
"once": false,
"onceDelay": 0.1,
"topic": "",
"payload": "",
"payloadType": "date",
"x": 210,
"y": 1080,
"wires": [
[
"2092e6ecfbe9a69e"
]
]
},
{
"id": "923a3ed75809c270",
"type": "function",
"z": "37ac4d80dffc96b7",
"name": "设计播报文本",
"func": "var msg1={}\nvar msgsend=\"当前办公区温度:\"+msg.payload+\"摄氏度\"\nmsg1.payload = { \"data\": { \"text\": msgsend}}\nreturn msg1;",
"outputs": 1,
"noerr": 0,
"initialize": "",
"finalize": "",
"libs": [],
"x": 640,
"y": 1080,
"wires": [
[
"217b64a92d993c3b"
]
]
},
{
"id": "2092e6ecfbe9a69e",
"type": "api-current-state",
"z": "37ac4d80dffc96b7",
"name": "获取办公区温度",
"server": "41ef4b78.2e2ab4",
"version": 3,
"outputs": 1,
"halt_if": "",
"halt_if_type": "str",
"halt_if_compare": "is",
"entity_id": "sensor.office_area_temperature1",
"state_type": "str",
"blockInputOverrides": false,
"outputProperties": [
{
"property": "payload",
"propertyType": "msg",
"value": "",
"valueType": "entityState"
},
{
"property": "data",
"propertyType": "msg",
"value": "",
"valueType": "entity"
}
],
"for": "0",
"forType": "num",
"forUnits": "minutes",
"override_topic": false,
"state_location": "payload",
"override_payload": "msg",
"entity_location": "data",
"override_data": "msg",
"x": 400,
"y": 1080,
"wires": [
[
"923a3ed75809c270"
]
]
},
{
"id": "a6425ddb4648c012",
"type": "debug",
"z": "37ac4d80dffc96b7",
"name": "打印调试",
"active": true,
"tosidebar": true,
"console": false,
"tostatus": false,
"complete": "payload",
"targetType": "msg",
"statusVal": "",
"statusType": "auto",
"x": 1100,
"y": 1080,
"wires": []
},
{
"id": "41ef4b78.2e2ab4",
"type": "server",
"name": "Home Assistant",
"version": 4,
"addon": true,
"rejectUnauthorizedCerts": true,
"ha_boolean": "y|yes|true|on|home|open",
"connectionDelay": true,
"cacheJson": true,
"heartbeat": false,
"heartbeatInterval": "30",
"areaSelector": "friendlyName",
"deviceSelector": "friendlyName",
"entitySelector": "friendlyName",
"statusSeparator": "at: ",
"statusYear": "hidden",
"statusMonth": "short",
"statusDay": "numeric",
"statusHourCycle": "h23",
"statusTimeFormat": "h:m"
}
]
3.2 播报当前时间
json配置如下,修改对应报错和设备就可实现
[
{
"id": "c440f14b9a897411",
"type": "api-call-service",
"z": "37ac4d80dffc96b7",
"name": "小爱播放",
"server": "41ef4b78.2e2ab4",
"version": 5,
"debugenabled": false,
"domain": "xiaomi_miot",
"service": "intelligent_speaker",
"areaId": [],
"deviceId": [],
"entityId": [
"sensor.xiaomi_lx04_5e02_conversation"
],
"data": "",
"dataType": "jsonata",
"mergeContext": "",
"mustacheAltTags": false,
"outputProperties": [],
"queue": "none",
"x": 860,
"y": 1160,
"wires": [
[
"f584c5d4390a2313"
]
]
},
{
"id": "e963bbc5ccc33294",
"type": "inject",
"z": "37ac4d80dffc96b7",
"name": "触发器",
"props": [
{
"p": "payload"
},
{
"p": "topic",
"vt": "str"
}
],
"repeat": "",
"crontab": "",
"once": false,
"onceDelay": 0.1,
"topic": "",
"payload": "",
"payloadType": "date",
"x": 210,
"y": 1160,
"wires": [
[
"88ecc8da53221391"
]
]
},
{
"id": "c3529a5aae4d759e",
"type": "function",
"z": "37ac4d80dffc96b7",
"name": "设计播报文本",
"func": "var msg1={}\nvar msgsend=\"当前北京时间是:\"+msg.payload\nmsg1.payload = { \"data\": { \"text\": msgsend}}\nreturn msg1;",
"outputs": 1,
"noerr": 0,
"initialize": "",
"finalize": "",
"libs": [],
"x": 640,
"y": 1160,
"wires": [
[
"c440f14b9a897411"
]
]
},
{
"id": "88ecc8da53221391",
"type": "api-current-state",
"z": "37ac4d80dffc96b7",
"name": "获取当前时间",
"server": "41ef4b78.2e2ab4",
"version": 3,
"outputs": 1,
"halt_if": "",
"halt_if_type": "str",
"halt_if_compare": "is",
"entity_id": "button.ipc_set_system_date_and_time",
"state_type": "str",
"blockInputOverrides": false,
"outputProperties": [
{
"property": "payload",
"propertyType": "msg",
"value": "",
"valueType": "entityState"
},
{
"property": "data",
"propertyType": "msg",
"value": "",
"valueType": "entity"
}
],
"for": "0",
"forType": "num",
"forUnits": "minutes",
"override_topic": false,
"state_location": "payload",
"override_payload": "msg",
"entity_location": "data",
"override_data": "msg",
"x": 400,
"y": 1160,
"wires": [
[
"c3529a5aae4d759e"
]
]
},
{
"id": "f584c5d4390a2313",
"type": "debug",
"z": "37ac4d80dffc96b7",
"name": "打印调试",
"active": true,
"tosidebar": true,
"console": false,
"tostatus": false,
"complete": "payload",
"targetType": "msg",
"statusVal": "",
"statusType": "auto",
"x": 1100,
"y": 1160,
"wires": []
},
{
"id": "41ef4b78.2e2ab4",
"type": "server",
"name": "Home Assistant",
"version": 4,
"addon": true,
"rejectUnauthorizedCerts": true,
"ha_boolean": "y|yes|true|on|home|open",
"connectionDelay": true,
"cacheJson": true,
"heartbeat": false,
"heartbeatInterval": "30",
"areaSelector": "friendlyName",
"deviceSelector": "friendlyName",
"entitySelector": "friendlyName",
"statusSeparator": "at: ",
"statusYear": "hidden",
"statusMonth": "short",
"statusDay": "numeric",
"statusHourCycle": "h23",
"statusTimeFormat": "h:m"
}
]
3.3 播报多个变量文本
json配置如下,修改对应报错和设备就可实现
[
{
"id": "62542dc6e8a50764",
"type": "api-call-service",
"z": "37ac4d80dffc96b7",
"name": "小爱播放",
"server": "41ef4b78.2e2ab4",
"version": 5,
"debugenabled": false,
"domain": "xiaomi_miot",
"service": "intelligent_speaker",
"areaId": [],
"deviceId": [],
"entityId": [
"sensor.xiaomi_lx04_5e02_conversation"
],
"data": "",
"dataType": "jsonata",
"mergeContext": "",
"mustacheAltTags": false,
"outputProperties": [],
"queue": "none",
"x": 720,
"y": 1380,
"wires": [
[
"77fb2fe16ca16586"
]
]
},
{
"id": "b985bc2ddf017ebe",
"type": "inject",
"z": "37ac4d80dffc96b7",
"name": "触发器",
"props": [
{
"p": "payload"
},
{
"p": "topic",
"vt": "str"
}
],
"repeat": "",
"crontab": "",
"once": false,
"onceDelay": 0.1,
"topic": "",
"payload": "",
"payloadType": "date",
"x": 210,
"y": 1260,
"wires": [
[
"6b73f75c930708a5"
]
]
},
{
"id": "be49e984903b1270",
"type": "function",
"z": "37ac4d80dffc96b7",
"name": "设计播报文本",
"func": "var msg1={}\nvar msgsend = `你好!我是智慧实验室小助手.\n 今天的温度是${msg.bgqwd}摄氏度,湿度是百分之${msg.bgqsd},请大家注意添衣保暖!在此非常感谢评委们耐心的观看,祝您合家欢乐,身体健康,万事如意!本次智慧实验室系统汇报到此结束。`\nmsg1.payload = { \"data\": { \"text\": msgsend}}\nreturn msg1;",
"outputs": 1,
"noerr": 0,
"initialize": "",
"finalize": "",
"libs": [],
"x": 420,
"y": 1380,
"wires": [
[
"62542dc6e8a50764"
]
]
},
{
"id": "6b73f75c930708a5",
"type": "api-current-state",
"z": "37ac4d80dffc96b7",
"name": "获取办公区温度",
"server": "41ef4b78.2e2ab4",
"version": 3,
"outputs": 1,
"halt_if": "",
"halt_if_type": "str",
"halt_if_compare": "is",
"entity_id": "sensor.office_area_temperature1",
"state_type": "str",
"blockInputOverrides": false,
"outputProperties": [
{
"property": "payload",
"propertyType": "msg",
"value": "",
"valueType": "entityState"
},
{
"property": "data",
"propertyType": "msg",
"value": "",
"valueType": "entity"
}
],
"for": "0",
"forType": "num",
"forUnits": "minutes",
"override_topic": false,
"state_location": "payload",
"override_payload": "msg",
"entity_location": "data",
"override_data": "msg",
"x": 400,
"y": 1260,
"wires": [
[
"c48fdb8762aba80c"
]
]
},
{
"id": "77fb2fe16ca16586",
"type": "debug",
"z": "37ac4d80dffc96b7",
"name": "打印调试",
"active": true,
"tosidebar": true,
"console": false,
"tostatus": false,
"complete": "payload",
"targetType": "msg",
"statusVal": "",
"statusType": "auto",
"x": 960,
"y": 1380,
"wires": []
},
{
"id": "c48fdb8762aba80c",
"type": "change",
"z": "37ac4d80dffc96b7",
"name": "温度处理",
"rules": [
{
"t": "move",
"p": "payload",
"pt": "msg",
"to": "bgqwd",
"tot": "msg"
}
],
"action": "",
"property": "",
"from": "",
"to": "",
"reg": false,
"x": 600,
"y": 1260,
"wires": [
[
"0d8e5cdeb3056292"
]
]
},
{
"id": "0d8e5cdeb3056292",
"type": "api-current-state",
"z": "37ac4d80dffc96b7",
"name": "获取办公区湿度",
"server": "41ef4b78.2e2ab4",
"version": 3,
"outputs": 1,
"halt_if": "",
"halt_if_type": "str",
"halt_if_compare": "is",
"entity_id": "sensor.office_area_humidity",
"state_type": "str",
"blockInputOverrides": false,
"outputProperties": [
{
"property": "payload",
"propertyType": "msg",
"value": "",
"valueType": "entityState"
},
{
"property": "data",
"propertyType": "msg",
"value": "",
"valueType": "entity"
}
],
"for": "0",
"forType": "num",
"forUnits": "minutes",
"override_topic": false,
"state_location": "payload",
"override_payload": "msg",
"entity_location": "data",
"override_data": "msg",
"x": 800,
"y": 1260,
"wires": [
[
"ed6a36645bbc6634"
]
]
},
{
"id": "ed6a36645bbc6634",
"type": "change",
"z": "37ac4d80dffc96b7",
"name": "湿度处理",
"rules": [
{
"t": "move",
"p": "payload",
"pt": "msg",
"to": "bgqsd",
"tot": "msg"
}
],
"action": "",
"property": "",
"from": "",
"to": "",
"reg": false,
"x": 980,
"y": 1260,
"wires": [
[
"be49e984903b1270"
]
]
},
{
"id": "41ef4b78.2e2ab4",
"type": "server",
"name": "Home Assistant",
"version": 4,
"addon": true,
"rejectUnauthorizedCerts": true,
"ha_boolean": "y|yes|true|on|home|open",
"connectionDelay": true,
"cacheJson": true,
"heartbeat": false,
"heartbeatInterval": "30",
"areaSelector": "friendlyName",
"deviceSelector": "friendlyName",
"entitySelector": "friendlyName",
"statusSeparator": "at: ",
"statusYear": "hidden",
"statusMonth": "short",
"statusDay": "numeric",
"statusHourCycle": "h23",
"statusTimeFormat": "h:m"
}
]
以上都是点击触发,大家可以尝试其他传感器触发。本次分享到此结束,感谢大家的阅读!
参考文献:
小爱同学小度音箱天猫精灵多平台语音对接教程–nodered版本