I’m looking into configuring ESPHome to receive Modbus TCP commands to control switches via Modbus TCP. Does anyone have experience setting this up or can provide guidance on how to achieve this with ESPHome? Alternatively, are there any other user-friendly tools or platforms recommended for programming an ESP32 for this task?
Any advice or suggestions would be greatly appreciated!
I want to connect an ESP32 chip directly to another Modbus TCP device without using Home Assistant. However, I find using ESPHome appealing due to its user-friendly programming interface. My goal is to toggle some relays based on the Modbus TCP messages received.
Hi there, i’m unable to build a firmware with that at the moment:
src/modbus_tcp_component.h:2:10: fatal error: WiFiClient.h: No such file or directory
Any suggestion. I need to “convert” a modbus tcp device in another network to home assistant sensors.
My home assistant instance can’t reach directly the modbus tcp IP from the cloud to local network.
Hi there, if anyone is still interested I’m trying to convert the modbus h library for esp-idf (that was the problem with WiFiClient.h which is an arduino library).
First steps seem promising as i’m reading correctly data from a modbus TCP device in my network and publishing the value to the sensors using mqtt.
Yes I am very interested by… I was planning to write a native ESPhome component… but I was not aware that WiFiClient was arduino only. Do you have advance since ?
i still haven’t generalized the library. I have a custom version i’m using to read some modbus data in my local network and send them via mqtt to home assistant.
I have exactly what you need!
So far it works very well with OpenTherm with similar purpose as you need.
I was looking for ready solution, but all were bad, so I made one myself.
Cheers and please buy me a coffee if you enjoy it!
Since Modbus uses 16-bit registers, and you want 10 32-bit values, you’ll need to read them as 20 individual 16-bit registers, for example using Bulk Operations.
After that, combine each pair to form a 32-bit value, but make sure you know which part of the pair is little-endian and which is big-endian. Big-endian is the most common, meaning the high word should go into the first register. Python example:
# Big-endian (most common)
value_32bit = (registers[0] << 16) | registers[1]
# Or for little-endian
# value_32bit = (registers[1] << 16) | registers[0]
# For signed 32-bit integer
if value_32bit >= 0x80000000:
value_32bit -= 0x100000000
I rewritten ESPhome Modbus Controller to modbusTCP.
Works same as original Modbus Controller (RTU)
At the Moment works only sensor without error Codes.
Comes in Future. Maybe it helps.
github://creepystefan/esphome_tcp
Hi Vincèn,
What you propose requires a Modbus-TCP connection? I am interested in this as I have a KWB boiler which has no network interface, so I will need to connect my own RS485-TTL board to it, how would you expect that this is visible to home assistant (I had assumed I’d connect to a ESP32 with ESPHome which is then visible over WiFi, looking for options as the Integration looks better but needs a Modbus-TCP unit bridging the modbus device and the network. Thanks