Ability to add multiple modbus hubs

This is fairly fresh implementation of modbus hubs and as I am using the OLD workaround then I think that’s about as much as I can help sorry.

The only other thing to double check…is your indentation correct?

Maybe someone else who has used this successfully may drop by?

Quick update on this subject.
Today I installed HA 0.89.2 in a new docker on my QNAP NAS.
The install went well and I have my fallback installation ready to start again if needed.

After logging in I updated the config.yaml with all my sensors, switches and binary sensors and found all my MQTT devices were working as expected. Also as expected all the modbus devices were not.

So I modified the modbus connection information as per the instructions in the documentation and added the hub: myHub info to all my devices.

On starting up the container and logging in again I found not one modbus device was connected and there were multiple errors and warnings in the log.

I had a good look at the documentation again

# Example configuration.yaml entry for multiple TCP connections
modbus:
  - type: tcp
    host: IP_ADDRESS_1
    port: 2020
    hub: hub1

  - type: tcp
    host: IP_ADDRESS_2
    port: 501
    hub: hub2

and after some thought I decided to try the below

#
# 
#Start Modbus Hub5
#########################################
modbus:
  - type: tcp
    host: myIP
    port: 5003
    name: hub5
#########################################    
# Meter Box PLC 
#IP: myIP
#Local Port: 5003
#Slot: 5    
#########################################
#End Modbus Hub5
#    
#Start Modbus Hub3
#########################################
  
  - type: tcp
    host: myIP
    port: 5001
    name: hub3
#########################################
# Master PLC
#IP: myIP
#Local Port: 5001
#Slot: 3
#########################################
#End Modbus Hub3                             
#
#Start Modbus Hub1
#########################################
  
  - type: tcp
    host: myIP
    port: 5002
    name: hub1
#########################################    
# Slave PLC 
#IP: myIP
#Local Port: 5002
#Slot: 1
#########################################
#End Modbus Hub1
#

On starting up and checking there were a couple of minor warnings and one error but it seemed like all the devices were connected and working in dev-state anyway.

A quick look through my ui showed random devices disconnected and others working.

Happy with that for tonight so I reverted to my existing (working) container for the night.

I will report back with more details once it’s all sorted.

UPDATE: Look here and the example config shown matches what I came up with that works for me. It appears the current modbus documentation may be incorrect or needs to be updated?

Cheers Steve Wells

Having a very quick look this morning and fixed a few typos I made in updating my config.yaml.

Result is that binary_sensors are the remaining problem which does gel with the one remaining error I have in my logs.

Invalid config for [binary_sensor.modbus]: expected int for dictionary value @ data['coils'][22]['coil']. Got None. (See /config/configuration.yaml, line 1268). Please check the docs at https://home-assistant.io/components/binary_sensor.modbus/

This is a snippet of what I have for my binary_sensor configuration…

#Start Binary Sensors
#########################################
#
binary_sensor:
#
#Modbus binary sensors
# NOTE: this is line 1268 referenced in the error message
  - platform: modbus
    coils:
#
#START hub5 binary sensors
#    
      - name: HW Tariff
        hub: hub5
        slave: 5
        coil: 1538
      - name: Front Occupied
        hub: hub5
        slave: 5
        coil: 1544

#END Modbus hub1 binary sensors

#After all the modbus sensors I have the MQTT ones
#START MQTT binary sensors
#
  - platform: mqtt
    name: "Pool Low Level"
    state_topic: "stat/sonoff23/POWER"
#    command_topic: "cmnd/sonoff23/POWER"
    availability_topic: "tele/sonoff23/LWT"
    qos: 1
    payload_on: "ON"
    payload_off: "OFF"
    payload_available: "Online"
    payload_not_available: "Offline"

To be honest I see no difference to the documentation example given for modbus binary sensors

For comparison sake, this is what I have for modbus sensors in my config…again all sensors are normal as are switches.

#########################################      
#
#
#START Modbus sensors
#
#
  - platform: modbus
    scan_interval: 10
    registers:
#########################################
#START Modbus hub5 sensors
#    
      - name: RTC YEAR
        hub: hub5
        slave: 5
        register: 3328
      - name: RTC MONTH
        hub: hub5
        slave: 5
        register: 3329

Can anyone advise a solution?

PS: My MQTT binary sensors are all unaffected it seems?

UPDATE: I had a look at the code in binary_sensor.py and I am wondering if (after reading the error message) it may be a matter of how the config items are ordered?

PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend({
    vol.Required(CONF_COILS): [{
        vol.Required(CONF_COIL): cv.positive_int,
        vol.Required(CONF_NAME): cv.string,
        vol.Optional(CONF_HUB, default=DEFAULT_HUB): cv.string,
        vol.Optional(CONF_SLAVE): cv.positive_int,
    }]
})

Maybe the config needs to be ordered in the same order as the platform schema above IE:

binary_sensor:
  - platform: modbus
    scan_interval: 10
    coils:
      - coil: 100
        name: Sensor1
        hub: hub1
        slave: 1

I’m off to try it anyway!
FURTHER UPDATE: My theory failed…modbus binary sensors appear to need some work it seems.

Friends, tell me in the modbus component there is no support for binary inputs (function 02)? Or is this option not documented? By analogy with binary coils (function 1) It probably should be written like this:

binary_sensor:
  - platform: modbus
    scan_interval: 1
    inputs:
      - name: Sensor1
        hub: hub1
        slave: 32
        input: 4
      - name: Sensor2
        hub: hub1
        slave: 32
        inputl: 5 

But this does not work.

Hey,

Anyone figured out how to make this work ?

Yup it’s working ace for me. Here’s a snip it of what I have running -


modbus:
  - type: tcp
    host: 172.17.1.202
    port: 502
    name: sma_battery
    
  - type: tcp
    host: 172.17.1.204
    port: 502
    name: sma_solar

  - type: tcp
    host: 172.17.1.205
    port: 502
    name: sma_meter

sensor sma:
- platform: modbus
  scan_interval: 1
  registers:
    - name: SMA Charge
      slave: 3
      register: 30845
      count: 2
      data_type: int
      hub: sma_battery
    - name: SMA Battery Flow
      unit_of_measurement: W
      slave: 3
      register: 30775
      count: 2
      data_type: int
      hub: sma_battery

What do you use the SMA meter for? Is this Home Manager 2? Never thought of connecting to this via Modbus…

Well the plan is to get the live feed data from it. However right now I can’t find any of the registers that work (I’ve not tried very hard though, not like the other two where it’s perfect).

I know it’s possible from the SMA Energy Meter as this software can show it. I think it does something over multicast but I’ve not sussed that out yet.

Hi everyone,
I’ve been interestedly following your discussion for a while and appreciate your work, since we will also get an SMA-based power plant.

Regarding the app that @cconnoruk mentioned, I found out that it is actually sending UDP multicast packets.

Dort sendet das Energy Meter über UDP Port 9522 an die Multicast-Adresse 239.12.255.254 . Die Adresse kann im Energy Meter und in der App eingestellt werden.

So according to the author you can configure the multicast address in the SHM2.0 but by default 239.12.255.254:9522 is used. It looks like the author (Heiko) was formerly employed as software developer at SMA.

Yup I just have no idea how to read that :slight_smile: … yet ;).

Once our system is running I hope I will have time to look into that :smile:. I guess sniffing some packets with Wireshark might already give some hints.

Yer I expect so … I just can’t be bothered enough ;).

SMA love the multicast, makes it a disaster on managed/corporate networks.

page 102 of the home manger 2(energy meter) details how to enable direct modbus polling to the home energy meter, However you will need installer access.