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

 找回密码
 立即注册
查看: 35655|回复: 43

[经验分享] TC1_A2接入HA

[复制链接]

6

主题

170

帖子

2220

积分

金牌会员

Rank: 6Rank: 6

积分
2220
金钱
2050
HASS币
20
发表于 2020-3-16 14:04:02 | 显示全部楼层 |阅读模式
本帖最后由 linoul 于 2020-3-27 21:52 编辑

刷写固件,按下面连接的教程刷写,当前有两个固件可以刷,都不完善,只能局域网控制开关,后者在前者的基础上增加了云易连的接入
https://github.com/linlyv/TC1_A2
https://github.com/IoTDevice/phicomm_tc1_a2

监听UDP信息,然后作为MQTT信息发送,HA里再使用MQTT的方法加入插座开关,注意MAC要大写
使用Node red很简单就实现了 以下是导出的流程 3月27日更新 多TC1支持的流 直接使用不用改动
[{"id":"a61aa149.e899","type":"udp out","z":"9c894eb7.3e503","name":"发送UDP指令","addr":"255.255.255.255","iface":"","port":"10182","ipv":"udp4","outport":"","base64":false,"multicast":"false","x":380,"y":60,"wires":[]},{"id":"86d4a70b.3ef518","type":"udp in","z":"9c894eb7.3e503","name":"监听UPD信息","iface":"","port":"10182","ipv":"udp4","multicast":"true","group":"255.255.255.255","datatype":"utf8","x":90,"y":120,"wires":[["246ba146.b6c9ae"]]},{"id":"eeb55119.e08a4","type":"debug","z":"9c894eb7.3e503","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","x":550,"y":180,"wires":[]},{"id":"c0e61dd3.cd01e","type":"mqtt in","z":"9c894eb7.3e503","name":"监控MQTT","topic":"device/ztc1/+/set","qos":"2","datatype":"utf8","broker":"8345ab7e.a3f928","x":100,"y":60,"wires":[["a61aa149.e899"]]},{"id":"14e1cdce.97c5c2","type":"mqtt out","z":"9c894eb7.3e503","name":"发布到MQTT","topic":"","qos":"","retain":"","broker":"8345ab7e.a3f928","x":550,"y":120,"wires":[]},{"id":"246ba146.b6c9ae","type":"json","z":"9c894eb7.3e503","name":"","property":"payload","action":"","pretty":false,"x":250,"y":120,"wires":[["2ef942fb.64b2ee"]]},{"id":"2ef942fb.64b2ee","type":"function","z":"9c894eb7.3e503","name":"转换主题","func":"msg.topic = 'device/ztc1/'+ msg.payload.mac +'/state'\nreturn msg;\n","outputs":1,"noerr":0,"x":380,"y":120,"wires":[["14e1cdce.97c5c2","eeb55119.e08a4"]]},{"id":"8345ab7e.a3f928","type":"mqtt-broker","z":"","name":"hassio","broker":"192.168.2.19","port":"1883","clientid":"","usetls":false,"compatmode":false,"keepalive":"60","cleansession":true,"birthTopic":"","birthQos":"0","birthPayload":"","closeTopic":"","closeQos":"0","closePayload":"","willTopic":"","willQos":"0","willPayload":""}]
HA配置
参考连接  
https://github.com/a2633063/zTC1/wiki/homeassistant%E6%8E%A5%E5%85%A5

switch:
  - platform: mqtt
    name: 'ztc1_1_MACMAC'
    state_topic: 'device/ztc1/MACMAC/state'
    command_topic: 'device/ztc1/MACMAC/set'
    payload_on: '{"mac":"MACMAC","plug_0":{"on":1}}'
    payload_off: '{"mac":"MACMAC","plug_0":{"on":0}}'
    value_template: '{{ value_json.plug_0.on }}'
    state_on: '1'
    state_off: '0'    
  - platform: mqtt
    name: 'ztc1_2_MACMAC'
    state_topic: 'device/ztc1/MACMAC/state'
    command_topic: 'device/ztc1/MACMAC/set'
    payload_on: '{"mac":"MACMAC","plug_1":{"on":1}}'
    payload_off: '{"mac":"MACMAC","plug_1":{"on":0}}'
    value_template: '{{ value_json.plug_1.on }}'
    state_on: '1'
    state_off: '0'
  - platform: mqtt
    name: 'ztc1_3_MACMAC'
    state_topic: 'device/ztc1/MACMAC/state'
    command_topic: 'device/ztc1/MACMAC/set'
    payload_on: '{"mac":"MACMAC","plug_2":{"on":1}}'
    payload_off: '{"mac":"MACMAC","plug_2":{"on":0}}'
    value_template: '{{ value_json.plug_2.on }}'
    state_on: '1'
    state_off: '0'
  - platform: mqtt
    name: 'ztc1_4_MACMAC'
    state_topic: 'device/ztc1/MACMAC/state'
    command_topic: 'device/ztc1/MACMAC/set'
    payload_on: '{"mac":"MACMAC","plug_3":{"on":1}}'
    payload_off: '{"mac":"MACMAC","plug_3":{"on":0}}'
    value_template: '{{ value_json.plug_3.on }}'
    state_on: '1'
    state_off: '0'
  - platform: mqtt
    name: 'ztc1_5_MACMAC'
    state_topic: 'device/ztc1/MACMAC/state'
    command_topic: 'device/ztc1/MACMAC/set'
    payload_on: '{"mac":"MACMAC","plug_4":{"on":1}}'
    payload_off: '{"mac":"MACMAC","plug_4":{"on":0}}'
    value_template: '{{ value_json.plug_4.on }}'
    state_on: '1'
    state_off: '0'
  - platform: mqtt
    name: 'ztc1_6_MACMAC'
    state_topic: 'device/ztc1/MACMAC/state'
    command_topic: 'device/ztc1/MACMAC/set'
    payload_on: '{"mac":"MACMAC","plug_5":{"on":1}}'
    payload_off: '{"mac":"MACMAC","plug_5":{"on":0}}'
    value_template: '{{ value_json.plug_5.on }}'
    state_on: '1'
    state_off: '0'


