Skip to content

Instantly share code, notes, and snippets.

@xangin
Last active June 10, 2023 14:07
Show Gist options
  • Save xangin/c09e5ddf212fb00e67f6b88c3fb0c06c to your computer and use it in GitHub Desktop.
Save xangin/c09e5ddf212fb00e67f6b88c3fb0c06c to your computer and use it in GitHub Desktop.
無線開關控制智慧風扇
blueprint:
name: 無線開關控制智慧風扇
description: 可利用任何無線開關來控制智慧風扇的開關/擺頭/風速增減,按鈕會產生何種action請參考無線開關在Z2M的說明
domain: automation
input:
fan_entity:
name: 風扇實體
selector:
entity:
domain: fan
remote_entity:
name: 無線開關實體
description: "請選擇sensor.xxxx_action"
selector:
entity:
domain: sensor
power_onoff_select:
name: 開關
description: (必填)請輸入要用來控制的按鈕action為何?(如button_1_single、single...等)
selector:
text:
oscillate_select:
name: 擺頭
description: (選填)請輸入要用來控制的按鈕action為何?(如button_1_single、single...等)
default: []
selector:
text:
speed_up_select:
name: 風速增強
description: (選填)請輸入要用來控制的按鈕action為何?(如button_1_single、single...等)
default: []
selector:
text:
speed_down_select:
name: 風速減弱
description: (選填)請輸入要用來控制的按鈕action為何?(如button_1_single、single...等)
default: []
selector:
text:
fan_speed_step_percent:
name: 每次風速增減百分比
description: 當按下一次風速增減時,是增加或減少多少百分比
default: 10
selector:
number:
min: 1.0
max: 50.0
unit_of_measurement: '%'
step: 1.0
mode: slider
mode: single
max_exceeded: silent
trigger:
- platform: state
entity_id: !input 'remote_entity'
to: !input 'power_onoff_select'
- platform: state
entity_id: !input 'remote_entity'
to: !input 'oscillate_select'
- platform: state
entity_id: !input 'remote_entity'
to: !input 'speed_up_select'
- platform: state
entity_id: !input 'remote_entity'
to: !input 'speed_down_select'
variables:
oscillate_select_entity: !input 'oscillate_select'
speed_up_select_entity: !input 'speed_up_select'
speed_down_select_entity: !input 'speed_down_select'
power_onoff_select_entity: !input 'power_onoff_select'
action:
- choose:
- alias: "Fan power on/off by center button"
conditions: "{{ trigger.to_state.state == power_onoff_select_entity }}"
sequence:
- entity_id: !input 'fan_entity'
service: fan.toggle
- alias: "Fan oscillate on/off by brightness up button"
conditions: "{{ trigger.to_state.state == oscillate_select_entity }}"
sequence:
- choose:
- conditions:
- or:
- condition: state
entity_id: !input 'fan_entity'
attribute: oscillate
state: false
- condition: state
entity_id: !input 'fan_entity'
attribute: oscillating
state: false
sequence:
- service: fan.oscillate
data:
oscillating: true
target:
entity_id: !input 'fan_entity'
- conditions:
- or:
- condition: state
entity_id: !input 'fan_entity'
attribute: oscillate
state: true
- condition: state
entity_id: !input 'fan_entity'
attribute: oscillating
state: true
sequence:
- service: fan.oscillate
data:
oscillating: false
target:
entity_id: !input 'fan_entity'
- alias: "Fan decrease speed by arrow left button"
conditions: "{{ trigger.to_state.state == speed_down_select_entity }}"
sequence:
- service: fan.decrease_speed
data:
percentage_step: !input 'fan_speed_step_percent'
target:
entity_id: !input 'fan_entity'
- alias: "Fan increase speed by arrow right button"
conditions: "{{ trigger.to_state.state == speed_up_select_entity }}"
sequence:
- choose:
- conditions:
- condition: state
entity_id: !input 'fan_entity'
state: 'off'
sequence:
- service: fan.turn_on
target:
entity_id: !input 'fan_entity'
default:
- service: fan.increase_speed
data:
percentage_step: !input 'fan_speed_step_percent'
target:
entity_id: !input 'fan_entity'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment