You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Google Home自动化YAML脚本编辑器温度传感器配置报错求助

解决Google脚本编辑器中温度传感器条件配置错误的问题

问题背景

要实现的自动化逻辑:当阳台WiFi温湿度传感器检测到环境温度超过24℃,且阳台门处于打开状态时,自动关闭空调。

错误配置与提示

编写的温度传感器条件如下:

condition:
    type: device.state.TemperatureControl
    state: temperatureAmbientCelsius
    greaterThan: 24
    device: WiFi Temperature & Humidity Sensor - Balcony

验证时触发错误:
[device.state.TemperatureControl] is an unknown type name. Expected types: [and, or, not, time.between, device.state... (truncated for brevity)]

对比正常配置

使用HumiditySetting配置湿度的类似条件可正常运行:

condition:
    type: device.state.HumiditySetting 
    state: humidityAmbientPercent
    greaterThan: 55
    device: WiFi Temperature & Humidity Sensor - Balcony

文档说明与疑问

官方文档指出:

报告其他trait涵盖数据的传感器应使用该trait,并将其queryOnly*属性设为true。例如温度传感器应使用TemperatureControl trait,将queryOnlyTemperatureControl属性设为true。

但不清楚如何在脚本编辑器的YAML中配置该属性。

解决方案

在温度传感器的条件配置里,需要把queryOnlyTemperatureControl属性添加到attributes字段下,正确的配置示例如下:

condition:
    type: device.state.TemperatureControl
    state: temperatureAmbientCelsius
    greaterThan: 24
    device: WiFi Temperature & Humidity Sensor - Balcony
    attributes:
        queryOnlyTemperatureControl: true

若添加属性后仍报错,需检查设备在Google Home中是否被正确识别为温度传感器,或尝试重新同步设备状态。

结合阳台门状态的完整自动化脚本示例:

automations:
  - name: Close AC when balcony is hot and door is open
    triggers:
      - type: device.state.Door
        state: open
        device: Balcony Door Sensor
      - type: device.state.TemperatureControl
        state: temperatureAmbientCelsius
        greaterThan: 24
        device: WiFi Temperature & Humidity Sensor - Balcony
        attributes:
            queryOnlyTemperatureControl: true
    conditions:
      - type: and
        conditions:
          - type: device.state.Door
            state: open
            device: Balcony Door Sensor
          - type: device.state.TemperatureControl
            state: temperatureAmbientCelsius
            greaterThan: 24
            device: WiFi Temperature & Humidity Sensor - Balcony
            attributes:
                queryOnlyTemperatureControl: true
    actions:
      - type: device.command.TurnOff
        device: Living Room AC

内容的提问来源于stack exchange,提问作者Vasya

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.13 12:15:02