Configuration relay board type R421A08 - RS485 MODBUS RTU

Greetings to the community.

I opened this topic to ask you for help configuring the relay board R421A08
image
My configuration:
raspberry pi2,


and this USB to RS485 adapter
image
(This adapter works well with raspberry + hassio because I use it to read energy consumption data from an EASTRON SDM220-MODBUS.image)

I did some tests and I could not make the R421A08 relay card work.
I used “Modbus Switch” but I did not succeed.

On the web I found this that could help us:

https://forum.logicmachine.net/showthread.php?tid=1403

Some of you much more expert than me could help me, with the code to be written?
Thank you very much.

  1. Install the GitHub code

  2. Control via command line component.

Thanks for the reply but I still can not understand what I have to do. Could you help me?

I follow…

I tried to do a lot of tests.
I changed the register, but I’ve never been successful.

For the register I followed these links:




https://forum.logicmachine.net/showthread.php?tid=1403

Some registers are in the comments.

What am I doing wrong?
I saw that the communication LED sometimes flashes.
This is the last code loaded:

modbus:
  type: serial
  method: rtu
  port: /dev/ttyUSB0
  baudrate: 9600
  stopbits: 1
  bytesize: 8
  parity: N


switch:
  platform: modbus
  slave: 1
  coils:
    - name: R1
      slave: 1
      coil: 40101
    - name: R2
      slave: 1
      coil: 40002
  registers:
    - name: R3
      slave: 1
      register: 40002
      command_on: 1
      command_off: 0
    - name: R4
      slave: 1
      register: 40003
      command_on: 1280
      command_off: 0
    - name: R5
      slave: 1
      register: 40104
      command_on: 01
      command_off: 00
    - name: R6
      slave: 1
      register: 01
      command_on: 1
      command_off: 0

Please can someone help me?
Thank you very much.

I have the same problem.
Has anyone got the solution?
This equipment accect function Preset Multiple Registers (FC=16), but the HA write registers whith de function Preset Single Register (FC=06).
Has anyone know implement this function in HA?

I found a solution that works but I do not get feedback from the relay module.

I wrote a script in python, which uses the mobuspy and is called by a button in the homeassistantt with command line.
My file calls 8O.py, and the id RS485 is 7.

My scripy in python:
#!/usr/bin/python

#---------------------------------------------------------------------------# 
# import the various server implementations
#---------------------------------------------------------------------------# 
from pymodbus.client.sync import ModbusTcpClient as ModbusClient
# from pymodbus.client.sync import ModbusSerialClient as ModbusClient
from pymodbus.transaction import ModbusRtuFramer as ModbusFramer
#---------------------------------------------------------------------------# 
# configure the client logging
#---------------------------------------------------------------------------# 
import logging
import sys

# parametros de entrada
relay = int(sys.argv[1])
value = int(sys.argv[2])

logging.basicConfig()
log = logging.getLogger()
log.setLevel(logging.DEBUG)
#Define Modbus Target Device
client = ModbusClient(host='192.168.1.10',port=502)
connection = client.connect()
print (connection)
# send write command to modbus server
#600= off 300 = on
register_value = client.write_register(relay, value, unit= 7)
client.close()

#---------------------------------------------------------------------------# 

In configuration.yaml:

  • platform: command_line
    switches:
    switch_1:
    command_on: ‘python3 /config/8O.py 1 300’
    command_off: ‘python3 /config/8O.py 1 600’

Please please follow the instructions at he top of the page and format your code properly.

Windows application for STM8S103 & R421A085 module

Use this utility to toggle the relay settings. Ideal for Windows 7.

Written in MS Visual Studio WIN32 C++.

https://sourceforge.net/projects/rs485modbus/

What has this to do with home assistant?

For 4 channel 4CH Modbus RTU relay module 4 ch relay module rs485
In configuration.yaml:

modbus:
  - type: serial
    name: hubrelay
    method: rtu
    port: /dev/ttyUSB1
    baudrate: 9600
    stopbits: 1 
    bytesize: 8
    parity: N
    timeout: 1
    
switch:
  - platform: modbus
    registers:
      - name: Relay1 
        hub: hubrelay
        slave: 1
        register: 1
        command_on: 256
        command_off: 512
        state_on: 1
        state_off: 0
      - name: Relay2 
        hub: hubrelay
        slave: 1
        register: 2
        command_on: 256
        command_off: 512
        state_on: 1
        state_off: 0
      - name: Relay3 
        hub: hubrelay
        slave: 1
        register: 3
        command_on: 256
        command_off: 512
        state_on: 1
        state_off: 0
      - name: Relay4 
        hub: hubrelay
        slave: 1
        register: 4
        command_on: 256
        command_off: 512
        state_on: 1
        state_off: 0