Hi, I am trying to integrate my HVAC system into home assistant that supports Modbus RTU. However, troubleshooting this via home assistant may be close to impossible, so first I am trying to read out basic values of the Modbus register via a windows tool, but so far without any luck.
I got the description of the modbus protocol from the manufacturer Microsoft OneDrive - Access files anywhere. Create docs with free Office Online. and try to use EasyModbus to read out the values, however I don’t seem to get anything meaningful. For example, the register 15017 is supposed to report some kind of temperature, but from EasyModbus i get the value -22528 modbus - Album on Imgur
Can anybody point me into the right direction how to get this work?
thanks @nikito7 . i managed to get some meaningful readings via ModScan64 and it shows the correct temperatures reported on the HVAC units display as well.
however home assistant somehow refuses to connect to the device, showing the following.
Pymodbus: HVAC: Modbus Error: [Connection] ModbusTcpClient(192.168.50.208:502): Connection unexpectedly closed 0.000048 seconds into read of 8 bytes without response from unit before it closed connection
Can you recommend me how to get out the readings via Modbus from the command line without needing to constantly modify configuration.yaml and restarting home assistant with each change?
@tom_l i meant a 3rd party tool that i could use to connect to modbus to check the reprted values and only add them to my HA config when i know what to add. ModScan kinda works, but the free version has some annoying limitations and its windows only - i’d like to connect from the machine where HA is running to eliminate potential firewall issues. i’ve looking at PyModbus, but it’s rather a library i can call from my own scripts which is beyond my knowledge, i’d prefer a simple binary
You can use pymodbus, but you need decode manually, or do the parsing code
#!/usr/bin/env python
"""
Pymodbus Synchronous Client Examples
--------------------------------------------------------------------------
The following is an example of how to use the synchronous modbus client
implementation from pymodbus.
It should be noted that the client can also be used with
the guard construct that is available in python 2.5 and up::
with ModbusClient('127.0.0.1') as client:
result = client.read_coils(1,10)
print result
"""
# --------------------------------------------------------------------------- #
# import the various client implementations
# --------------------------------------------------------------------------- #
from pymodbus.client.sync import ModbusTcpClient as ModbusClient
# from pymodbus.client.sync import ModbusUdpClient as ModbusClient
# from pymodbus.client.sync import ModbusSerialClient as ModbusClient
# --------------------------------------------------------------------------- #
# configure the client logging
# --------------------------------------------------------------------------- #
import logging
FORMAT = ('%(asctime)-15s %(threadName)-15s '
'%(levelname)-8s %(module)-15s:%(lineno)-8s %(message)s')
logging.basicConfig(format=FORMAT)
log = logging.getLogger()
log.setLevel(logging.DEBUG)
UNIT = 0x1
def run_sync_client():
# ------------------------------------------------------------------------#
# choose the client you want
# ------------------------------------------------------------------------#
# make sure to start an implementation to hit against. For this
# you can use an existing device, the reference implementation in the tools
# directory, or start a pymodbus server.
#
# If you use the UDP or TCP clients, you can override the framer being used
# to use a custom implementation (say RTU over TCP). By default they use
# the socket framer::
#
# client = ModbusClient('localhost', port=5020, framer=ModbusRtuFramer)
#
# It should be noted that you can supply an ipv4 or an ipv6 host address
# for both the UDP and TCP clients.
#
# There are also other options that can be set on the client that controls
# how transactions are performed. The current ones are:
#
# * retries - Specify how many retries to allow per transaction (default=3)
# * retry_on_empty - Is an empty response a retry (default = False)
# * source_address - Specifies the TCP source address to bind to
# * strict - Applicable only for Modbus RTU clients.
# Adheres to modbus protocol for timing restrictions
# (default = True).
# Setting this to False would disable the inter char timeout
# restriction (t1.5) for Modbus RTU
#
#
# Here is an example of using these options::
#
# client = ModbusClient('localhost', retries=3, retry_on_empty=True)
# ------------------------------------------------------------------------#
client = ModbusClient('10.3.0.223', port=9502)
# from pymodbus.transaction import ModbusRtuFramer
# client = ModbusClient('localhost', port=5020, framer=ModbusRtuFramer)
# client = ModbusClient(method='binary', port='/dev/ptyp0', timeout=1)
# client = ModbusClient(method='ascii', port='/dev/ptyp0', timeout=1)
# client = ModbusClient(method='rtu', port='/dev/ptyp0', timeout=1,
# baudrate=9600)
client.connect()
log.debug("Read input registers")
rr = client.read_input_registers(1, 1, unit=UNIT)
assert(not rr.isError()) # test that we are not an error
# ----------------------------------------------------------------------- #
# close the client
# ----------------------------------------------------------------------- #
client.close()
if __name__ == "__main__":
run_sync_client()