Since 0.108 1-3 the modbus integration is broken (status from April 14th). And as I already run a NodeRed instance in HA I want to share my solution to poll “input registers” from my SMA Inverter in NodeRed and post the register values via MQTT. So in HA you only configure corresponding MQTT sensors and everything works again.
OK let’s start:
grab a “Modbus Read” block and drag in in your working area.
in the server field create a new modbus client and enter the same data you used in the modbus intzegration in HA.
my modbus integration looked like this:
modbus: name: sma type: tcp host: 192.168.178.101 port: 502
and this is the corresponding modbus client in NodeRed
to read a group of input registers into a buffer you specify the start register and number of 16 bit values to read.
so my modbus sensors definition looked like this:
sensors: - platform: modbus scan_interval: 30 registers: - name: yield_total hub: sma unit_of_measurement: kWh slave: 3 register: 30513 register_type: input count: 4 - name: yield_day hub: sma unit_of_measurement: kWh slave: 3 register: 30517 register_type: input count: 4
and this is the corresponding modbus read block
this results in a buffer with 8 values representing input register addresses 30513-30520.
Now use an inject block and configure it to trigger a repeating message in the interval you want the modbus registers to be polled and connect the output of the inject block with the modbus read block.
now drag two “mqtt out” blocks and configure them to send the payload to a mqtt topic of your choice.
the end result looks like this
in HA define two mqtt sensor instead of the modbus sensors like this
- platform: mqtt name: "yield_total" state_topic: "sma/4/4" device_class: "power" unit_of_measurement: "Wh" - platform: mqtt name: "yield_day" state_topic: "sma/4/8" device_class: "power" unit_of_measurement: "Wh"
This should do the trick.