Example code
Example code
esphome:
name: energy-meter
friendly_name: Energy meter
esp32:
board: esp32dev
framework:
type: arduino
# Enable logging
logger:
ota:
password: "xxx"
wifi:
ssid: wifi_ssid
password: wifi_password
manual_ip:
# Set this to the IP of the ESP
static_ip: 192.168.1.97
# Set this to the IP address of the router. Often ends with .1
gateway: 192.168.1.1
# The subnet of the network. 255.255.255.0 works for most home networks.
subnet: 255.255.255.0
captive_portal:
modbus:
id: modbus1
modbus_controller:
- id: jsymk
#modbus device address
address: 0x1
modbus_id: modbus1
update_interval: 12s
command_throttle: 50ms
i2c:
sda: 21
scl: 22
font:
- file:
type: gfonts
family: Baloo+Bhaijaan+2
weight: 500
id: baloo_18_500
size: 18
- file:
type: gfonts
family: Baloo+Bhaijaan+2
weight: 700
id: baloo_32_700
size: 32
- file:
type: gfonts
family: Baloo+Bhaijaan+2
weight: 700
id: baloo_18_700
size: 18
- file: "gfonts://Material+Symbols+Outlined"
id: icons_18
size: 18
glyphs: ["\ue63e", "\ue648"] # mdi-wifi, mdi-wifi-off
display:
- platform: ssd1306_i2c
model: "SSD1306 128x64"
address: 0x3C
id: oled
rotation: 180°
lambda: |-
it.print(-1, -4, id(baloo_18_500), "Energy Meter");
if(id(connection_status).state == 1) {
it.print(it.get_width(), 0, id(icons_18), TextAlign::TOP_RIGHT, "\ue63e");
}
else {
it.print(it.get_width(), 0, id(icons_18), TextAlign::TOP_RIGHT, "\ue648");
}
binary_sensor:
# Connection status
- platform: status
name: "Status"
id: connection_status
sensor:
# First channel voltage
- platform: modbus_controller
modbus_controller_id: jsymk
id: voltage1
name: "Voltage"
icon: mdi:alpha-v-box
device_class: energy
address: 0x0048
unit_of_measurement: "V"
register_type: holding
value_type: U_DWORD
accuracy_decimals: 1
filters:
- multiply: 0.0001
register_count: 1
response_size: 4
# Frequency
- platform: modbus_controller
modbus_controller_id: jsymk
id: frequency
name: "Frequency"
icon: mdi:sine-wave
device_class: energy
address: 0x004F
unit_of_measurement: "Hz"
register_type: holding
value_type: U_DWORD
accuracy_decimals: 1
filters:
- multiply: 0.01
register_count: 1
response_size: 4