ha折腾之插座盒子tc1接入ha

[复制链接]
查看787 | 回复1 | 2023-12-6 21:00:21 | 显示全部楼层 |阅读模式
本帖最后由 chln 于 2023-12-6 21:01 编辑

# 效果
2.png

# 插座盒子tc1介绍及刷固件
## 插座盒子tc1介绍
1.png

硬件:
4个USB充电,6个插孔
功能:
按键控制所有插口通断
控制每个接口独立开关
MQTT服务器连接控制
通过mqtt连入homeassistant
实时显示功率,运行时间
## 固件
https://github.com/a2633063/zTC1
https://gitee.com/a2633063/zTC1
需要注意:
   请遵循大佬声明
  1. 注意: 本项目主要目的为作者本人自己学习及使用TC1排插而开发,本着开源精神及造福网友而开源,仅个人开发,可能无法做到完整的测试,所以不承担他人使用本项目照成的所有后果.
  2. 严禁他人将本项目用户用于任何商业活动.个人在非盈利情况下可以自己使用,严禁收费代刷等任何盈利服务
复制代码
注意硬件为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方式)
  1. ha 配置目录config:(注意修改macmac地址)
  2. mkdir config/packages
  3. vim package/ztc1_1_macmac.yaml
  4. mqtt:
  5.   - switch:
  6.       name: 'ztc1_1_macmac'
  7.       unique_id: ztc1_1_macmac
  8.       state_topic: 'device/ztc1/macmac/state'
  9.       command_topic: 'device/ztc1/macmac/set'
  10.       payload_on: '{"mac":"macmac","plug_0":{"on":1}}'
  11.       payload_off: '{"mac":"macmac","plug_0":{"on":0}}'
  12.       value_template: '{{ value_json.plug_0.on }}'
  13.       state_on: '1'
  14.       state_off: '0'
  15.       availability_topic: "device/ztc1/macmac/availability"
  16.       payload_available: 1
  17.       payload_not_available: 0
  18.   - switch:
  19.       name: 'ztc1_2_macmac'
  20.       unique_id: ztc1_2_macmac
  21.       state_topic: 'device/ztc1/macmac/state'
  22.       command_topic: 'device/ztc1/macmac/set'
  23.       payload_on: '{"mac":"macmac","plug_1":{"on":1}}'
  24.       payload_off: '{"mac":"macmac","plug_1":{"on":0}}'
  25.       value_template: '{{ value_json.plug_1.on }}'
  26.       state_on: '1'
  27.       state_off: '0'
  28.       availability_topic: "device/ztc1/macmac/availability"
  29.       payload_available: 1
  30.       payload_not_available: 0
  31.   - switch:
  32.       name: 'ztc1_3_macmac'
  33.       unique_id: ztc1_3_macmac
  34.       state_topic: 'device/ztc1/macmac/state'
  35.       command_topic: 'device/ztc1/macmac/set'
  36.       payload_on: '{"mac":"macmac","plug_2":{"on":1}}'
  37.       payload_off: '{"mac":"macmac","plug_2":{"on":0}}'
  38.       value_template: '{{ value_json.plug_2.on }}'
  39.       state_on: '1'
  40.       state_off: '0'
  41.       availability_topic: "device/ztc1/macmac/availability"
  42.       payload_available: 1
  43.       payload_not_available: 0
  44.   - switch:
  45.       name: 'ztc1_4_macmac'
  46.       unique_id: ztc1_4_macmac
  47.       state_topic: 'device/ztc1/macmac/state'
  48.       command_topic: 'device/ztc1/macmac/set'
  49.       payload_on: '{"mac":"macmac","plug_3":{"on":1}}'
  50.       payload_off: '{"mac":"macmac","plug_3":{"on":0}}'
  51.       value_template: '{{ value_json.plug_3.on }}'
  52.       state_on: '1'
  53.       state_off: '0'
  54.       availability_topic: "device/ztc1/macmac/availability"
  55.       payload_available: 1
  56.       payload_not_available: 0
  57.   - switch:
  58.       name: 'ztc1_5_macmac'
  59.       unique_id: ztc1_5_macmac
  60.       state_topic: 'device/ztc1/macmac/state'
  61.       command_topic: 'device/ztc1/macmac/set'
  62.       payload_on: '{"mac":"macmac","plug_4":{"on":1}}'
  63.       payload_off: '{"mac":"macmac","plug_4":{"on":0}}'
  64.       value_template: '{{ value_json.plug_4.on }}'
  65.       state_on: '1'
  66.       state_off: '0'
  67.       availability_topic: "device/ztc1/macmac/availability"
  68.       payload_available: 1
  69.       payload_not_available: 0
  70.   - switch:
  71.       name: 'ztc1_6_macmac'
  72.       unique_id: ztc1_6_macmac
  73.       state_topic: 'device/ztc1/macmac/state'
  74.       command_topic: 'device/ztc1/macmac/set'
  75.       payload_on: '{"mac":"macmac","plug_5":{"on":1}}'
  76.       payload_off: '{"mac":"macmac","plug_5":{"on":0}}'
  77.       value_template: '{{ value_json.plug_5.on }}'
  78.       state_on: '1'
  79.       state_off: '0'
  80.       availability_topic: "device/ztc1/macmac/availability"
  81.       payload_available: 1
  82.       payload_not_available: 0
  83.   - sensor:
  84.       name: 'ztc1_power_macmac'
  85.       unique_id: ztc1_power_macmac
  86.       state_topic: 'device/ztc1/macmac/sensor'
  87.       unit_of_measurement: 'W'
  88.       icon: 'mdi:gauge'
  89.       value_template: '{{ value_json.power }}'
  90.       availability_topic: "device/ztc1/macmac/availability"
  91.       payload_available: 1
  92.       payload_not_available: 0
  93.   - sensor:
  94.       name: 'ztc1_time_macmac'
  95.       unique_id: ztc1_time_macmac
  96.       state_topic: 'device/ztc1/macmac/sensor'
  97.       #unit_of_measurement: '秒'
  98.       icon: 'mdi:gauge'
  99.       availability_topic: "device/ztc1/macmac/availability"
  100.       payload_available: 1
  101.       payload_not_available: 0
  102.       #value_template: '{{ value_json.total_time }}'
  103.       value_template: >-
  104.         {% set time = value_json.total_time %}
  105.         {% set minutes = ((time % 3600) / 60) | int %}
  106.         {% set hours = ((time % 86400) / 3600) | int %}
  107.         {% set days = (time / 86400) | int %}
  108.         {%- if time < 60 -%}
  109.           <1分钟
  110.         {%- else -%}
  111.           {%- if days > 0 -%}
  112.               {{ days }}天
  113.           {%- endif -%}
  114.           {%- if hours > 0 -%}
  115.               {{ hours }}小时
  116.           {%- endif -%}
  117.           {%- if minutes > 0 -%}
  118.               {{ minutes }}分钟
  119.           {%- endif -%}
  120.         {%- endif -%}

  121. homeassistant:
  122.   customize:
  123.     switch.ztc1_1_macmac:
  124.       friendly_name: zTC1插槽1_水台
  125.     switch.ztc1_2_macmac:
  126.       friendly_name: zTC1插槽2_显示器
  127.     switch.ztc1_3_macmac:
  128.       friendly_name: zTC1插槽3_外置插排
  129.     switch.ztc1_4_macmac:
  130.       friendly_name: zTC1插槽4_电视果
  131.     switch.ztc1_5_macmac:
  132.       friendly_name: zTC1插槽5_夜灯
  133.     switch.ztc1_6_macmac:
  134.       friendly_name: zTC1插槽6_ps5
  135.     sensor.ztc1_power_macmac:
  136.       friendly_name: zTC1功率
  137.     sensor.ztc1_time_macmac:
  138.       friendly_name: zTC1运行时间

复制代码
  1. vim config/configuration.yaml
  2. homeassistant:
  3.   packages: !include_dir_named packages
复制代码

    4.重启ha

# 卡片设置
3.png


回复

使用道具 举报

1055173307 | 2024-4-9 10:21:52 | 显示全部楼层
学习
回复

使用道具 举报

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

本版积分规则