之后HA就能顺利操作开关了,有个问题就是如果按插座上的实体按钮来开关,貌似不会发送UDP信息,导致HA里设备获取不到状态,不知道有没有解决办法。

回复

使用道具 举报

1

主题

29

帖子

1878

积分

金牌会员

Rank: 6Rank: 6

积分
1878
金钱
1849
HASS币
0
发表于 2020-3-16 15:21:43 | 显示全部楼层
终于有大神出手搞A2了,学习!
回复

使用道具 举报

106

主题

551

帖子

2789

积分

金牌会员

Rank: 6Rank: 6

积分
2789
金钱
2238
HASS币
20
发表于 2020-3-16 15:52:29 | 显示全部楼层
太好了,家里刚好有一个A2躺尸
回复

使用道具 举报

106

主题

551

帖子

2789

积分

金牌会员

Rank: 6Rank: 6

积分
2789
金钱
2238
HASS币
20
发表于 2020-3-16 18:03:15 | 显示全部楼层
git里没有写刷写方法,楼主操作成功了,把操作方法也分享一下呗
回复

使用道具 举报

106

主题

551

帖子

2789

积分

金牌会员

Rank: 6Rank: 6

积分
2789
金钱
2238
HASS币
20
发表于 2020-3-16 18:38:31 | 显示全部楼层
找到了,是我网速太慢
回复

使用道具 举报

0

主题

20

帖子

58

积分

注册会员

Rank: 2

积分
58
金钱
38
HASS币
0
发表于 2020-3-17 11:27:42 | 显示全部楼层
刷好了,但MQTT服务器怎么设置,我是N1上装好MQTT软件emqtt,在ha上连接好emqtt服务
回复

使用道具 举报

1

主题

150

帖子

1649

积分

金牌会员

Rank: 6Rank: 6

积分
1649
金钱
1499
HASS币
0
发表于 2020-3-17 15:45:50 | 显示全部楼层
太好了,家里刚好有一个A2
回复

使用道具 举报

6

主题

170

帖子

2220

积分

金牌会员

Rank: 6Rank: 6

积分
2220
金钱
2050
HASS币
20
 楼主| 发表于 2020-3-17 21:47:23 | 显示全部楼层
eme915 发表于 2020-3-17 11:27
刷好了,但MQTT服务器怎么设置,我是N1上装好MQTT软件emqtt,在ha上连接好emqtt服务 ...

现在的固件设置不了MQTT 是通过node red来把UDP转发成MQTT的,按我贴的设置就可以
回复

使用道具 举报

0

主题

20

帖子

58

积分

注册会员

Rank: 2

积分
58
金钱
38
HASS币
0
发表于 2020-3-18 09:02:42 | 显示全部楼层
linoul 发表于 2020-3-17 21:47
现在的固件设置不了MQTT 是通过node red来把UDP转发成MQTT的,按我贴的设置就可以 ...

好的,我查下node red相关资料
回复

使用道具 举报

0

主题

20

帖子

58

积分

注册会员

Rank: 2

积分
58
金钱
38
HASS币
0
发表于 2020-3-18 09:20:30 | 显示全部楼层
试了下,里面修改了mac,但还是不行,不知道出问题在什么地方 QQ截图20200318091643.png
回复

使用道具 举报

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

本版积分规则

Archiver|手机版|小黑屋|Hassbian

GMT+8, 2024-11-29 04:36 , Processed in 0.145363 second(s), 34 queries .

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

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