用於Home Assistant的Python腳本,使用Fan Template和Broadlink控制風扇速度。
當你設定風速時,腳本會自動呼叫多次broadlink service
如果你的風速範圍為1~12
範例1: 當你設定風速從1到5時,會呼叫 增加
風速4次
範例2: 當你設定風速從5到2時,會呼叫 減少
風速3次
範例3: 當你設定風速從2到12時,會呼叫 減少
風速2次
在 HomeAssistant 啟用 python_script
- 增加
python_script:
到你的configuration.yaml
- 創建資料夾
<config>/python_scripts
- 重新啟動 HomeAssistant
在HACS的automation分類裡面找到Fan Speed Control
安裝
或是直接複製Python腳本到你的<config>/python_scripts
資料夾裡面
key | required | type | description |
---|---|---|---|
fan_speed | true | string | speed from fan template |
fan_speed_entity_id | true | string | |
fan_entity_id | true | string | |
fan_speed_count | true | integer | |
service_domain | true | string | |
service | true | string | |
service_data_increase | true | object | |
service_data_decrease | true | object |
設定在Fan template的 set_percentage
上
set_percentage:
- service: python_script.fan_speed_control
data_template:
fan_speed: "{{ percentage }}"
fan_speed_entity_id: 'input_number.status_fan_speed'
fan_entity_id: 'fan.bedroom_fan'
fan_speed_count: 12
service_domain: 'remote'
service: 'send_command'
service_data_increase:
entity_id: remote.broadlink
device: fan
command: increase
service_data_decrease:
entity_id: remote.broadlink
device: fan
command: decrease
input_boolean:
status_fan_power:
name: 'Fan Power'
input_number:
status_fan_speed:
name: 'Fan Speed'
max: 0
max: 100
input_select:
fan_osc:
name: 'Fan osc'
options:
- 'True'
- 'False'
fan:
- platform: template
fans:
bedroom_fan:
friendly_name: "myFan"
speed_count: 12
value_template: "{{ states('input_boolean.status_fan_power') }}"
percentage_template: "{{ states('input_number.status_fan_speed') | int }}"
oscillating_template: "{{ states('input_select.fan_osc') }}"
turn_on:
- condition: state
entity_id: input_boolean.status_fan_power
state: 'off'
- service: remote.send_command
data:
entity_id: remote.broadlink
device: fan
command: toggle
- service: input_boolean.turn_on
entity_id: input_boolean.status_fan_power
turn_off:
- condition: state
entity_id: input_boolean.status_fan_power
state: 'on'
- service: remote.send_command
data:
entity_id: remote.broadlink
device: fan
command: toggle
- service: input_boolean.turn_off
entity_id: input_boolean.status_fan_power
set_percentage:
- service: python_script.fan_speed_control
data_template:
fan_speed: "{{ percentage }}"
fan_speed_entity_id: 'input_number.status_fan_speed'
fan_entity_id: 'fan.bedroom_fan'
fan_speed_count: 12
service_domain: 'remote'
service: 'send_command'
service_data_increase:
entity_id: remote.broadlink
device: fan
command: increase
service_data_decrease:
entity_id: remote.broadlink
device: fan
command: decrease
set_oscillating:
- condition: state
entity_id: input_boolean.status_fan_power
state: 'on'
- service: remote.send_command
data:
entity_id: remote.broadlink
device: fan
command: oscillate
- service: input_select.select_next
entity_id: input_select.fan_osc
增加logger到 configuration.yaml
logger:
default: warn
logs:
homeassistant.components.python_script.fan_speed_control.py: debug