智能家居 AOG。将设备状态与 firestore 字段集成的最佳方式(2021 年)
Smarthome AOG. The best way (in 2021) to integrate state of devices with firestore fields
-
google-cloud-platform
-
google-cloud-functions
-
actions-on-google
-
google-smart-home
-
google-cloud-firestore
我有这个项目:https://github.com/neuberfran/firebasefunction/blob/main/firebase/functions/smart-home/fulfillment.js
它运作良好。但是,例如,我想实现一个条件,如果我关闭了车库并且我说“关闭车库”,Home assistantt 会提醒我。
如下图所示,我正在使用 rpi3/iot-device/back-end 来控制 garagestate 字段。
我需要知道实现此条件的最佳方法,即读取 garagestate 字段的值,并从中知道我是否可以打开车库:
您可能需要根据 Firestore 状态在 onExecute
到 return an error 中添加一个中间条件:
// ...
for (const target of command.devices) {
const configRef = firestore.doc(`device-configs/${target.id}`)
const targetDoc = await configRef.get()
const {garagestate} = targetDoc.data()
if (garagestate === false) {
// garagestate exists and is false
// return an error
return {
requestId,
payload: {
status: 'ERROR',
errorCode: 'alreadyClosed'
}
}
}
// ...
}
// ...
google-cloud-platform
google-cloud-functions
actions-on-google
google-smart-home
google-cloud-firestore
我有这个项目:https://github.com/neuberfran/firebasefunction/blob/main/firebase/functions/smart-home/fulfillment.js 它运作良好。但是,例如,我想实现一个条件,如果我关闭了车库并且我说“关闭车库”,Home assistantt 会提醒我。
如下图所示,我正在使用 rpi3/iot-device/back-end 来控制 garagestate 字段。 我需要知道实现此条件的最佳方法,即读取 garagestate 字段的值,并从中知道我是否可以打开车库:
您可能需要根据 Firestore 状态在 onExecute
到 return an error 中添加一个中间条件:
// ...
for (const target of command.devices) {
const configRef = firestore.doc(`device-configs/${target.id}`)
const targetDoc = await configRef.get()
const {garagestate} = targetDoc.data()
if (garagestate === false) {
// garagestate exists and is false
// return an error
return {
requestId,
payload: {
status: 'ERROR',
errorCode: 'alreadyClosed'
}
}
}
// ...
}
// ...