Modbus Connection to (xxx.xxx.xxx.xxx, xxx) failed: [Errno 111] Connection refused

Hi,
I’m just playing around with my HA in preparation of the real installation next spring.
I’m struggling with the modbus integration – It look like the HA isn’t able to connect to my Modbus TCP slave at all.

The error message says “Connection to (192.168.0.97, 502) failed: [Errno 111] Connection refused”

In my config file I implemented “modbus: !include modbus.yaml” and the modbus.yaml looks this way:

# cat modbus.yaml
# configuration entry for a TCP connection
# com.teltonika.rut955  slave: 100
 
# system :
  - name: teltonika
    retry_on_empty: true
    retries: 10
    type: tcp
    host: 192.168.0.97
    port: 502

    sensors:
     - name: System uptime
       unit_of_measurement: min
       slave: 100 #The number of the slave (Optional for tcp and upd Modbus)
       address: 1 #Address of the Register 
       count: 2 #Number of Registers to read
       input_type: holding #type of address (discrete_input/coil/holding)
       data_type: uint32 #Response representation (int8, int16, int32, int64, uint8, uint16, uint32, uint64, float16, float32, float64, string)
       scan_interval: 10 #update interval of the entity in seconds

     - name: Modem ID
       slave: 100
       address: 328
       count: 8 
       data_type: string 
       scan_interval: 30

My first question – is my assumption correct that this is more an connection (network) problem rather than a configuration problem?

Second question – naming of the parameters - I have in HA documentation

address: 328
count: 8

but the documentation of my slave provides me with

Register Address
Register Number
and 
Number Of Registers

so my assumption is

Register Address <-> address
Number Of Registers <-> count

and I don’t need the Register Number …. ?

kind regards
Tobias Blattner

Network issue, or you need ip whitelist in modbus slave

Try add

    delay: 1
    timeout: 3

Maybe is hex vs decimal only diference

Hi,
thanks for the tip - unfortunately it still isn’t working … I think it’s the slave who is refusing to accept incoming connections.
Because when I simplify my setup by running ModSim on my computer I get at least an connection – no valid values so far but at least a connection.

I set my ModSim (LongInt) Register to 111111 and HS displays 65536 :man_facepalming:

Hi,

just to let you and everyone else know:
It turns out that the Teltonika RUT955 MODBUS TCP SLAVE isn’t working under firmware RUT9_R_00.07.02.7 - With an older Version (RUT9XX_R_00.06.07) it is working without any problems.

Regarding “Register address” and “Start Address” from the RUT_Wiki - the Register Number need to be the Start Address.

So, for example:

For System Uptime (Register number = 2) you would set:

Start address = 2
Number of registers = 2

For System temperature (in 0.1 °C) (Register number = 6) you would set:

Start address = 6
Number of registers = 2

Here is my modbus.yaml for the two mentioned values from above:

# cat modbus.yaml
# configuration entry for a TCP connection
# com.teltonika.rut955  slave: 1
 
# system :
  - name: teltonika
    retry_on_empty: true
    retries: 10
    type: tcp
    host: 192.168.0.97
    port: 502
    delay: 1
    timeout: 3
# REMARK: scan_interval: <5 can cause troubles
    sensors:
     - name: System uptime
       unit_of_measurement: no idea
       slave: 1 #The number of the slave (Optional for tcp and upd Modbus)
       address: 2 #Address of the Register 
       count: 2 #Number of Registers to read
       input_type: holding #type of address (discrete_input/coil/holding)
       data_type: uint32 #Response representation (int8, int16, int32, int64, uint8, uint16, uint32, uint64, float16, float32, float64, string)
       scan_interval: 5 #update interval of the entity in seconds
       scale: 1.0 #In ?
       precision: 0 #Number of decimals 

     - name: System temperature
       slave: 1
       address: 6
       count: 2 
       data_type: uint32 
       scan_interval: 5 
       scale: 0.000001 #In 0.1°C
       unit_of_measurement: °C
       precision: 2

So I hope one day this will help some fellow adventurer :sunglasses: and save him some time!

Kind Regards
Tobi

3 Likes