Read modbus with ESP32 and ESPHome

Is anyone using ESP32 to read modbus data? Is it even possible?
Im now using Raspberry Pi and RS485 modbus dongle to receive data from my energymeter (Carlo Gavazzi EM24). Im wondering is there any way to do that same with ESP32 and ESPHome?
I found this, but i don’t know what can we do with that and how to use?


And dongle im now using is like this:

Generally anything an arduino can do, an esp8266 or esp32 can do. Googling “arduino modbus” leads here https://www.arduino.cc/en/ArduinoModbus/ArduinoModbus

So there is a library you could probably leverage in esp.

And I cannot see a modbus component in the esphome docs, that source code on github is a bit of a mystery, but it is just a serial protocol isn’t it?

Yes it is serial protocol.

So it should be possible, it would be very nice to use ESPHome and ESP32 for this, but i have no idea where to start. :frowning:
If someone has any idea, i would appreciate very much. :slight_smile:

Try dropping a pull request on the esphome GitHub. That code is not old, probably being worked out by Otto. If a few of us pr it, maybe it’ll happen sooner rather than later.

I have a similar request and dug around a bit. I’ve found mentions of modbus on the changelogs of ESPHome (https://github.com/esphome/esphome/pull/789 and https://github.com/esphome/esphome/pull/806) and theres a modbus folder in the components folder, as @JISARG already found out (https://github.com/esphome/esphome/tree/dev/esphome/components/modbus).

Maybe the SPI Component is the correct one? https://esphome.io/components/spi.html

Is someone able to clarify?

The pzem sensors, which are supported in esphome, use modbus. Maybe look at that code for inspiration?

1 Like

I think I’m looking for pretty much the same thing but I’d like to communicate from Hass.io through ESP Home to my Car charger (rs485) to control the power draw.

Modbus code is in esphome - as you point out. However it is not a component. It is a base for other components, pzem is an example.

Nothing to do with SPI afact.

You’ll need a rs-485-ttl adapter. And details of the communication the car charger uses. Do you have some documentation?

Someone has done a great job reverse engineerin that in the TWS Manager project https://github.com/cdragon/TWCManager it should cointain all information necessary. However I’m not capable of utilizing that information to get going.

That does not use modbus. See https://github.com/cdragon/TWCManager/issues/5

However the protocol does seem to be well documented in the heavily commented python code. Beyond that, pkease start another thread as it is off topic here :wink:

1 Like

But is possibile from esphome read direcly rs485 modbus example from Sdm230 modbus reader?

Modbus code is in esphome - as you point out. However it is not a component. It is a base for other components, pzem is an example.

Nothing to do with SPI afaict.

sorry @nickrout but I did not understand what you mean, explain in practice how can I configure esphome and which 2 gpio should I use to connect it to my rs458 modbus sdm230 counter

I have said it numerous times in this thread. Look at the esphome pzem code, it uses the modbus library.

I’ll make it simpler:

  1. Go here https://github.com/esphome/esphome/tree/dev/esphome

  2. Use the search box to search for modbus.

"

1 Like

@jiisaa and @wifi75
Did you make any progress in this?

I would love to read my energy meter with an esp32, maybe even all of my 4 energy meter with one esp32.

There are now more uart components in HA, eg Custom UART Device — ESPHome and example here Custom UART Text Sensor — ESPHome

You can read easily up to 32 devices using Arduino MKR WiFi 1010 with MKR 485 shield. Use Arduino libraries for the Shield and PubSub library for MQTT.
Read holding registers and publish value to the corresponding topic.
Then just make MQTT Sensor in HA and subscribe.

I’m using it to read from pH and EC sensors through modbus. Works perfect.

1 Like

Full modbus

Examples

1 Like

Do you have more i fo about these snesors? Type name price?