Ser2net - Raspberry PI as remote RS232/Serial device controller

I have an original raspberry PI set up in another room, with a USB to serial cable and Ser2net running so I can control a Octava HDMI Matrix switch remotely (currently being done via my Vera home automation controller)

local socket = require("socket")
host = "192.168.1.77"
c = assert(socket.connect(host, 4001))
c:settimeout(5)
local sres, serr = c:send(string.char(0x02,0x32,0x31,0x31,0x03))
print("Send:", sres, serr)
local data, rerr = c:receive(100)
luup.log (data)
print ("Receive:", data, rerr)
c:close()

Now - I have to hold my hands up and say that I had a huge amount of help creating the LUA code above that sends the required value, but I was wondering if there was a way I could send the same information via Home Assistant ?

If it helps , here is my ser2net.conf entry for that port on the remote PI I target .

4001:raw:600:/dev/ttyUSB0:9600 NONE 1STOPBIT 8DATABITS -XONXOFF -LOCAL -RTSCTS

For those that do not know ser2net as I understand it, its an service that listens to a TCP port and pipes data to and from a serial port via the TCP port. It is configured by the file /etc/ser2net.conf and is run on the machine with the serial port that you want to make available over TCP/IP

A command_line switch with your code or a shell_command could do the work.

Many thanks, however what would the command line or shell command be for such a command ?

At it is ser2net, I was hoping something like the ‘TCP Sensor’ could work here. https://home-assistant.io/components/sensor.tcp/

Here is a mock up.

sensor:
  platform: tcp
  name: Switch HDMI Matrix to Input 1A
  host: 192.168.1.77
  port: 4001
  timeout: 5
  payload: "0x02,0x32,0x31,0x31,0x03"

Thoughts?

OK, well this is interesting…

I have created a group for the above TCP Sensor and it is actually getting information back from the HDMI matrix in the other room over ser2net…

It is giving me an error, which suggests something is being sent, and Home Assistant is receiving the feedback, which looks to be it’s standard error response from the Octava HDMI matrix i’m testing against. (I can’t see it all)

"0 ** invalid input. Refer to install guide or FAQ ... ."

http://www.octavainc.com/image/install_guide_pdf/4x2%20HDMI%20Matrix/4x2%20HDMI%20Matrix%20Switch%20Install%20guide-1213-11’-web.pdf

Here is the Octava’s manual entry for the serial connection

By the looks of this, it is sending the command or checking for a response all the time ?

Can anyone confirm what is being seen here (exactly) ? My assumption is that it is constantly reading what the Matrix last said, but is the payload in the code earlier being sent every time to do that ?

Zooming into one of the entries, I see this, but other can just be a ‘0’ or partials of the following…

Any thoughts on how I can send a single payload over TCP, and see the results?

Still hoping for some help / advice if anyone has the time (many thanks)

Hi, if anyone is able to look at this I would appreciate any help to get this to work…

Ever the eternal optimist - still hoping someone can help me with this.

How can HASS send a HEX value to a serial device over TCP via a Home Assistant component or a command line ser2net config ?

did you get anywhere with this? im looking to do the same for my sony av reciever using a lantronix IDS 10 IP-serial converter

cheers

So I know this thread is a year old but I am actually in the market for a Octava UHD41-ARC (the newer version of the HD41-ARC) and of course I want to remote control it.

My first thought was the rs232 port because the manual so helpfully lists the HEX codes though I am leaning towards an IR transmitter so I can control more than just the UHD41 in the media cabinet; however, I will control everything via ser2net/socat.

Assuming you have ser2net and socat setup correctly, can you send a command from your HA server with socat to the PI running ser2net? I feel like the best approach is to use the Shell Command component to send the serial commands. HA doesn’t need to be aware of the device itself - a shell command just seems easier.

So from your HA server can you send a command like this (update to your correct port):

socat /dev/ttyUSB0,\x02\x32\x31\x32\x03,raw,echo=0,crnl

This should set the device to input port 2.

i ended up buying a broadlink rm mini IR blaster. Although added it to HA, ive not fully configured yet

Hmm, I wasn’t aware of that product. I am going to do the same and try the RM Mini.

I figure by the time I buy a PI Zero, install the IR emitter, and spend an hour or so configuring it I am already past the $24 the Broadlink costs and my solution won’t look at nice.

Thanks for the info.