如題
設備需求:BroadLink RM (型號依需求自選)即能判別電源功率的插座(如Sonoff S31)
Step 1. 黑豆加入HA 及學碼
Step 2. 安裝風扇速度控制的python script , 風扇控速的python script有很多 , 我個人使用的是群內大神寫的 , 請參考 GitHub - yiskang/homeassistant-remote-fan-speed-control: A python script for Home Assistant that control fan speed with Fan Template and Broadlink. 去安裝
Step 3. 編寫風扇控制yaml , 這部分放在configuation.yaml , 熟手了可以切到 packages裡,沒用到的功能請自行註解#掉
yaml如下:
switch:
- platform: broadlink
mac: xx:xx:xx:xx:xx:xx
switches:
- name: fan
command_on: JgBYAAABIJQROBITERMSOBEUERMSEx=
command_off: JgBYAAABIJQROBITERMSO==
#擺頭
- name: Fan Oscillate
command_on: JgCCACgOKQ8NKSkPKQ8OKA4ADQUASDA=
command_off: JgCCACgOKQ8NKSkPKQ8DSkOKA4ADQU=
#省電模式
- name: Fan ECO
command_on: JgBYAAABIZMSOBETEhMSNxQREhMSEIADQU
command_off: JgBYAAABIZMSOBETEhMSNxQREhMSExETEhADQU
- name: Fan Mode
command_on: JgBoACkOKQ8NKSkPKQ8NKQ0pDSk
command_off: JgBoACkOKQ8NKSkPKQ8NKQ
- name: Time to close
command_on: JgBoACcPKQ8MKikOKg4NKQ4oDigqDg4oDikNAAU4
command_off: JgBoACcPKQ8MKikOKg4NKQ4oD
- name: Time To Open
command_on: JgBoACkOKQ4NKSkPK
command_off: JgBoACkOKQ4NKSkPKQ8MKikPDCo
- name: New Sampo Fan Speed Up
command_on: JgBIAAABIpMSNxITEhMROBI==
command_off: JgBIAAABIpMSNxITEhMROBI==
- name: New Sampo Fan Speed Down
command_on: JgBIAAABIpMTNxETEhMTNhI==
command_off: JgBIAAABIpMTNxETEhMTNhI==
- platform: template
switches:
newsampo_power:
friendly_name: "New Sampo Power"
value_template: "{{ states('sensor.plug_energy_power')|float > 2 }}"
turn_on:
service: switch.turn_on
target:
entity_id: switch.new_sampo_fan_power
turn_off:
service: switch.turn_off
target:
entity_id: switch.new_sampo_fan_power
- platform: template
switches:
new_sampo_fan_power:
friendly_name: "New Sampo DC Fan Power"
value_template: "{{ states('sensor.plug_energy_power')|float > 2 }}"
turn_on:
service: script.turn_on
data:
entity_id: script.new_sampo_fan_power
turn_off:
service: script.turn_on
data:
entity_id: script.new_sampo_fan_power
script:
new_sampo_fan_power:
sequence:
- service: input_text.set_value
data_template:
entity_id: input_text.status_new_sampo_fan_speed
value: '{{4/7 * 100 | int}}'
- service: remote.send_command
data:
entity_id: remote.zhi_neng_yao_kong_remote
command: b64:JgBYAAABIJQROBITERMSOBEUERMSExITERMSOBE4EhMROBI3EjgROBI3EjgRFBETEhMSExETEhMSExITETgSNxI4ETgSNxI4EQADowABJkoSAArvAAEkShIADQU==
input_text:
status_new_sampo_fan_speed:
name: 'New Sampo Speed'
initial: 4 # //!<<< Adjust this value if your actual fan speed is not zero. Formula: round( current_speed / speed_count * 100 );
input_select:
fan_osc:
name: 'Fan osc'
options:
- 'True'
- 'False'
fan:
- platform: template
fans:
new_sampo_fan:
friendly_name: "New Sampo DC Fan"
speed_count: 7
value_template: "{{ states('switch.new_sampo_fan_power') }}"
percentage_template: "{{ states('input_text.status_new_sampo_fan_speed') | int }}"
oscillating_template: "{{ states('input_select.fan_osc') }}"
turn_on:
- condition: state
entity_id: switch.new_sampo_fan_power
state: 'off'
- service: switch.turn_on
entity_id: switch.new_sampo_fan_power
turn_off:
- condition: state
entity_id: switch.new_sampo_fan_power
state: 'on'
- service: switch.turn_off
entity_id: switch.new_sampo_fan_power
set_percentage:
- service: python_script.remote_fan_speed_control
data_template:
percentage: "{{ percentage }}"
entity_id: fan.new_sampo_fan
speed_entity_id: input_text.status_new_sampo_fan_speed
speed_count: 7
service: remote.send_command
service_data_decrease:
entity_id: remote.zhi_neng_yao_kong_remote
command: b64:JgBIAAABIpMTNxETEhMTNhITEhMSExETEhMSNxM3ERQROBI3EjcSOBE4EzcROBEUETgSExISEhMSExITEhISOBETEjgROBI3EgANBQ==
service_data_increase:
entity_id: remote.zhi_neng_yao_kong_remote
command: b64:JgBIAAABIpMSNxITEhMROBITERQRExITEhMROBI3ExISNxI4EjcTNhM3ETgSOBISEhMSExETEhMSExEUEhMROBI3EjcTNxE4EgANBQ==
set_oscillating:
- condition: state
entity_id: switch.chimei_dc_fan_power
state: 'on'
- service: remote.send_command
data:
entity_id: remote.fang_jian_rm4c_mini_remote
command: b64:JgCCACgOKQ8NKSkPKQ8MKg0pKQ8NKQ0pDSkNAAU5KQ8pDg0qKQ4pDw0pDigpDw0pDSkOKQ0ABTkpDikPDCopDykODikMKikODSoMKgwqDQAFOSkOKg4NKSkPKQ8MKg0pKQ8MKg0pDSkOAAU4KQ8pDg0pKg4pDw0pDigpDwwqDSkOKA4ADQU=
- service: input_select.select_next
entity_id: input_select.fan_osc
sensor:
- platform: template
sensors:
fan_speed:
friendly_name: "電風扇風速"
value_template: >-
{% set consumption = states('sensor.plug_energy_power')|float %}
{% if consumption == 0 %}
off
{% elif 2.8 <= consumption <= 3.2 %}
Speed 1
{% elif 3.8 <= consumption <= 4.2 %}
Speed 2
{% elif 4.8 <= consumption <= 5.2 %}
Speed 3
{% elif 9 <= consumption <= 11 %}
Speed 4
{% elif 14 <= consumption <= 16.1 %}
Speed 5
{% elif 16.7 <= consumption <= 18.2 %}
Speed 6
{% elif 19 <= consumption <= 24 %}
Speed 7
{% else %}
ShutDown
{% endif %}
STEP 4. 編寫完yaml後 , 請重啟home assistant ,會產生電風扇的實體,再來就是dashboard的部分
type: entities
entities:
- type: section
- entity: fan.new_sampo_fan
state_color: true
name: 聲寶DC電風扇
- entity: fan.new_sampo_fan
type: custom:multiple-entity-row
name: 風扇控制
state_header: 狀態
icon: mdi:fan
toggle: true
state_color: true
entities:
- entity: sensor.fan_speed
name: 風速
- entity: switch.new_sampo_fan_speed_up
name: UP
icon: mdi:fan-plus
toggle: true
tap_action:
action: toggle
- entity: switch.new_sampo_fan_speed_down
name: Down
icon: mdi:fan-minus
toggle: true
tap_action:
action: toggle
- entity: switch.plug
type: custom:multiple-entity-row
name: 風扇狀態
state_header: 電源
styles:
width: 30px
toggle: true
state_color: true
entities:
- entity: sensor.plug_energy_voltage
name: 電壓
styles:
width: 30px
- entity: sensor.plug_energy_current
name: 電流
styles:
width: 30px
- entity: sensor.plug_energy_power
name: 功率
styles:
width: 30px
show_header_toggle: false
title: 客廳聲寶風扇
state_color: true
這樣就完成了 , 以上為本次分享 , 有需要的人請自行取用及修改
2023.10.29增加風速段位判斷