Skip to content

Instantly share code, notes, and snippets.

@willwhui
Created December 3, 2017 03:19
Show Gist options
  • Save willwhui/425dcb10ddc361a2230dd56c3ea821f3 to your computer and use it in GitHub Desktop.
Save willwhui/425dcb10ddc361a2230dd56c3ea821f3 to your computer and use it in GitHub Desktop.
在hass中接入小米网关
@willwhui
Copy link
Author

使用模板控制网关自带的灯的颜色:

如果想使用颜色名字(比如"red","orange")来控制,其结果是灯的某些实际颜色和预期的颜色有差别。
所以尝试用data_template

data_template:
  rgb_color: > 
    {% if states.sensor.waqi_zhuhai.state | int >=  51 %}
      [255,0,0]   
    {% else %}
      [128,0,128]
    {% endif %}

结果不能成功:
ERROR (MainThread) [homeassistant.core] Invalid service data for light.turn_on: None for dictionary value @ data['rgb_color']. Got '[128, 0, 128]'
可见其原因是不能正确的将模板中的字符串转换为rgb值
可行的解决方案是:
将模板改为普通的规则,有多少个if就设置多少个规则。
这些规则具有相同的trigger,不同的condition。
如:

- alias: "Light on Air Quality Index: brown"
  hide_entity: true
  trigger:
    - platform: state
      entity_id: input_boolean.aqi_checker 
      to: 'on'
  condition:
    condition: numeric_state
    entity_id: sensor.waqi_zhuhai
    #below: 
    above: 300
  action:
    - service: light.turn_on
      entity_id: !secret xiaomi_gateway_light_id
      data:
        rgb_color: [165,42,42]

- alias: "Light on Air Quality Index: purple"
  hide_entity: true
  trigger:
    - platform: state
      entity_id: input_boolean.aqi_checker 
      to: 'on'
  condition:
    condition: numeric_state
    entity_id: sensor.waqi_zhuhai
    below: 301
    above: 200
  action:
    - service: light.turn_on
      entity_id: !secret xiaomi_gateway_light_id
      data:
        rgb_color: [128,0,128]

@willwhui
Copy link
Author

不能正常接受感应器信息

在hass的设备(树莓派)上不恰当的配置iptables,更改端口转发规则,会导致无法发现感应器,并出现invalide key错误。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment