- 积分
- 498
- 金钱
- 359
- 威望
- 0
- 贡献
- 0
- HASS币
- 0
中级会员
- 积分
- 498
- 金钱
- 359
- HASS币
- 0
|
楼主 |
发表于 2019-11-1 15:39:30
|
显示全部楼层
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'
sensor:
- platform: mqtt
name: 'ztc1_power_MACMAC'
state_topic: 'device/ztc1/MACMAC/sensor'
unit_of_measurement: 'W'
icon: 'mdi:gauge'
value_template: '{{ value_json.power }}'
- platform: mqtt
name: 'ztc1_time_MACMAC'
state_topic: 'device/ztc1/MACMAC/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:
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运行时间
改MACMAC为自己的,ok!!! |
|