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

 找回密码
 立即注册
查看: 7450|回复: 5

[技术探讨] Yeelight蓝牙调光开关自动化应用分享

[复制链接]

3

主题

68

帖子

723

积分

高级会员

Rank: 4

积分
723
金钱
655
HASS币
0
发表于 2021-6-18 17:47:12 | 显示全部楼层 |阅读模式
本帖最后由 jgx2003 于 2021-6-18 18:01 编辑

Yeelight的蓝牙调光开关接入也有段时间了,最近趁着618自己也撸了2个,奈何家里没有可以控制的灯,所以就想着通过HA的自动化搞点事情,正好家里的买的小米风扇1X因为太便宜了,雷布斯配不起遥控器了,这样一来对于老人和孩子不够友好,所以就计划着用调光开关来遥控风扇。
可惜自己对HA的自动化不太了解,参考论坛和官网,一顿东拼西凑,最后功能是实现了,但是不太优美,所以分享出来,第一是为了给有需要的HA友借鉴,第二也是希望大佬能出来帮着优化优化。
主要实现的功能如下:
1、  单击打开/关闭风扇
2、  长按打开/关闭摇头
3、  右转调高风速
4、  左转调低风速
5、  长按并右转增大摇头角度
6、  长按并左转减小摇头角度
部分代码如下(有些可以直接用网页端的自动化直接创建):
alias: 单击旋钮打开风扇
description: ''
trigger:
  - platform: state
    entity_id: sensor.ble_dimmer_f82********
    attribute: last packet id
condition:
  - condition: and
    conditions:
      - condition: state
        entity_id: sensor.ble_dimmer_f82*******
        attribute: last type of press
        state: short press
action:
  - service: fan.toggle
    entity_id: fan.xiaomi_smart_fan
mode: single
alias: '右旋转调高转速 '
description: ''
trigger:
  - platform: state
    entity_id: sensor.ble_dimmer_f82********
    attribute: last packet id
condition:
  - condition: and
    conditions:
      - condition: state
        entity_id: sensor.ble_dimmer_f82******
        attribute: last type of press
        state: rotate right
action:
  - service: fan.set_percentage
    data_template:
      entity_id: fan.xiaomi_smart_fan
      percentage: '{{states.fan.xiaomi_smart_fan.attributes.percentage +5}}'
mode: single
alias: '按压左旋转减小风扇摆角 '
description: ''
trigger:
  - platform: state
    entity_id: sensor.ble_dimmer_f82*******
    attribute: last packet id
condition:
  - condition: and
    conditions:
      - condition: state
        entity_id: sensor.ble_dimmer_f82*******
        attribute: last type of press
        state: rotate left (pressed)
action:
  - service: xiaomi_miio_fan.fan_set_oscillation_angle
    data_template:
      entity_id: fan.xiaomi_smart_fan
      angle: '{{((states.fan.xiaomi_smart_fan.attributes.angle)/30) |round*30 - 30}}'
mode: single
PS:按压旋转减小摇头角度的时候有个问题需要注意一下,因为小米风扇的摇头角度为30、60、90、120、140,自动化给参数的时候只能用这几个数值,其它数值都可以通过+/-30得到,但是140需要特别注意,当风扇默认是140时,如果直接减去30得到110,这时候因为角度参数不对,服务是无法被调用的,所以才有了上面的公式:{{((states.fan.xiaomi_smart_fan.attributes.angle)/30) |round*30 -30}}

回复

使用道具 举报

20

主题

219

帖子

2179

积分

金牌会员

Rank: 6Rank: 6

积分
2179
金钱
1945
HASS币
87
发表于 2021-6-18 18:12:26 | 显示全部楼层
感谢楼主分享
回复

使用道具 举报

33

主题

2064

帖子

5400

积分

论坛元老

Rank: 8Rank: 8

积分
5400
金钱
3336
HASS币
60
QQ
发表于 2021-6-18 21:29:39 | 显示全部楼层
谢谢分享。
我不生产技术,我只是技术的搬运工。
回复

使用道具 举报

11

主题

313

帖子

1324

积分

金牌会员

Rank: 6Rank: 6

积分
1324
金钱
1011
HASS币
10
发表于 2021-6-18 23:52:29 | 显示全部楼层
多少钱入的啊
回复

使用道具 举报

0

主题

54

帖子

345

积分

中级会员

Rank: 3Rank: 3

积分
345
金钱
291
HASS币
0
发表于 2021-10-31 08:56:22 | 显示全部楼层
大佬,请问怎么判断点击次数呢?
回复

使用道具 举报

9

主题

86

帖子

698

积分

高级会员

Rank: 4

积分
698
金钱
612
HASS币
0
发表于 2022-4-5 16:32:28 | 显示全部楼层
请问下楼主是怎么接入ha的。
回复

使用道具 举报

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

本版积分规则

Archiver|手机版|小黑屋|Hassbian

GMT+8, 2024-6-16 01:56 , Processed in 4.005034 second(s), 28 queries .

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

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