本帖最后由 guxingtianya 于 2025-1-12 22:41 编辑
HA版本: Core 2024.12.5,OS14.1,TC1刷了大神的固件,大神固件详见https://github.com/a2633063/zTC1
1.用大神的app可通过mqtt连接HA,也已编辑configuration.yaml文件,添加以下文字:homeassistant:
packages: !include_dir_named packages
2.packages文件夹下创建yaml文件,yaml检查配置没有错误,但是在MQTT集成中无法发现TC1设备
以下是我的代码,麻烦各位大佬看下有啥问题,yaml检查配置没有错误,MACMAC也替换为我的设备mac了,另外我的mqtt已经有Z2m网关的设备了,是不是不能再加了?
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
- 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
- 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
- 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
- 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
- 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
- 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
sensor.ztc1_power_MACMAC:
friendly_name: zTC1功率
sensor.ztc1_time_MACMAC:
friendly_name: zTC1运行时间
|