Hi,
I am using a M5stack core device to which I flashed ESPhome onto to which I want to send some variables to via Modbus. However I can’t get the right value to be send to the sensor I created.
I connected a HW-097 module with jumper cables, similar to below image.
I plugged in a USB to serial modbus device in my Home Assistant server, similar to this one:
This is my ESPHome .yaml code:
esphome:
name: m5stack-fire
platform: ESP32
board: m5stack-core-esp32
# Enable logging
logger:
# Enable Home Assistant API
api:
ota:
password: "xxx"
wifi:
ssid: "xxx"
password: "xxx"
# Enable fallback hotspot (captive portal) in case wifi connection fails
ap:
ssid: "M5Stack Fallback Hotspot"
password: "xxx"
captive_portal:
time:
- platform: sntp
id: sntp_time
uart:
id: mod_bus
tx_pin: 17
rx_pin: 16
baud_rate: 9600
stop_bits: 1
modbus:
id: modbus1
flow_control_pin: 5
modbus_controller:
- id: modbuscontrollerm5stack
## the Modbus device addr
address: 0x1
modbus_id: modbus1
sensor:
- platform: modbus_controller
modbus_controller_id: modbuscontrollerm5stack
name: "Woonkamer Temperatuur"
id: woonkamer_temperatuur
register_type: holding
address: 0x40001
value_type: U_WORD
This is the Modbus part in my configurations.yaml
# Example configuration.yaml entry for a serial connection
modbus:
- name: hub1
type: serial
baudrate: 9600
bytesize: 8
method: rtu
parity: N
port: "/dev/serial/by-id/usb-1a86_USB2.0-Ser_-if00-port0"
stopbits: 1
The esphome sensor “Woonkamer Temperatuur” pops up in my Home Assistant. When I try to send a value with the Service tab under Developer Tools, i am using the following:
service: modbus.write_register
data:
value: 20
hub: hub1
address: 40001
unit: 1
The thing that happens is that what I fill at address, is often set as the value for the sensor. But not always. So at least something happens and data connection is there.
However I think it has something to do with the array of bytes which will sometimes lead to a setting of the register and sometimes not. It seems like a coincidence that sometimes a readable signal is sent for the slave.
Does anyone know if should set the bytesize/parity or stopbits different in Configuration.yaml? Do I maybe have to set the value or the address in a different form? Or does the Value_type (currently U_WORD) have to be set differently?