How to toggle a relay from a modbus serial port module from HA


I am a very beginner in HomeAssistant and I just would like to turn on/off some lights from my smartphone…

I have installed:

  • HA in a raspberry pi 4
  • on modbus serial port module
  • 16 relays card

From HA terminal, if send [echo -ne “AT+T5” > /dev/ttyUSB0] my relay toggles [OK]
How to control this from a card in the overview?
I have to create a entity and services in configuration.yaml or use some python script or other?

I read many web pages and I found only this:
in file /conf/configuration.yaml
type: serial
method: rtu
port: /dev/ttyUSB0
baudrate: 9600
stopbits: 1
bytesize: 8
parity: N

Your lights are not modbus controlled. You can not use that integration.

Create a shell command with your terminal command:

Then once you can make the relay toggle by calling that shell command (use the developer tools services menu to test it), use it in a template switch for both the turn on and turn off service:

Thanks for this so quick answer!
Looks like I didn’t seek in the good way…
I gonna read your links
Thanks again!