PZEM-003 + 单片机TTL转RS485模块
esphome:
name: pzem02
friendly_name: PZEM02
project:
name: HA.PZEM02
version: v3.0.0
# name_add_mac_suffix: "true"
min_version: "2024.03.01"
#开发板
esp8266:
#开发板类型
board: nodemcuv2
# 开启日志功能
logger:
# 设置API
api:
encryption:
key: !secret api_key
# 设置OTA
ota:
password: !secret ota_password
#设置WIFI
wifi:
ssid: !secret wifi_ssid
password: !secret wifi_password
# 设置AP名称与密码
ap:
ssid: "PZEM02"
password: !secret ap_password
# 如果wifi连接失败,启动热点
captive_portal:
#设置web服务器
web_server:
port: 80
auth:
username: !secret web_server_username
password: !secret web_server_password
time:
- platform: homeassistant
id: ha_time
timezone: "Asia/Shanghai"
uart:
tx_pin: GPIO04
rx_pin: GPIO05
baud_rate: 9600
stop_bits: 2
sensor:
- platform: pzemdc
id: pzem_dc
current:
name: "Current"
voltage:
name: "Voltage"
power:
name: "Power"
energy:
name: "Energy"
update_interval: 60s
- platform: wifi_signal
name: "WiFi Signal"
update_interval: 30s
button:
- platform: restart
name: "Restart"
- platform: template
name: "Reset Energy"
icon: mdi:cached
on_press:
then:
- delay: 100ms
- pzemdc.reset_energy: pzem_dc
text_sensor:
- platform: wifi_info
ip_address:
name: "IP"
id: id_sensor_ip
icon: mdi:ip
type: vertical-stack
cards:
- square: false
type: grid
cards:
- type: gauge
entity: sensor.pzem02_voltage
needle: true
min: 20
max: 28.4
name: NVR电池
severity:
green: 22
yellow: 0
red: 0
- type: gauge
entity: sensor.pzem02_current
min: 0
max: 10
needle: true
severity:
green: 2
yellow: 5
red: 8
name: 充电电流
- type: gauge
entity: sensor.pzem02_power
needle: true
severity:
green: 40
yellow: 100
red: 160
min: 0
max: 200
name: 充电功率
- type: horizontal-stack
cards:
- show_name: true
show_icon: true
show_state: true
type: glance
entities:
- entity: sensor.pzem02_yesterday_energy
name: 昨日电量
- entity: sensor.pzem02_daily_energy
name: 今日电量
- entity: sensor.pzem02_monthly_energy
name: 本月电量
state_color: true
- type: custom:apexcharts-card
experimental:
color_threshold: true
brush: true
graph_span: 30h
span:
end: hour
show:
last_updated: true
header:
standard_format: false
show: true
title: 当前功率
show_states: true
colorize_states: true
now:
show: true
color: red
label: Now
series:
- entity: sensor.pzem02_power
type: line
group_by:
func: avg
duration: 5m
stroke_width: 2
show:
extremas: true
header_color_threshold: true
in_brush: true
color_threshold:
- value: 20
color: steelblue
- value: 40
color: midnightblue
- value: 60
color: orange
- value: 80
color: orangered
- value: 100
color: red
##/homeassistant/configuration.yaml
utility_meter:
pzem02_daily_energy: #pzem02今日电量
source: sensor.pzem02_energy
cycle: daily
pzem02_monthly_energy: #pzem02本月电量
source: sensor.pzem02_energy
cycle: monthly
pzem02_yearly_energy: #pzem02今年电量
source: sensor.pzem02_energy
cycle: yearly
template:
- sensor:
- name: pzem02_yesterday_energy #昨日电量
unit_of_measurement: kWh
device_class: energy
state: "{{(state_attr('sensor.pzem02_daily_energy','last_period') | float)| round(3)}}"
- name: pzem02_Last_month_energy #上月电量
unit_of_measurement: kWh
device_class: energy
state: "{{(state_attr('sensor.pzem02_monthly_energy','last_period') | float)| round(3)}}"
- name: pzem02_last_year_energy #去年电量
unit_of_measurement: kWh
device_class: energy
state: "{{(state_attr('sensor.pzem02_yearly_energy','last_period') | float)| round(3)}}"
|