esphome:
name: config-address
friendly_name: Config address
on_boot:
priority: -100
then:
- lambda: |-
auto new_address = 0x02;
if(new_address < 0x01 || new_address > 0xF7) // sanity check
{
ESP_LOGE("ModbusLambda", "Address needs to be between 0x01 and 0xF7");
return;
}
esphome::modbus_controller::ModbusController *controller = id(pzem);
auto set_addr_cmd = esphome::modbus_controller::ModbusCommandItem::create_write_single_command(
controller, 0x0002, new_address);
delay(200) ;
controller->queue_command(set_addr_cmd);
ESP_LOGI("ModbusLambda", "PZEM Addr set");
modbus:
- id: mbus
uart_id: PZEM
send_wait_time: 200ms
modbus_controller:
- id: pzem
address: 0x1
modbus_id: mbus
command_throttle: 0ms
setup_priority: -10
update_interval: 30s
uart:
- id: PZEM
rx_pin: GPIO3
tx_pin: GPIO1
baud_rate: 9600
esp8266:
board: esp01_1m
# Enable logging
logger:
level: DEBUG
web_server:
port: 80
# Enable Home Assistant API
api:
encryption:
key: "KSBBBQVoVbJ6j8flF+rrMq3a6yiGQceZSjmn9oUvclY="
ota:
password: "75f29fec0521d7ac3b824da11b1bb751"
wifi:
ssid: !secret wifi_ssid
password: !secret wifi_password
# Enable fallback hotspot (captive portal) in case wifi connection fails
ap:
ssid: "Config-Address Fallback Hotspot"
password: "RWcV3qCI71y0"
manual_ip:
static_ip: 172.23.109.16
gateway: 172.23.109.126
subnet: 255.255.255.128
dns1: 172.23.109.126
dns2: 1.1.1.1
captive_portal:
sensor:
- platform: pzemac
address: 0x02
current:
name: "Address2 Current"
voltage:
name: "Address2 Voltage"
energy:
name: "Address2 Energy"
power:
name: "Address2 Power"
frequency:
name: "Address2 Frequency"
power_factor:
name: "Address2 Power Factor"
update_interval: 10s
1 Like