啥详细代码?配置文件A大不是提供的有吗,自动化我发那个把MAC地址改成你的就行了。
配置文件(比如packages目录zm1.yaml):
sensor:
- platform: mqtt
name: 'zm1_你的MAC地址_temperature'
# friendly_name: 温度
state_topic: 'device/zm1/你的MAC地址/sensor'
unit_of_measurement: '°C'
icon: 'mdi:thermometer'
value_template: '{{ value_json.temperature }}'
- platform: mqtt
name: 'zm1_你的MAC地址_humidity'
# friendly_name: 湿度
state_topic: 'device/zm1/你的MAC地址/sensor'
unit_of_measurement: '%'
icon: mdi:water-percent
value_template: '{{ value_json.humidity }}'
- platform: mqtt
name: 'zm1_你的MAC地址_pm25'
# friendly_name: PM25
state_topic: 'device/zm1/你的MAC地址/sensor'
unit_of_measurement: 'μg/m³'
icon: mdi:blur
value_template: '{{ value_json.PM25 }}'
- platform: mqtt
name: 'zm1_你的MAC地址_hcho'
# friendly_name: 甲醛
state_topic: 'device/zm1/你的MAC地址/sensor'
unit_of_measurement: 'mg/m³'
icon: mdi:chemical-weapon
value_template: '{{ value_json.formaldehyde }}'
light:
- platform: mqtt
name: zm1_你的MAC地址_brightness
schema: template
command_topic: "device/zm1/你的MAC地址/set"
state_topic: "device/zm1/你的MAC地址/state"
command_on_template: >
{"mac": "你的MAC地址"
{%- if brightness is defined -%}
, "brightness": {{ ((brightness-1) / 64 )|int +1 }}
{%- else -%}
, "brightness": 4
{%- endif -%}
}
command_off_template: '{"mac": "你的MAC地址", "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 -%}
homeassistant:
customize:
light.zm1_你的MAC地址_brightness:
friendly_name: zM1亮度
sensor.zm1_你的MAC地址_temperature:
friendly_name: zM1温度
sensor.zm1_你的MAC地址_humidity:
friendly_name: zM1湿度
sensor.zm1_你的MAC地址_pm25:
friendly_name: zM1 PM2.5
sensor.zm1_你的MAC地址_hcho:
friendly_name: zM1甲醛
根目录automations文件:
# ----------------------------------
- id: '1999666935551'
alias: 自动开
description: ''
trigger:
- at: '08:00:00' #早上8点开
platform: time
condition: []
action:
- entity_id: light.zm1_你的MAC地址_brightness
service: light.turn_on
- id: '1999666681661'
alias: 自动关
description: ''
trigger:
- at: '00:00:00' #晚上12点关
platform: time
condition: []
action:
- entity_id: light.zm1_你的MAC地址_brightness
service: light.turn_off
# ----------------------------------
|