有些场景或是开关不适合让别人操作
那就只好设一组自己的密码了
利用小米无线开关的三种操作模式
单击、双击、长按
再加上时间差进行密码的调整
1.configuration加入虚拟开关
input_boolean:
single_click:
name: 單擊無線開關
initial: off
icon: mdi:car
double_click:
name: 雙擊無線開關
initial: off
icon: mdi:car
long_click:
name: 長按無線開關
initial: off
icon: mdi:car
long_click_2:
name: 長按無線開關2
initial: off
icon: mdi:car
看你的密码要几码,就设几个开关
2.automations设定自动化
连动几个按钮模式
- alias: single_click
trigger:
platform: event
event_type: xiaomi_aqara.click
event_data:
entity_id: binary_sensor.switch_06067067
click_type: single
action:
- service: input_boolean.turn_on
entity_id: input_boolean.single_click
- alias: double_click
trigger:
platform: event
event_type: xiaomi_aqara.click
event_data:
entity_id: binary_sensor.switch_06067067
click_type: double
action:
- service: input_boolean.turn_on
entity_id: input_boolean.double_click
- alias: long_click
trigger:
platform: event
event_type: xiaomi_aqara.click
event_data:
entity_id: binary_sensor.switch_06067067
click_type: long_click_press
action:
- service: input_boolean.turn_on
entity_id: input_boolean.long_click
- alias: long_click_2 #当长按的开关是在的时候才会执行,也可以用两次或者双击多几种判断模式
3.利用时间差,决定点击的顺序
- alias: code button auto close_1
trigger:
- platform: state
entity_id: input_boolean.single_click
from: 'off'
to: 'on'
condition: []
action:
- delay:
seconds: 4
- service: input_boolean.turn_off
entity_id: input_boolean.single_click
- alias: code button auto close_2
trigger:
- platform: state
entity_id: input_boolean.double_click
from: 'off'
to: 'on'
condition: []
action:
- delay:
seconds: 2
- service: input_boolean.turn_off
entity_id: input_boolean.double_click
- alias: code button auto close_3
trigger:
- platform: state
entity_id: input_boolean.long_click
from: 'off'
to: 'on'
condition: []
action:
- delay:
seconds: 2
- service: input_boolean.turn_off
entity_id: input_boolean.long_click
- alias: code button auto close_4
trigger:
- platform: state
entity_id: input_boolean.long_click_2
from: 'off'
to: 'on'
condition: []
action:
- delay:
seconds: 1
- service: input_boolean.turn_off
entity_id: input_boolean.long_click_2
秒数越长的越先按:单击->双击->长按->长按
另外因为要利用无线开关的状态
所以长按一定要在最后面(參考下面的場景執行)
4.場景執行
- alias: code_open_secret_mode
trigger:
- platform: state
entity_id: binary_sensor.switch_06067067
from: 'off'
to: 'on'
condition:
condition: and
conditions:
- condition: state
entity_id: input_boolean.single_click
state: 'on'
- condition: state
entity_id: input_boolean.double_click
state: 'on'
- condition: state
entity_id: input_boolean.long_click
state: 'on'
- condition: state
entity_id: input_boolean.long_click_2
state: 'off'
action:
- service: switch.toggle
entity_id: switch.l.5
- service: input_boolean.turn_off
entity_id: input_boolean.single_click
- service: input_boolean.turn_off
entity_id: input_boolean.double_click
- service: input_boolean.turn_off
entity_id: input_boolean.long_click
- service: input_boolean.turn_off
entity_id: input_boolean.long_click_2
设定好之后单击->双击->长按->长按就会执行隐藏的场景了
新学还在摸索
代码写的有些冗长
只能用最简单的逻辑一个一个写
再麻烦版内的高手有空帮忙看看怎么简化
另外乱按也有可能会有开启的情况
不过调整一下时间或是再增加按钮应该多少可以克服
突然想到的东西,和大家分享一下
|