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

 找回密码
 立即注册
查看: 31166|回复: 81

[进阶教程] Homebridge中将Switch设置为Light,Fan的方法

  [复制链接]

6

主题

737

帖子

5584

积分

论坛元老

Rank: 8Rank: 8

积分
5584
金钱
4842
HASS币
20
发表于 2018-4-16 19:28:29 | 显示全部楼层 |阅读模式
本帖最后由 mitu 于 2018-4-16 19:28 编辑

今天几位大神用porxy和light_template将Homeassistant中的开关改成灯泡形式用于在Homekit中将开关显示为灯泡,其实完全可以修改Homebridge-Homeassistant插件中switch.js文件来实现,只需将原来文件中第154行-165行修改即可:原文件:
    this.service = new Service.Switch();
    if (this.data && this.data.attributes && this.data.attributes.homebridge_switch_type === 'outlet') {
      this.service = new Service.Outlet();
      if (this.data.attributes && this.data.attributes.homebridge_model) {
        model = String(this.data.attributes.homebridge_model);
      } else {
        model = 'Outlet';
      }
      this.service
        .getCharacteristic(Characteristic.OutletInUse)
        .on('get', this.getPowerState.bind(this));
    }
改为:
 this.service = new Service.Switch();
if (this.data && this.data.attributes && (this.data.attributes.homebridge_switch_type === 'lock' || this.data.attributes.homebridge_switch_type === 'fan' || this.data.attributes.homebridge_switch_type === 'outlet' || this.data.attributes.homebridge_switch_type === 'light')) {
if (this.data.attributes.homebridge_switch_type === 'outlet') {
this.service = new Service.Outlet();
model = 'Outlet';
this.service
.getCharacteristic(Characteristic.OutletInUse)
.on('get', this.getPowerState.bind(this));
} else if (this.data.attributes.homebridge_switch_type === 'light') {
this.service = new Service.Lightbulb();
model = 'Light';
} else if (this.data.attributes.homebridge_switch_type === 'fan') {
this.service = new Service.Fan();
model = 'Fan';
} else if (this.data.attributes.homebridge_switch_type === 'lock') {
this.service = new Service.LockMechanism();
model = 'Lock';
}
if (this.data.attributes && this.data.attributes.homebridge_model) {
model = String(this.data.attributes.homebridge_model);
}
}
游客,如果您要查看本帖隐藏内容请回复
修改好的文件可以直接放到原来的位置即可。
我用的是ubuntu,文件路径:/usr/lib/node_modules/homebridge-homeassistant/accessories



回复

使用道具 举报

6

主题

737

帖子

5584

积分

论坛元老

Rank: 8Rank: 8

积分
5584
金钱
4842
HASS币
20
 楼主| 发表于 2018-4-16 19:29:20 | 显示全部楼层
本帖最后由 mitu 于 2018-4-16 19:37 编辑

homebridge_switch_type:可以设置为light,fan,outlet。lock暂时不可用。看效果图,这一屏在HA中全是switch。 IMG_4810.PNG
回复

使用道具 举报

26

主题

176

帖子

726

积分

高级会员

Rank: 4

积分
726
金钱
550
HASS币
0
发表于 2018-4-16 20:55:50 | 显示全部楼层
这难道不就把所有的switch都换成灯了
回复

使用道具 举报

6

主题

737

帖子

5584

积分

论坛元老

Rank: 8Rank: 8

积分
5584
金钱
4842
HASS币
20
 楼主| 发表于 2018-4-16 20:59:57 来自手机 | 显示全部楼层
hdcola 发表于 2018-4-16 20:55
这难道不就把所有的switch都换成灯了

如果不设置homebridge_switch_type,显示就是switch,如果设置homebridge_switch_type为fan,显示就是风扇,设置homebridge_switch_type为light,就显示为灯泡了,homekit里还可以设置灯泡图标。
回复

使用道具 举报

175

主题

2956

帖子

7555

积分

超级版主

我就是六神

Rank: 8Rank: 8

积分
7555
金钱
4574
HASS币
398

活跃会员教程狂人灌水之王

QQ
发表于 2018-4-17 01:12:58 | 显示全部楼层
看看~~~ 学习下,是加了几个类型是吗??
回复

使用道具 举报

175

主题

2956

帖子

7555

积分

超级版主

我就是六神

Rank: 8Rank: 8

积分
7555
金钱
4574
HASS币
398

活跃会员教程狂人灌水之王

QQ
发表于 2018-4-17 01:16:47 | 显示全部楼层
不过你这个不是永久的啊,下次更新又要换~~~
回复

使用道具 举报

16

主题

262

帖子

3709

积分

论坛元老

Rank: 8Rank: 8

积分
3709
金钱
3442
HASS币
0
发表于 2018-4-17 08:10:37 | 显示全部楼层
这个看看,感谢分享
回复

使用道具 举报

14

主题

654

帖子

3826

积分

论坛元老

Rank: 8Rank: 8

积分
3826
金钱
3167
HASS币
10
发表于 2018-4-17 23:27:18 | 显示全部楼层
前来学些……
回复

使用道具 举报

14

主题

654

帖子

3826

积分

论坛元老

Rank: 8Rank: 8

积分
3826
金钱
3167
HASS币
10
发表于 2018-4-17 23:29:25 | 显示全部楼层
非常的厉害了 确实可以有极高效率的执行 只是在显示界面做调整 不参与到ha业务逻辑
回复

使用道具 举报

18

主题

142

帖子

2572

积分

金牌会员

Rank: 6Rank: 6

积分
2572
金钱
2430
HASS币
0

论坛风云人物

发表于 2018-4-18 00:00:38 | 显示全部楼层
我在porxy那边有说过,只是我没有这种需求,所以就没改
回复

使用道具 举报

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

本版积分规则

Archiver|手机版|小黑屋|Hassbian

GMT+8, 2024-4-25 13:23 , Processed in 0.117283 second(s), 36 queries .

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

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