HA Modbus integration TA CMI. How to setup Modbus Slave with HA?

Hi,

my Usecase:
i have integrated homeatic IP Data to homeassistant.

I want to setup a Modbus Slave on HA and read the Modbus from Technische Alternative (TA) CMI from Home assistant.

I only read how to read data from HA via modbus. I have done that successfully with the configuration.yaml.

But i don’t find any information to setup a own Modbus Register with HA fill it with data from HA, like Temperature Data from homematic and then read it from other Modbus Masters like TA CMI.

It would be great if some can give me advice, tip, dokumentation how to set it up in HA.

Best Regards

David

I cannot comment on possible integrations for HA to act as a Modbus server (slave) but this can be done relatively easily from within Node-RED. I have certainly managed to use Node-RED to set up an HTTP server that responds to client requests, and I can ‘pull’ data from Node-RED into HA using a REST call.

I use Node-RED extensively, and this includes Modbus master (client) interaction with my solar inverter as a Modbus slave (server). The node-red-contrib-modbus set of nodes includes a Modbus Server (and Modbus Flex Server) node which hold ‘registers’ that can be written to and read from.

I have only used the included example flow for testing, but I have managed to write to registers and to be able to read back on the same machine. I see no reason why this could not be developed into a flow that responds to HA entity state changes, writes these changes to the NR Modbus server ‘registers’, and provides the ability for an external Modbus client to read (and perhaps also write) these registers.

https://github.com/BiancoRoyal/node-red-contrib-modbus

Note that the Modbus server acts just as a stand-alone server with a defined register capacity. To use this you need to define your own register map, and to set up Modbus writes to actually put data into the registers.

Alternatively, if you are using Modbus over TCP, then this is just a protocol using TCP, so it should be possible to build a Modbus server based on http in and http response nodes.

Thanks for your answer!

Well, i hope to kepp my setup as simple as possible. Before switching to Node-RED i try to accomplish it with HA.

For TA CMI, i need a Modbus TCP/IP, i have found this post:

so it’s not out of the box possible to setup with HA.

I think a way could be via modbus.py PyModbus - A Python Modbus Stack — PyModbus 3.0.0.dev5 documentation

If anybody have a tip or already accomplished it, would be happy to have some guidance.

I have ended up with:
Home Assistant Input Data from Homematic IP
Output to Modbus Server with: PyModbus - A Python Modbus Stack — PyModbus 3.0.0.dev5 documentation
Read Modbus via TA C.M.I and send it via CAN to UVR16X2 and configure it, in my environment

Works great for me, now i can work with all my Homematic ip temperature Room Sensors and TA UVR16x2

Home Assistant configuration.yaml:

modbus:
- name: "ha"
   type: tcp
   host: xxx.xxx.xxx.xxx
   port: 502

Home Assistant scripts.yaml:

ha_cmi:
  sequence:
  - service: modbus.write_register
    data:
    address: 1
    unit: 1
    hub: ha
    value: '{{ states(''sensor.temperatur_und_luftfeuchtigkeitssensor_mit_display_temperature_4'') | int }}'
  mode: single
  alias: ha_cmi

Home Assistant automations.yaml:

- alias: ha_ta
  trigger:        
    platform: time_pattern  
    minutes: '/1'
    seconds: 00
  action:
    service: script.ha_cmi
2 Likes

I’m a bit confused as to who is the Modbus server in this scenario.

Based on my understanding I thought that TA C.M.I. is the modbus server. I can’t get this work however.
I can read/write values from/to CMI if I treat it as slave using EasyModbusTCP Server Simulator.

I’m currently using the JSON API to publish to mqtt - but only have that working for sensor values.
So looking into another way to get function data from the UVR16x2 / CMI.

Hi @davidhom ,
thanks for your solution.
I want to achieve the same, I want to send the current temperature and the target temperature from my room thermostats over modbus_tcp to the C.M.I. But my UVR16x2 + C.M.I isn’t installed yet. I just figure out how it would work.

As I understand the CMI is the Modbus master and HA cannot act as HA Slave?
In your script snippet where is the information to which IP data is sent? Will the modbus.write_register takes the IP from the modbus configuration from configuration.yaml?

Do I need to setup a third-party modbus server (act as slave)? Or what do you mean with

Output to Modbus Server with: PyModbus - A Python Modbus Stack — PyModbus 3.0.0.dev5 documentation

So the Host IP in modbus configuration from configuration.yaml points to this third-party modbus server?

Would really appreciate if you explain the setup a bit more in detail.

Thanks!

Hi all!
I am also trying to integrate the inputs and outputs of my UVR1611 in HA… At the moment I am using the following integration, which is working fine:

Only drawback is that I recieve the data obly each 10min. So I am looking to a solution, which is completely local, where I can read the values more often. This should be possible over modbus. Now my question is what I would need for this and how to setup everything? Do I need something like this:

Waveshare RS485 to RJ45 Ethernet Converter Module, Industrial Rail-Mount RS485 Serial Server,TCP/IP to Serial Module,300~115200 BPS Baudrate,10 / 100M Auto-Negotiation RJ45 Connector Amazon.de

Thanks in advance!

I did a workaround and with that you can get the data every minute, but quicker than 1 minute is not possible because of the “too much requests” error.
And i can also controll the CMI in Home Assistant without the Modbus integration.

Hi Biscuit :slight_smile:
Can that Node-red Modbus integration be used with esphome and modbus rtu? I have a Growatt inverter and I want to emulate an SDM630 smart meter, is this possible with node-red?

As far as I know, yes.
I did experiment with this and successfully managed to create a Modbus server inside Node-RED. I have always used Modbus over TCP. It should all be possible over RTU provided the hardware can be seen by HA/Node-RED, but I have no personal experience with RTU.

The hardest part, for me, was getting my head around what was the server and what was the client.
Good luck.

1 Like