本帖最后由 reggie 于 2018-7-27 11:58 编辑
萌新才开始玩ha,在论坛和官网资料痛苦的挣扎,总算把所有设备接入。卧室用的yeelight顶灯和两个小米无线开关,然后有个空调伴侣,这里分享无线开关控制顶灯和空调的代码。
实现的功能
1. 单击开/关 顶灯(普通模式)
2. 双击开灯并且设置成月光模式
3. 长按 开/关 空调
【2018.7.27 代码更新】调整了开灯和设置模式的顺序,之前的代码会在开启月光模式的时候先闪一下,然后把空调的代码改成模板实现,简洁很多
- alias: turn on bed room light normal
trigger:
platform: event
event_type: click
event_data:
entity_id: binary_sensor.switch_158d0001f3fda9_2
click_type: single
condition:
- condition: state
entity_id: light.bedroom
state: 'off'
action:
- service: light.yeelight_set_mode
entity_id: light.bedroom
data:
mode: normal
- service: light.turn_on
entity_id: light.bedroom
- alias: turn on bed room light moonlight
trigger:
platform: event
event_type: click
event_data:
entity_id: binary_sensor.switch_158d0001f3fda9_2
click_type: double
action:
- service: light.yeelight_set_mode
entity_id: light.bedroom
data:
mode: moonlight
- service: light.turn_on
entity_id: light.bedroom
- alias: turn off bed room light
trigger:
platform: event
event_type: click
event_data:
entity_id: binary_sensor.switch_158d0001f3fda9_2
click_type: single
condition:
- condition: state
entity_id: light.bedroom
state: 'on'
action:
service: light.turn_off
entity_id: light.bedroom
- alias: toggle bedroom ac
trigger:
platform: event
event_type: click
event_data:
entity_id: binary_sensor.switch_158d0001f3fda9_2
click_type: long_click_press
action:
service_template: >
{% if is_state('climate.bedroom', 'off') %}
climate.turn_on
{% else %}
climate.turn_off
{% endif %}
entity_id: climate.bedroom
|