Modbus relay status verification when device does not support reading individual coils

This is my device: 8-ch Ethernet Relay Module, Modbus RTU/Modbus TCP Protocol, PoE port Communication and its docs for Modbus TCP Modbus POE ETH Relay – Waveshare Wiki

While my question is ultimately about Home Assistant configuration, it uses Pymodbus so its sort of a both. How can I get HA to use pymodbus correctly …

The device only supports reading all coils, not individual coils. So, I can’t read the
status of individual relays. I can only read the status of all relays at once.

I have tested in this in pymodbus and verified that this is indeed the issue.

Reading one coil fails

# Read coils
try:
    result = client.read_coils(address=0, count=1, unit=1)
    if result.isError():
        print(f"Error reading coils: {result}")
    else:
        print(f"Coil status: {result.bits}")
except Exception as e:
    print(f"Exception occurred: {e}")

# Close the client
client.close()

Logs

DEBUG:pymodbus.logging:Connection to Modbus server established. Socket ('192.168.0.129', 51038)
DEBUG:pymodbus.logging:Current transaction state - IDLE
DEBUG:pymodbus.logging:Running transaction 1
DEBUG:pymodbus.logging:SEND: 0x0 0x1 0x0 0x0 0x0 0x6 0x0 0x1 0x0 0x0 0x0 0x1
DEBUG:pymodbus.logging:New Transaction state "SENDING"
DEBUG:pymodbus.logging:Changing transaction state from "SENDING" to "WAITING FOR REPLY"
DEBUG:pymodbus.logging:Transaction failed. (Modbus Error: [Invalid Message] No response received, expected at least 8 bytes (0 received)) 
DEBUG:pymodbus.logging:Processing: 
DEBUG:pymodbus.logging:Frame check, no more data!
DEBUG:pymodbus.logging:Getting transaction 1
DEBUG:pymodbus.logging:Changing transaction state from "PROCESSING REPLY" to "TRANSACTION_COMPLETE"
Error reading coils: Modbus Error: [Input/Output] Modbus Error: [Invalid Message] No response received, expected at least 8 bytes (0 received)

Reading all coils in a row works

# Connect to the client
if client.connect():
    log.debug('Connection to Modbus server established.')
    try:
        # Attempt to read 8 coils
        result = client.read_coils(0, 8, unit=1)
        if result.isError():
            print(f"Error reading coils: {result}")
        else:
            # Print status of each coil
            status = result.bits
            for i in range(len(status)):
                print(f"Relay {i+1} status: {'ON' if status[i] else 'OFF'}")
    except Exception as e:
        print(f"Exception occurred: {e}")
    finally:
        client.close()
        log.debug('Connection to Modbus server closed.')
else:
    log.error('Unable to connect to Modbus server.')

Logs

DEBUG:pymodbus.logging:Connection to Modbus server established. Socket ('192.168.0.129', 51039)
DEBUG:root:Connection to Modbus server established.
DEBUG:pymodbus.logging:Current transaction state - IDLE
DEBUG:pymodbus.logging:Running transaction 1
DEBUG:pymodbus.logging:SEND: 0x0 0x1 0x0 0x0 0x0 0x6 0x0 0x1 0x0 0x0 0x0 0x8
DEBUG:pymodbus.logging:New Transaction state "SENDING"
DEBUG:pymodbus.logging:Changing transaction state from "SENDING" to "WAITING FOR REPLY"
DEBUG:pymodbus.logging:Changing transaction state from "WAITING FOR REPLY" to "PROCESSING REPLY"
DEBUG:pymodbus.logging:RECV: 0x0 0x1 0x0 0x0 0x0 0x4 0x1 0x1 0x1 0x0
DEBUG:pymodbus.logging:Processing: 0x0 0x1 0x0 0x0 0x0 0x4 0x1 0x1 0x1 0x0
DEBUG:pymodbus.logging:Factory Response[ReadCoilsResponse: 1]
DEBUG:pymodbus.logging:Adding transaction 1
DEBUG:pymodbus.logging:Frame check, no more data!
DEBUG:pymodbus.logging:Getting transaction 1
DEBUG:pymodbus.logging:Changing transaction state from "PROCESSING REPLY" to "TRANSACTION_COMPLETE"
Relay 1 status: OFF
Relay 2 status: OFF
Relay 3 status: OFF
Relay 4 status: OFF
Relay 5 status: OFF
Relay 6 status: OFF
Relay 7 status: OFF
Relay 8 status: OFF
DEBUG:root:Connection to Modbus server closed.

Given all that, how can I use the verify configuration of a Modbus Switch to check the status?

My main issue is that I need to verify the status of the relays so my switches in Home
Assistant are in sync with the actual status of the relays. I’m using “normally closed”
on some relays and those ones in particular are not working as expected in Home
Assistant.

Thanks!

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật