ESP-IM1266-Meter电表制作

ESP-IM1266-Meter电表制作

接入Home Assistant效果:

image-20220530011149190

硬件图:

image-20220530005707784

image-20220530005750588

加个外壳

image-20220530005939349

软件:

这是使用罗总框架实现数据获取

QQ图片20220530005818

这是使用ESPHome实现数据获取

image-20220530010114916

接入homeassistant

img

资源:

IM1266手册: IM1266_C471615.pdf

BOM表和Gerber文件: EDP-IM1266-Meter.zip

罗总框架实现的固件: esp8266_im1266_mb.bin

ESPHome实现的代码: im1266.yaml

开源协议: GPL 3.0

im1266.yaml

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
#################################################
##IM1266 Energy V1.0##
######### 20220528 by MiWyf #####################

# Your secrets.yaml
# wifi_ssid: 'ssid' #WiFi_SSID名称
# wifi_password: '12345678' #WiFi密码
# wifi_password_AP: '12345678' #ap_WiFi密码
# wifi_fast_connect: 'false' #如果SSID是隐藏的,设置为true
# wifi_reboot_timeout: 60s #WiFi离线多久后重启设备,秒s/分钟min/小时h,不需要此功能设置为0s
# ota_password: '12345678' #OTA密码
# api_password: '12345678' #OTA密码
# api_reboot_timeout: 0s #与客户端(如Home Assistant)失去连接多久后重启设备,秒s/分钟min/小时h,不需要此功能设置为0s
# mqtt_reboot_timeout: 0s

#################################################

substitutions:
#Name your Gateway
device_name: im1266
#Home Assistant Name
friendly_name: ESP IM1266
#Secret YAML is used for next data:
api_pw: !secret api_password
ota_pw: !secret ota_password

esphome:
name: ${device_name}
platform: ESP8266
board: esp01_1m

# Enable logging
#logger:
#level: DEBUG

# Enable Home Assistant API
api:
password: ${api_pw}
reboot_timeout: 0s

# Enable OTA
ota:
password: ${ota_pw}

#Enable WEB
web_server:
port: 80

# Enable HA Time
time:
- platform: homeassistant
id: homeassistant_time

wifi:
ssid: !secret wifi_ssid
password: !secret wifi_password

# Enable fallback hotspot (captive portal) in case wifi connection fails
ap:
ssid: "IM1266"
password: "12345678"

captive_portal:

status_led:
pin: GPIO16

#UART Settings
uart:
id: mod_bus
tx_pin: 12
rx_pin: 14
baud_rate: 4800
stop_bits: 1

modbus:
flow_control_pin: 13
id: modbus1

modbus_controller:
- id: epever
## the Modbus device addr
address: 0x1
modbus_id: modbus1
setup_priority: -10

sensor:
- platform: uptime
id: uptime_s
update_interval: 60s
- platform: modbus_controller
modbus_controller_id: epever
name: "${friendly_name} Voltage"
id: im1266_voltage
register_type: holding
address: 0x0048
unit_of_measurement: "V"
value_type: U_DWORD
accuracy_decimals: 4
filters:
- multiply: 0.0001
- platform: modbus_controller
modbus_controller_id: epever
name: "${friendly_name} Current"
id: im1266_current
register_type: holding
address: 0x0049
unit_of_measurement: "A"
value_type: U_DWORD
accuracy_decimals: 4
filters:
- multiply: 0.0001
- platform: modbus_controller
modbus_controller_id: epever
name: "${friendly_name} Power"
id: im1266_power
register_type: holding
address: 0x004A
unit_of_measurement: "W"
value_type: U_DWORD
accuracy_decimals: 4
filters:
- multiply: 0.0001
- platform: modbus_controller
modbus_controller_id: epever
name: "${friendly_name} Energy"
id: im1266_energy
register_type: holding
address: 0x004B
unit_of_measurement: "kWh"
value_type: U_DWORD
accuracy_decimals: 4
filters:
- multiply: 0.0001
- platform: modbus_controller
modbus_controller_id: epever
name: "${friendly_name} PF"
id: im1266_pf
register_type: holding
address: 0x004C
unit_of_measurement: ""
value_type: U_DWORD
accuracy_decimals: 3
filters:
- multiply: 0.001
- platform: modbus_controller
modbus_controller_id: epever
name: "${friendly_name} CO2"
id: im1266_co2
register_type: holding
address: 0x004D
unit_of_measurement: "Kg"
value_type: U_DWORD
accuracy_decimals: 4
filters:
- multiply: 0.0001
- platform: modbus_controller
modbus_controller_id: epever
name: "${friendly_name} Temprature"
id: im1266_temprature
register_type: holding
address: 0x004E
unit_of_measurement: "°C"
value_type: U_DWORD
accuracy_decimals: 2
filters:
- multiply: 0.01
- platform: modbus_controller
modbus_controller_id: epever
name: "${friendly_name} Frequency"
id: im1266_frequency
register_type: holding
address: 0x004F
unit_of_measurement: "Hz"
value_type: U_DWORD
accuracy_decimals: 2
filters:
- multiply: 0.01

switch:
# - platform: uart
# name: "UART String Output"
# data: 'DataToSend'

- platform: uart
name: "${friendly_name} clear10"
data: [0x01,0x10,0x00,0x4B,0x00,0x02,0x04,0x00,0x00,0x00,0x00,0xB6,0x2C]
#- platform: modbus_controller
#modbus_controller_id: epever
#name: "${friendly_name} Clear"
#register_type: holding
#address: 0x004B
#bitmask: 0
#true: 0x10, false:0x06
#use_write_multiple: true
#custom_command: [0x01,0x10,0x00,0x4B,0x00,0x02,0x04,0x00,0x00,0x00,0x00]

# - platform: uart
# name: "UART Recurring Output"
# data: [0xDE, 0xAD, 0xBE, 0xEF]
# send_every: 1s
- platform: restart
name: "${friendly_name} Restart"

# Extra sensor to keep track of gateway uptime
text_sensor:
- platform: template
name: "${friendly_name} Uptime"
lambda: |-
uint32_t dur = id(uptime_s).state;
int dys = 0;
int hrs = 0;
int mnts = 0;
if (dur > 86399) {
dys = trunc(dur / 86400);
dur = dur - (dys * 86400);
}
if (dur > 3599) {
hrs = trunc(dur / 3600);
dur = dur - (hrs * 3600);
}
if (dur > 59) {
mnts = trunc(dur / 60);
dur = dur - (mnts * 60);
}
char buffer[17];
sprintf(buffer, "%ud %02uh %02um %02us", dys, hrs, mnts, dur);
return {buffer};
icon: mdi:clock-start
update_interval: 60s