Modbus2HA/modbus2ha.yaml

112 lines
2.7 KiB
YAML

esphome:
name: your-device-name
friendly_name: your-device-name
substitutions:
tx_pin: GPIO17
rx_pin: GPIO16
esp32:
board: esp32dev
framework:
type: arduino
# Enable logging
logger:
# Enable Home Assistant API
api:
encryption:
key: "YOUR-HA-API-KEY"
ota:
password: "YOUR-OTA-KEY"
wifi:
ssid: !secret wifi_ssid
password: !secret wifi_password
# I have to use static IPs, your setup might be different
manual_ip:
# Set this to the IP of the ESP
static_ip: 192.168.10.10
# Set this to the IP address of the router. Often ends with .1
gateway: 192.168.10.1
# The subnet of the network. 255.255.255.0 works for most home networks.
subnet: 255.255.255.0
dns1: 192.168.10.1
# Enable fallback hotspot (captive portal) in case wifi connection fails
ap:
ssid: "FALLBACK-AP"
password: "secretfallbackpassword"
web_server:
port: 80
# If you use Home Assistant please remove this `mqtt` section and uncomment the `api` component!
# The native API has many advantages over MQTT: https://esphome.io/components/api.html#advantages-over-mqtt
mqtt:
broker: !secret mqtt_host
# username: !secret mqtt_username
# password: !secret mqtt_password
id: mqtt_client
uart:
id: uart_1
baud_rate: 9600
tx_pin: ${tx_pin}
rx_pin: ${rx_pin}
stop_bits: 1
parity: NONE
# The increased RX buffer size is important because
# the full BMS response must fit into the buffer
rx_buffer_size: 384
# debug:
# dummy_receiver: false
# direction: BOTH
# after:
# delimiter: "\r"
# sequence:
# - lambda: UARTDebug::log_string(direction, bytes);
# Further reading: https://esphome.io/components/modbus
modbus:
# flow_control_pin: 5
# send_wait_time: 500ms
id: modbus1
uart_id: uart_1
# Further reading: https://esphome.io/components/modbus_controller
modbus_controller:
- id: modbus_device
address: 0x01 ## address of the Modbus slave device on the bus
modbus_id: modbus1
update_interval: 10s
setup_priority: -10
# Now the real works starts
# Here you have to define your registers including type
# Addresses are device specific, so you have to figure out them based on your
# modbus device. Also the type must be correct. See below link about value_types, etc.
#
# Further reading: https://esphome.io/components/sensor/modbus_controller
sensor:
- platform: modbus_controller
modbus_controller_id: modbus_device
name: "Current Power"
register_type: read
address: 0x003A
unit_of_measurement: "W"
value_type: U_WORD
- platform: modbus_controller
modbus_controller_id: modbus_device
name: "Current Energy"
register_type: read
address: 0x003C
unit_of_measurement: "Wh"
value_type: U_WORD