本帖最后由 chln 于 2023-12-6 21:01 编辑
# 效果
# 插座盒子tc1介绍及刷固件
## 插座盒子tc1介绍
硬件:
4个USB充电,6个插孔
功能:
按键控制所有插口通断
控制每个接口独立开关
MQTT服务器连接控制
通过mqtt连入homeassistant
实时显示功率,运行时间
## 固件
https://github.com/a2633063/zTC1
https://gitee.com/a2633063/zTC1
需要注意:
请遵循大佬声明
- 注意: 本项目主要目的为作者本人自己学习及使用TC1排插而开发,本着开源精神及造福网友而开源,仅个人开发,可能无法做到完整的测试,所以不承担他人使用本项目照成的所有后果.
- 严禁他人将本项目用户用于任何商业活动.个人在非盈利情况下可以自己使用,严禁收费代刷等任何盈利服务
复制代码 注意硬件为a1版本,烧写请参考github或者gitee中的过程 https://github.com/a2633063/zTC1 ... 6%E7%83%A7%E5%BD%95
# 插座盒子tc1连接ha配置
## tc1连接mqtt
简单介绍:
1.通过手机app配网连接到路由器wifi(强烈建议后续固定ip)
2.在app中输入mqtt的配置,app会通过udp将MQTT配置发给zTC1(上一篇的mqtt中的账户密码ip)
3.需要取作者公众号获取激活码(免费的)
详细介绍参考: https://github.com/a2633063/zTC1 ... B%E4%BD%BF%E7%94%A8
## tc1接入ha
简单介绍:
1.mqtt接入ha(上一篇)
2.新建ztc1的配置文件(ha的package方式)
- ha 配置目录config:(注意修改macmac地址)
- mkdir config/packages
- vim package/ztc1_1_macmac.yaml
- mqtt:
- - switch:
- name: 'ztc1_1_macmac'
- unique_id: 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'
- availability_topic: "device/ztc1/macmac/availability"
- payload_available: 1
- payload_not_available: 0
- - switch:
- name: 'ztc1_2_macmac'
- unique_id: 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'
- availability_topic: "device/ztc1/macmac/availability"
- payload_available: 1
- payload_not_available: 0
- - switch:
- name: 'ztc1_3_macmac'
- unique_id: 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'
- availability_topic: "device/ztc1/macmac/availability"
- payload_available: 1
- payload_not_available: 0
- - switch:
- name: 'ztc1_4_macmac'
- unique_id: 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'
- availability_topic: "device/ztc1/macmac/availability"
- payload_available: 1
- payload_not_available: 0
- - switch:
- name: 'ztc1_5_macmac'
- unique_id: 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'
- availability_topic: "device/ztc1/macmac/availability"
- payload_available: 1
- payload_not_available: 0
- - switch:
- name: 'ztc1_6_macmac'
- unique_id: 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'
- availability_topic: "device/ztc1/macmac/availability"
- payload_available: 1
- payload_not_available: 0
- - sensor:
- name: 'ztc1_power_macmac'
- unique_id: ztc1_power_macmac
- state_topic: 'device/ztc1/macmac/sensor'
- unit_of_measurement: 'W'
- icon: 'mdi:gauge'
- value_template: '{{ value_json.power }}'
- availability_topic: "device/ztc1/macmac/availability"
- payload_available: 1
- payload_not_available: 0
- - sensor:
- name: 'ztc1_time_macmac'
- unique_id: ztc1_time_macmac
- state_topic: 'device/ztc1/macmac/sensor'
- #unit_of_measurement: '秒'
- icon: 'mdi:gauge'
- availability_topic: "device/ztc1/macmac/availability"
- payload_available: 1
- payload_not_available: 0
- #value_template: '{{ value_json.total_time }}'
- value_template: >-
- {% set time = value_json.total_time %}
- {% set minutes = ((time % 3600) / 60) | int %}
- {% set hours = ((time % 86400) / 3600) | int %}
- {% set days = (time / 86400) | int %}
- {%- if time < 60 -%}
- <1分钟
- {%- else -%}
- {%- if days > 0 -%}
- {{ days }}天
- {%- endif -%}
- {%- if hours > 0 -%}
- {{ hours }}小时
- {%- endif -%}
- {%- if minutes > 0 -%}
- {{ minutes }}分钟
- {%- endif -%}
- {%- endif -%}
- homeassistant:
- customize:
- switch.ztc1_1_macmac:
- friendly_name: zTC1插槽1_水台
- switch.ztc1_2_macmac:
- friendly_name: zTC1插槽2_显示器
- switch.ztc1_3_macmac:
- friendly_name: zTC1插槽3_外置插排
- switch.ztc1_4_macmac:
- friendly_name: zTC1插槽4_电视果
- switch.ztc1_5_macmac:
- friendly_name: zTC1插槽5_夜灯
- switch.ztc1_6_macmac:
- friendly_name: zTC1插槽6_ps5
- sensor.ztc1_power_macmac:
- friendly_name: zTC1功率
- sensor.ztc1_time_macmac:
- friendly_name: zTC1运行时间
复制代码- vim config/configuration.yaml
- homeassistant:
- packages: !include_dir_named packages
复制代码
4.重启ha
# 卡片设置
|