|
发表于 2023-1-15 10:53:22
|
显示全部楼层
我是单独写的一个mqtt.yaml文件,亲测成功运行,你可以参考。这个方法是斐讯M1的开发群里的大佬给的解决方案。
文件放在这里/config/mqtt.yaml
sensor:
- name: 'zm1_b0f89329159f_temperature'
# friendly_name: 温度
state_topic: 'device/zm1/b0f89329159f/sensor'
unit_of_measurement: '°C'
icon: 'mdi:thermometer'
value_template: '{{ value_json.temperature }}'
unique_id: "温度"
- name: 'zm1_b0f89329159f_humidity'
# friendly_name: 湿度
state_topic: 'device/zm1/b0f89329159f/sensor'
unit_of_measurement: '%'
icon: mdi:water-percent
value_template: '{{ value_json.humidity }}'
unique_id: "湿度"
- name: 'zm1_b0f89329159f_pm25'
# friendly_name: PM25
state_topic: 'device/zm1/b0f89329159f/sensor'
unit_of_measurement: 'μg/m³'
icon: mdi:blur
value_template: '{{ value_json.PM25 }}'
unique_id: "PM2.5"
- name: 'zm1_b0f89329159f_hcho'
# friendly_name: 甲醛
state_topic: 'device/zm1/b0f89329159f/sensor'
unit_of_measurement: 'mg/m³'
icon: mdi:chemical-weapon
unique_id: "甲醛"
value_template: '{{ value_json.formaldehyde }}'
light:
- name: zm1_b0f89329159f_brightness
unique_id: "亮度"
schema: template
command_topic: "device/zm1/b0f89329159f/set"
state_topic: "device/zm1/b0f89329159f/state"
command_on_template: >
{"mac": "b0f89329159f"
{%- if brightness is defined -%}
, "brightness": {{ ((brightness-1) / 64 )|int +1 }}
{%- else -%}
, "brightness": 4
{%- endif -%}
}
command_off_template: '{"mac": "b0f89329159f", "brightness": 0}'
state_template: >
{%- if value_json.brightness == 0 -%}
off
{%- else -%}
on
{%- endif -%}
brightness_template: >
{%- if value_json.brightness is defined -%}
{{ ( value_json.brightness *64 )|int }}
{%- endif -%}
unique_id: "亮度" unique_id: "甲醛值"
以下这段写到主配置文件configuration.yaml里
homeassistant:
customize:
light.zm1_b0f89329159f_brightness:
friendly_name: 客厅M1亮度
sensor.zm1_b0f89329159f_temperature:
friendly_name: 客厅温度
sensor.zm1_b0f89329159f_humidity:
friendly_name: 客厅湿度
sensor.zm1_b0f89329159f_pm25:
friendly_name: 客厅PM2.5
sensor.zm1_b0f89329159f_hcho:
friendly_name: 书房甲醛浓度 |
|