完全可以,不过个人觉得这样不容易拍错。。。。
复制粘贴即可,如果提示编码错误,转成UTF-8
# Configure a default setup of Home Assistant (frontend, api, etc)
default_config:
# Uncomment this if you are using SSL/TLS, running in Docker container, etc.
# http:
# base_url: example.duckdns.org:8123
# Text to speech
tts:
- platform: google_translate
group: !include groups.yaml
automation: !include automations.yaml
script: !include scripts.yaml
scene: !include scenes.yaml
switch:
#tc1A
- platform: mqtt
name: 'ztc1_1_d0bae4632e62'
state_topic: 'device/ztc1/d0bae4632e62/state'
command_topic: 'device/ztc1/d0bae4632e62/set'
payload_on: '{"mac":"d0bae4632e62","plug_0":{"on":1}}'
payload_off: '{"mac":"d0bae4632e62","plug_0":{"on":0}}'
value_template: '{{ value_json.plug_0.on }}'
state_on: '1'
state_off: '0'
- platform: mqtt
name: 'ztc1_2_d0bae4632e62'
state_topic: 'device/ztc1/d0bae4632e62/state'
command_topic: 'device/ztc1/d0bae4632e62/set'
payload_on: '{"mac":"d0bae4632e62","plug_1":{"on":1}}'
payload_off: '{"mac":"d0bae4632e62","plug_1":{"on":0}}'
value_template: '{{ value_json.plug_1.on }}'
state_on: '1'
state_off: '0'
- platform: mqtt
name: 'ztc1_3_d0bae4632e62'
state_topic: 'device/ztc1/d0bae4632e62/state'
command_topic: 'device/ztc1/d0bae4632e62/set'
payload_on: '{"mac":"d0bae4632e62","plug_2":{"on":1}}'
payload_off: '{"mac":"d0bae4632e62","plug_2":{"on":0}}'
value_template: '{{ value_json.plug_2.on }}'
state_on: '1'
state_off: '0'
- platform: mqtt
name: 'ztc1_4_d0bae4632e62'
state_topic: 'device/ztc1/d0bae4632e62/state'
command_topic: 'device/ztc1/d0bae4632e62/set'
payload_on: '{"mac":"d0bae4632e62","plug_3":{"on":1}}'
payload_off: '{"mac":"d0bae4632e62","plug_3":{"on":0}}'
value_template: '{{ value_json.plug_3.on }}'
state_on: '1'
state_off: '0'
- platform: mqtt
name: 'ztc1_5_d0bae4632e62'
state_topic: 'device/ztc1/d0bae4632e62/state'
command_topic: 'device/ztc1/d0bae4632e62/set'
payload_on: '{"mac":"d0bae4632e62","plug_4":{"on":1}}'
payload_off: '{"mac":"d0bae4632e62","plug_4":{"on":0}}'
value_template: '{{ value_json.plug_4.on }}'
state_on: '1'
state_off: '0'
- platform: mqtt
name: 'ztc1_6_d0bae4632e62'
state_topic: 'device/ztc1/d0bae4632e62/state'
command_topic: 'device/ztc1/d0bae4632e62/set'
payload_on: '{"mac":"d0bae4632e62","plug_5":{"on":1}}'
payload_off: '{"mac":"d0bae4632e62","plug_5":{"on":0}}'
value_template: '{{ value_json.plug_5.on }}'
state_on: '1'
state_off: '0'
#tc1B
- platform: mqtt
name: 'ztc1_1_d0bae463b505'
state_topic: 'device/ztc1/d0bae463b505/state'
command_topic: 'device/ztc1/d0bae463b505/set'
payload_on: '{"mac":"d0bae463b505","plug_0":{"on":1}}'
payload_off: '{"mac":"d0bae463b505","plug_0":{"on":0}}'
value_template: '{{ value_json.plug_0.on }}'
state_on: '1'
state_off: '0'
- platform: mqtt
name: 'ztc1_2_d0bae463b505'
state_topic: 'device/ztc1/d0bae463b505/state'
command_topic: 'device/ztc1/d0bae463b505/set'
payload_on: '{"mac":"d0bae463b505","plug_1":{"on":1}}'
payload_off: '{"mac":"d0bae463b505","plug_1":{"on":0}}'
value_template: '{{ value_json.plug_1.on }}'
state_on: '1'
state_off: '0'
- platform: mqtt
name: 'ztc1_3_d0bae463b505'
state_topic: 'device/ztc1/d0bae463b505/state'
command_topic: 'device/ztc1/d0bae463b505/set'
payload_on: '{"mac":"d0bae463b505","plug_2":{"on":1}}'
payload_off: '{"mac":"d0bae463b505","plug_2":{"on":0}}'
value_template: '{{ value_json.plug_2.on }}'
state_on: '1'
state_off: '0'
- platform: mqtt
name: 'ztc1_4_d0bae463b505'
state_topic: 'device/ztc1/d0bae463b505/state'
command_topic: 'device/ztc1/d0bae463b505/set'
payload_on: '{"mac":"d0bae463b505","plug_3":{"on":1}}'
payload_off: '{"mac":"d0bae463b505","plug_3":{"on":0}}'
value_template: '{{ value_json.plug_3.on }}'
state_on: '1'
state_off: '0'
- platform: mqtt
name: 'ztc1_5_d0bae463b505'
state_topic: 'device/ztc1/d0bae463b505/state'
command_topic: 'device/ztc1/d0bae463b505/set'
payload_on: '{"mac":"d0bae463b505","plug_4":{"on":1}}'
payload_off: '{"mac":"d0bae463b505","plug_4":{"on":0}}'
value_template: '{{ value_json.plug_4.on }}'
state_on: '1'
state_off: '0'
- platform: mqtt
name: 'ztc1_6_d0bae463b505'
state_topic: 'device/ztc1/d0bae463b505/state'
command_topic: 'device/ztc1/d0bae463b505/set'
payload_on: '{"mac":"d0bae463b505","plug_5":{"on":1}}'
payload_off: '{"mac":"d0bae463b505","plug_5":{"on":0}}'
value_template: '{{ value_json.plug_5.on }}'
state_on: '1'
state_off: '0'
sensor:
#tc1A
- platform: mqtt
name: 'ztc1_power_d0bae4632e62'
state_topic: 'device/ztc1/d0bae4632e62/sensor'
unit_of_measurement: 'W'
icon: 'mdi:gauge'
value_template: '{{ value_json.power }}'
- platform: mqtt
name: 'ztc1_time_d0bae4632e62'
state_topic: 'device/ztc1/d0bae4632e62/sensor'
#unit_of_measurement: '秒'
icon: 'mdi:gauge'
#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 -%}
#tc1B
- platform: mqtt
name: 'ztc1_power_d0bae463b505'
state_topic: 'device/ztc1/d0bae463b505/sensor'
unit_of_measurement: 'W'
icon: 'mdi:gauge'
value_template: '{{ value_json.power }}'
- platform: mqtt
name: 'ztc1_time_d0bae463b505'
state_topic: 'device/ztc1/d0bae463b505/sensor'
#unit_of_measurement: '秒'
icon: 'mdi:gauge'
#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:
#tc1A
switch.ztc1_1_d0bae4632e62:
friendly_name: 打印机
switch.ztc1_2_d0bae4632e62:
friendly_name: 电脑主机
switch.ztc1_3_d0bae4632e62:
friendly_name: 书房摄像头
switch.ztc1_4_d0bae4632e62:
friendly_name: 电脑显示器
switch.ztc1_5_d0bae4632e62:
friendly_name: 服务器
switch.ztc1_6_d0bae4632e62:
friendly_name: 书房路由器
sensor.ztc1_power_d0bae4632e62:
friendly_name: zTC1功率
sensor.ztc1_time_d0bae4632e62:
friendly_name: zTC1运行时间
#tc1B
switch.ztc1_1_d0bae463b505:
friendly_name: S1
switch.ztc1_2_d0bae463b505:
friendly_name: S2
switch.ztc1_3_d0bae463b505:
friendly_name: S3
switch.ztc1_4_d0bae463b505:
friendly_name: S4
switch.ztc1_5_d0bae463b505:
friendly_name: S5
switch.ztc1_6_d0bae463b505:
friendly_name: S6
sensor.ztc1_power_d0bae463b505:
friendly_name: ztc1功率
sensor.ztc1_time_d0bae463b505:
friendly_name: ztc1运行时间
|