• Have you tried out dark mode?! Scroll to the bottom of any page to find a sun or moon icon to turn dark mode on or off!

diy solar

diy solar

Universal software Modbus(serial) to bidirectional MQTT forwarder.

Luk88

Solar Addict
Joined
Apr 5, 2024
Messages
783
Location
Poland
My Python script I use to pull data off and to control the Y&H inverters via serial modbus is slowly becoming more universal as I'm expecting some Modbus utility power meters to arrive and I'd like to use it for that too. But before I spend time rewriting it again I thought to ask if there is some better universal open source software capable of bridging the Modbus serial - MQTT gap on a normal PC/raspberry pi (so not ESP32)?

I'd like this software to be able to fetch from Modbus registers via serial, process the data in a configured way (for example divide by 10 and convert to float, or do other arbitrary math transforms). Also I'd like it to subscribe to MQTT topics and write to Modbus registers based on messages coming from MQTT. Support for multiple devices on one port and ability to generate Home Assistant autodiscovery mesasges for all these would be a huge bonus.

If anyone knows something like this please let me know.
 
My Python script I use to pull data off and to control the Y&H inverters via serial modbus is slowly becoming more universal as I'm expecting some Modbus utility power meters to arrive and I'd like to use it for that too. But before I spend time rewriting it again I thought to ask if there is some better universal open source software capable of bridging the Modbus serial - MQTT gap on a normal PC/raspberry pi (so not ESP32)?

I'd like this software to be able to fetch from Modbus registers via serial, process the data in a configured way (for example divide by 10 and convert to float, or do other arbitrary math transforms). Also I'd like it to subscribe to MQTT topics and write to Modbus registers based on messages coming from MQTT. Support for multiple devices on one port and ability to generate Home Assistant autodiscovery mesasges for all these would be a huge bonus.

If anyone knows something like this please let me know.
I believe Node red will be the best choice.
 
my project does most of that:

doesn't do any complex math operations though... can do multiplication by adjusting units in the protocol csv files though.

still a bit of a work in progress. still lots of features on the list to add in.
 
this would be an example config for 2 devices running on the same modbus adapter / port.
since i don't have an example for 2 devices on one port written anywhere.
tested something similar and it worked.

the modbus registers are defined via csv files.

Code:
[general]
log_level = DEBUG

[transport.device1] #name must be unique, ie: transport.modbus
#rs485 / modbus device
#protocol config files are located in protocols/
protocol_version = voltronic_bms_2020_03_25

port = /dev/ttyUSB0
baudrate = 9600
address = 0

#the 'transport' that we want to share this with
bridge = transport.mqtt

manufacturer = hotnoob
model = 48v100AH
name = device1 test RS485
#optional; leave blank to autofetch serial from device
serial_number = transport_device1_test

read_interval = 30
error_interval = 60

[transport.device2] #name must be unique, ie: transport.modbus
#protocol config files are located in protocols/
protocol_version = v0.14

port = /dev/ttyUSB0
baudrate = 9600
address = 1

#the 'transport' that we want to share this with
bridge = transport.mqtt

manufacturer = hotnoob
model = 48v100AH
name = device2 test RS485
#optional; leave blank to autofetch serial from device
serial_number = transport_device2_test

read_interval = 45
error_interval = 60


[transport.mqtt]
#connect mqtt
transport=mqtt
host =
port = 1883
user =
pass =
base_topic = solar/modbus/
error_topic = /error
json = false
discovery_enabled = true
discovery_topic = homeassistant
 
I believe Node red will be the best choice.
Sorry. I'm not a big fan of java script and even less of the "low code" stuff. Of course you couldn't know it when you made this suggestion so perhaps it is the best choice for someone else :-)

But I'd argue learning something like python and using it is much better, by giving one freedom to fix all bugs, add your own features and so on. "Low code" systems in general appear simple to use on the surface, until you try doing something slightly unconventional, then it turns out you need to know the programming language they are written in (or worse, their made up scripting language), as well as you need to really understand the details of how the entire system works and often they are written in a very convoluted way and depend on very heavy software (like a browser). What I'm trying to say is the initial learning curve may be gentle, but it gets very steep very fast quickly if you try to do something more advanced. With "normal code" programming the initial learning curve may be a bit steep (especially for the very first programming language a person learns) but then levels out and stays level and you can do everything you can imagine. All the hard stuff (algorithms and so on) is already done by others in open source libraries.

Don't take this as a personal attack. I don't know node red. It may very well be great. I just don't like low code stuff in general.

my project does most of that:

doesn't do any complex math operations though... can do multiplication by adjusting units in the protocol csv files though.

still a bit of a work in progress. still lots of features on the list to add in.
Thanks. After a brief look it seems like exactly what I'm looking for. Maybe a little bit of an overkill - being a multiprotocol thing, but I'd know only after getting deeper into it.

I don't need more math than multiplication and division at this stage so that is covered.

I see there is HA auto discovery, cool. And it supports writing to modbus. (I assume you write to the same topic you're reading once you configure the register as writable in the csv). I wonder how extensible auto discovery is. One of the goals I have is to have all the entities auto discovered by HA (such as number, select, switch etc - not just sensors, so the whole device, including controls, pops up ready to be added to dashboards in HA).

I could probably get it to do everything I need out of the box, perhaps except of autodiscovery of these writable entities (I'm not sure about value templates either).

I'll be having a closer look.
 

diy solar

diy solar
Back
Top