『瀚思彼岸』» 智能家居技术论坛

 找回密码
 立即注册
查看: 3952|回复: 6

[经验分享] 射频风扇接入HA&HomeKit

[复制链接]

106

主题

551

帖子

2789

积分

金牌会员

Rank: 6Rank: 6

积分
2789
金钱
2238
HASS币
20
发表于 2020-3-29 23:35:14 | 显示全部楼层 |阅读模式

家里书房的射频风扇实际是一个和吊灯一体的吊扇,开关也用博联的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 %}
效果图:
微信图片_20200329233439.png

评分

参与人数 1金钱 +7 收起 理由
wormshow + 7 感谢楼主分享!

查看全部评分

回复

使用道具 举报

8

主题

264

帖子

2409

积分

金牌会员

Rank: 6Rank: 6

积分
2409
金钱
2145
HASS币
15
发表于 2020-3-31 09:58:12 | 显示全部楼层
好厲害,看起來好複雜, 買了sonoff rf bridge,還不知道能不能把日本買的吸頂燈也整合進HA
回复

使用道具 举报

6

主题

352

帖子

1333

积分

金牌会员

Rank: 6Rank: 6

积分
1333
金钱
981
HASS币
0
发表于 2020-4-1 15:47:50 | 显示全部楼层
谢谢分享,向楼主学习
回复

使用道具 举报

0

主题

13

帖子

176

积分

注册会员

Rank: 2

积分
176
金钱
163
HASS币
0
发表于 2020-10-27 17:53:53 | 显示全部楼层
sonoff rf bridge 有没有控制上限?打算一个控制器控制多把风扇
回复

使用道具 举报

2

主题

51

帖子

512

积分

高级会员

Rank: 4

积分
512
金钱
461
HASS币
0
发表于 2021-9-18 15:31:46 | 显示全部楼层
大佬,貌似更新代码失效了
回复

使用道具 举报

10

主题

163

帖子

1179

积分

金牌会员

Rank: 6Rank: 6

积分
1179
金钱
1016
HASS币
0
发表于 2022-6-6 23:25:24 | 显示全部楼层
收藏学习了
回复

使用道具 举报

3

主题

42

帖子

938

积分

高级会员

Rank: 4

积分
938
金钱
896
HASS币
0
发表于 2022-6-7 07:41:02 | 显示全部楼层
厉害厉害,向楼主学习

论坛助手,iPhone
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

Archiver|手机版|小黑屋|Hassbian

GMT+8, 2024-11-28 18:54 , Processed in 0.080262 second(s), 32 queries .

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表