家里书房的射频风扇实际是一个和吊灯一体的吊扇,开关也用博联的TC2控制着,想办法接入HK通过siri控制
实现代码如下,给大家提供参考:
input_booleans.yaml:
# 风扇
shufang_fan:
name: 书房风扇开关
icon: mdi:fan
input_selects.yaml:
# 风扇
shufang_fan_speed:
name: 风速
options:
- 'off'
- '1'
- '2'
- '3'
- '4'
- '5'
- '6'
initial: 'off'
icon: mdi:fan
shufang_fan_osc:
name: 摇头
options:
- true
- false
initial: false
icon: mdi:sync
shufang_fan_direction:
name: 正反向
options:
- forward
- reverse
initial: forward
icon: mdi:swap-horizontal
fans.yaml:
- platform: template
fans:
shufang_fan:
friendly_name: "书房风扇"
value_template: "{{ states('input_boolean.shufang_fan') }}"
speed_template: "{{ states('input_select.shufang_fan_speed') }}"
oscillating_template: "{{ states('input_select.shufang_fan_osc') }}"
direction_template: "{{ states('input_select.shufang_fan_direction') }}"
turn_on:
- service: script.shufang_fan_on
turn_off:
- service: script.shufang_fan_off
set_speed:
- service: script.shufang_fan_speed
data_template:
speed: "{{ speed }}"
set_oscillating:
- service: script.fan_oscillating
data_template:
oscillating: "{{ oscillating }}"
set_direction:
- service: script.fan_direction
data_template:
direction: "{{ direction }}"
speeds:
- 'off'
- '1'
- '2'
- '3'
- '4'
- '5'
- '6'
scripts.ymal:
# 书房风扇
turn_on_study_fan1:
alias: study fan on 1
sequence:
service: broadlink.send
data:
host: XX.XX.XX.XX
packet: 6QAwAQQEBAYQBAYFCAUECAUHBAABJwcQIikJDyMnCicLJgsmDCYMDSQmDCUMJQ0OIw0lJQ0MJiUMJQwlDSQPCyYjDwooCSkIKQmnIwACBARbCgQIBAgUBgQNBQQVFAQGBBIHKQgrIQ8JKCIRIBAiECIQCCgjDwonCycKJwqmJQ0kDyIOIw4LJyMODCYlDCQOJQ4iDiMODCYjDiQOIw4MJgsnIw4MJSQOJA4jDiQNDSYjDgsmDCUMJg2kJA0lDSQNJQwOJSQMDCYkDiQNJQ0kDSQNDCYkDSUOIw4NJAwlJQ0NJSUNJBUcDSUNDCcjDQwmDCYLJQ2lJA0lDCYMJQwMJScMDSMlDSYMJQwmDCUMDCYlDCUOIw0MJgwlJQ0MJyQMJQ0kDSUNDCYmCwwnCiYMJgsABdwAAAAAAAAAAA==
turn_on_study_fan2:
alias: study fan on 2
sequence:
service: broadlink.send
data:
host: XX.XX.XX.XX
packet: 6QAWASoJJwoPIigKDyMnCycKJwsmDCYLDiQlDCYMJQwNJQ0lJgsNJSYMJQ4jDQ0kDCYmDAsmDCYLJiaOJA4jDxwAAgoEZAQoBC4HKiERCCkhESERIBEJKAkoIhAJKAonCigjkCMPIxAhDiQOCyYkDwonIw8jDiMOJA4jDgwmIxAiDiMOCycMJSQOCyckDiMOJA0MJwsmJA0LJgwmDCYkjyQOJA4jDyMNDCcjDQwlJwslDSQNJQ0kDwonJAwlDSQOCyYMJiQNDCYlDSQNJQ0LJgwmJgwLJgwlDCYljiUNJQ4kDCYLDCYlDAwmJQ0kDSUNJA0mDAwlJQ0lDSQNDSQNJSUMDSclCyUNJQwNJA0lJQ4LJQ0lDCcjAAXcAAA=
turn_on_study_fan3:
alias: study fan on 2
sequence:
service: broadlink.send
data:
host: XX.XX.XX.XX
packet: 6QAoAQURBAQEBQQFDwABSB4oCw4iKAwlCycLJgwnCg0kJgwmDCUNDCUNJSUMDCYlDiMNDCYkDgsnIw8KJwsnIxAFqh0AAmkFBAgNBBMHBwQEBRkKCQUEBBQFBCoIKSEQCSkiECEQCSgiEAkoJA4KJwonIw8KpiUNIw4kDiUMCygiDgsnJA4jDiQOIw4lDAwnIw8kDCQOCyYLJyQNCyckDiQNCyYmDA0lJA8LJgslJA4LpSUNJQ0lDCUNDCUlDA0lJQ0kDSYMJQwlDQwlJgwkDSUNDCYNJCUNDCUmDCUNDCUlDQwmJA4LJQwmJQ4MoycLJQwmDCYLDiQlDA0lJQ0kDSUNJA0lDgslJQ4jDSUNDCUMJiUNDCUlDSUNDCYkDA0lJgwMJQwmJQ0LAAXc
turn_on_study_fan4:
alias: study fan on 2
sequence:
service: broadlink.send
data:
host: XX.XX.XX.XX
packet: 6QAUAQQFBAQEFwcpCCkiEAgqIREhEAkoCSgKKCIQCSgKJyMPIpAkDiQPIg4jEAknJA4LJiUNIw4lDSMOJQ0MJSQPIg4lDQsmDCYkDQwmJA4kDgsmDCUMJiQODCUNJCUNJo0lDSQNJQ0kDQwmJA0MJiQOJA0lDSUMJA8KJyQNJQ0kDQwmCyYkDwomJQ0kDQwmDCUMJiUMDSUMJiQNJY4nCyUMJgwlDA4kJQwNJiQNJQwlDSYLJQ0MJSUNJQwlDQ0kDSUlDA0lJQ0mDAwlDCUNJSUOCyUOJCUMJY4mDiMNJQwlDQwmJA0MJSUNJQwlDiQOIw0MJScLJQwlDQwmDCUlDQwmJQwlDQwlDCcLJSUODCQNJSUMJQAF3AAAAAA=
turn_on_study_fan5:
alias: study fan on 2
sequence:
service: broadlink.send
data:
host: XX.XX.XX.XX
packet: 6QAeAQQFBAcEBAQFAAEnBhEhKQkPIigKKAomCycLJgwNJCYMJQwmDA0kDSYlDQslJQ0MJiQNJA8KJyMPCigh9RgAAhAEFQQVBCsgEyARHxIIKQgpIg8JKSIQCiciDyIQCSgjEAgoIw8KJwqoJQ0kDiMPIw4LJiQOCyYlDSQNJA8jDiMPCiYkDiMOJA4LJwsmJA0MJyQNCyYkDSUNDCYkDQwmJA8LJAynJgwlDSQNJQ0MJiQNDCUlDSUMJQ0kDSUOCyUmDCQNJQ0MJgwmJA0LJiUNDCUlDSQNDiQmCw0lJQ0MJQyoJQ0kDSQNJQwNJSUOCiYlDCcLJgsmDCUOCiYlDiMOIw0NJQwlJQ0NJiQMDiUkDCUNDCUlDQwmJA0NJA4ABdwAAAAAAAAAAAAA
turn_on_study_fan6:
alias: study fan on 2
sequence:
service: broadlink.send
data:
host: XX.XX.XX.XX
packet: 6QAUAQABQR4oCg8jJwonDCUMJgwlDQwkJgwlDCYNDSQMJSYMDCYlDAwmJA4jEAkoIhAKJyH2FgACbwsHBhsJBQQGBBYeEwYpCSogEAkqIBEIKSEQIg8KKCIPCigiDwopCagkDiQOIw4kDQsnIw4MJiQOIw4kDyIOJA4LJiQOIw4kDwomCyckDQsnJA4MJSQOJQwLJyQNDSQmDAwlDaclDCUNJA0lDgslJQ0MJSUOJA4kDSMOJA0MJSUOIw0lDQwlDCYlDQwlJQ0MJSUOJA0LJyQNDCUlDQwlDaYlDSUNJA0lDQwmJA0MJSUNJgsmDCUMJQ0MJSUNJA4kDQwlDiQlDA0lJQ4LJSUOJAwNJSYMDSQlDQwlDQAF3AAAAAA=
change_study_fan_direction:
alias: change study fan direction
sequence:
service: broadlink.send
data:
host: XX.XX.XX.XX
packet: 6QAYAQQHBAQECQ4EAAGhICgKJwsnCycKKAoNJSUMJQ0lDA0lDCUlDQwmJQ0LKAkoIg8LJyAAAyAEKgQNBB4KEAQUBSoiECASIBEJKAkoIhEIKCIQCSgKJyMPCickDgonIw8jDgupIw4kDyIOIw4LJiQODCciDiQOJA0lDSQNDCYkDSQOIw4MJgsmJA4MJiQNDSQMJiQOCyYlDQsmJQ0kDQynJQ0lDCUNJQwNJiQMDCYlDSQNJQwlDSUMDCYlDCUNJA4MJQwlJQ0MJiYLDSYMJCUNDiQkDQ4kJQwlDgunJQwnCyUMJQ0NJCcMCyYkDSUNJQwlDCUNDCUlDiQNJQwMJgwmJA0MJyMNDCYMJSUNDSQlDQwmJA0lDA0ABdw=
turn_on_study_fan_osc:
alias: study fan osc
sequence:
service: broadlink.send
data:
host: XX.XX.XX.XX
packet: 6QA8AQcEBAYFBAkHBAUECQQHBAQQBAgLBAQICAQQBgQLCgUECQQIBgABXh4pCQ8jJwsnCyYLJwslDA0lJQwmDCUNDCUNJiUNCigkDQwkDCcMJQwlJA8KJyMPGgAC7QQvBSoIBA0EBhIfEg0EDxMIKQgpIREIKiEQCicKKAkoCicjDwooIw4jDiONJA4kDiMOJA0LJyQNDSUkDiMPIw4jDiQOCyYkDyIOJA4LJgsmJA4LJyQOCyYLJgwnCycjDQwlJQ0kDSWMJQ4jDSUNJA0MJiQNDSUkDSYMJA0lDSQNDCcjDSUOJA0LJgwmJA0MJiUNCyYOJgolDCYlDAwlJQ0lDSSNJA4kDCYMJQ0MJSUMDSUlDSQNJQwlDSUNDSQlDSQNJQ0MJQ0lJQwMKCMOCyUMJgwlDCckDA0lJQ0kDiQABdwAAAAAAAAAAAAAAAA=
turn_off_study_fan:
alias: study fan off
sequence:
service: broadlink.send
data:
host: XX.XX.XX.XX
packet: 6QAwATMEBwQIBAQqBTwECwUAAU0EBA4pCRAjJwknCycLJgsmDA0lJQwmDCYNDCQNJSUMDCckDiMPCicKKCMQCCsEAAFGBAQE8QQQIQQtEQQFGh8SIRAgESARCCogESERIRAJKQgoIxAKJyIQIg8KJwooJA8JJwonDCYjDiSPJA4lDSMOJA4LJiUNCyYkDyQNIw4kDiMPCyUlDSQOIw8LJgsmJA4LJyQNJQ0MJQwmJA4LJgwmDCUlDSSPJQ0kDSUNJA0MJiUMDCYlDCUNJQ0mCyUNDCUlDSQNJQ0MJQ0lJQ0MJSUNJQ0MJgwlJQ0MJQwmDCUmDCSPJQ0lDCUNJQwMJyQNDCYkDSQNJQwlDSUNDCUlDiMPIw0MJgwlJQwNJyQNJA4LJQ0lJQwNJQ4jDiQlDiUABdwAAAAAAAAAAA==
shufang_fan_on:
alias: shufang fan on
sequence:
- service: light.turn_on
data:
entity_id: light.shufang
- service: input_boolean.turn_on
data:
entity_id: input_boolean.shufang_fan
- service: script.shufang_fan_speed
data_template:
speed: "{{ states('input_select.shufang_fan_speed') }}"
shufang_fan_off:
alias: shufang fan off
sequence:
- service: script.turn_off_study_fan
- service: input_boolean.turn_off
data:
entity_id: input_boolean.shufang_fan
shufang_fan_speed:
alias: shufang fan speed
sequence:
- service_template: >
{% if speed == '1' %}
script.turn_on_study_fan1
{% elif speed == '2' %}
script.turn_on_study_fan2
{% elif speed == '3' %}
script.turn_on_study_fan3
{% elif speed == '4' %}
script.turn_on_study_fan4
{% elif speed == '5' %}
script.turn_on_study_fan5
{% elif speed == '6' %}
script.turn_on_study_fan6
{% else %}
script.turn_off_study_fan
{% endif %}
- service: input_select.select_option
data_template:
entity_id: input_select.shufang_fan_speed
option: "{{ speed }}"
fan_oscillating:
alias: shufang fan osc
sequence:
- service_template: >
{% if oscillating == 'True' and
is_state( 'input_boolean.shufang_fan','on' ) %}
script.turn_on_study_fan_osc
{% else %}
script.shufang_fan_speed
{% endif %}
data_template:
speed: "{{ states('input_select.shufang_fan_speed') }}"
- service: input_select.select_option
data_template:
entity_id: input_select.shufang_fan_osc
option: >
{% if oscillating == 'True' and
is_state( 'input_boolean.shufang_fan','on' ) and
is_state( 'input_select.shufang_fan_osc', 'True' ) %}
False
{% elif oscillating == 'True' and
is_state( 'input_boolean.shufang_fan','on' ) and
is_state( 'input_select.shufang_fan_osc', 'False' ) %}
True
{% else %}
script.shufang_fan_speed
{% endif %}
fan_direction:
alias: change fan direction
sequence:
- service_template: >
{% if direction == 'reverse' and
is_state( 'input_boolean.shufang_fan','on' ) %}
script.change_study_fan_direction
{% else %}
script.shufang_fan_speed
{% endif %}
data_template:
speed: "{{ states('input_select.shufang_fan_speed') }}"
- service: input_select.select_option
data_template:
entity_id: input_select.shufang_fan_direction
option: >
{% if direction == 'reverse' and
is_state( 'input_boolean.shufang_fan','on' ) and
is_state( 'input_select.shufang_fan_direction', 'reverse' ) %}
forward
{% elif direction == 'reverse' and
is_state( 'input_boolean.shufang_fan','on' ) and
is_state( 'input_select.shufang_fan_direction', 'forward' ) %}
reverse
{% else %}
script.shufang_fan_speed
{% endif %}
效果图:
|