Assistance sending ascii data through a usb to RS485 device

Hello! I am having trouble with knowing how to send serial ascii data from home assistant to an RS485 input of a device I built.
For many years(about 20), I have been using a home automation system I wrote in Visual Basic. The program kept growing over the years to the point that I needed to make a change for many reasons - too numerous to mention here. In the VB program, I would send data through a USB to RS485 converter, then to a RS485/Ethernet converter and onto the house network. At the other end, I have another RS485/Ethernet converter which then sends the RS485 data to the Mute box. The purpose of the Mute box is to control where audio announcements are heard on different floors of the house. The mute box receives a command such as “SZx1(crlf)” thru “SZx7(crlf)” which the box uses to mute any combination of 3 floors. This worked very well in the VB program so I am trying to switch it to Home Assistant.

I first added the RS485 converter to a USB port on HA and checked in “All Hardware” where I found the ID = “/dev/serial/by-id/usb-FTDI_FT232R_USB_UART_A10PF0PH-if00-port0”. I then added to the Yamal-Config file the following:

modbus:

  • name: Audio_zone
    type: serial
    method: rtu
    port: /dev/serial/by-id/usb-FTDI_FT232R_USB_UART_A10PF0PH-if00-port0
    baudrate: 9600
    stopbits: 1
    bytesize: 8
    parity: N

I also have the following in the Yamal-config file:

shell_command:
audz2: "printf ‘\x53\x5A\x78\x32\x0D\x0A’ > /dev/serial/by-id/usb-FTDI_FT232R_USB_UART_A10PF0PH-if00-port0

then in Automations, I execute a shell command as:

action: shell_command.audz2
metadata: {}
data: {}

This is what I understood from what I have read on how to do this but, obviously, it doesn’t work. I sure would appreciate any help from someone who can see where I have gone wrong.
Thanks

Please review the community guidelines on how to properly post YAML so it is readable.

I’m confused as why you are using modbus when it looks like a custom device that isn’t using the modbus protocol.

Have you considered using an esphome device?

It would make this setup less dependent on HA and expand options while decreasing complexity

Thank you for responding to my question. I have never used this forum before so I will take a look at the guidelines for YAML. The only reason I am using Modbus is that I had not found any other way to send data through the RS485 converter. Please let me know if there is. Everything I read said to use Modbus. The device I built just wants “SZx” and the number 1 thru 7 than a Cr Lf in RS485 format.

Thanks for your response. I had not considered using an esphome device because I knew nothing about them. After I read your response, I read up on ESP and will definitely consider the use of that the next time. Right now I would like to get what I have working since it has worked from my Visual Basic program for the past year.

I apologize for PeteRage, he should have provided the link.

The reason for this is that indentation is important! Just because HA accepted the YAML doesn’t mean it’s going to function like you think it should. There are helpful people here that are steeped in YAML/Python code that can spot errors of misindentation where HA cannot.

Thank you.

Hello! As to my dilemma with sending an ascii string out a usb port to my mute box, I have made a number of changes.
I removed Modbus from YAML config. and I changed the shell command to -

shell_command:
  audz2: 'stty -F /dev/ttyUSB0 9600 && echo -e "SZx2\r\n" > /dev/serial/by-id/usb-FTDI_FT232R_USB_UART_A10PF0PH-if00-port0'

If first sets the baud rate and then sends the code. I realize the baud rate only needs to be sent once when the system boots but I don’t think that would be a show stoper.

The shell command is executed as part of an automation as:

alias: Test
description: ""
triggers:
  - type: turned_on
    device_id: 196f740c17ce654994496861e6144750
    entity_id: b34e03dc6fd7154bc5de6aac7b172254
    domain: light
    trigger: device
conditions: []
actions:
  - action: shell_command.audz2
    metadata: {}
    data: {}
  - action: tts.speak
    metadata: {}
    target:
      entity_id: tts.piper
    data:
      cache: true
      media_player_entity_id: media_player.s10_dd7f_2
      message: test
mode: single

This allows me to trun on a light which causes the code to be sent and then speek. The speeking works every time but not the code to the mute box.
Any help would be greatly appreciated.

First, a caveat: What I know about shell commands is what I read in the documentation

What I read is that the shell command is the last section of the YAML Try putting your

shell_command:
  audz2: 'stty -F /dev/ttyUSB0 9600 && echo -e "SZx2\r\n" > /dev/serial/by-id/usb-FTDI_FT232R_USB_UART_A10PF0PH-if00-port0'

as the last section of your YAML.

I assume you did, but I have to ask, “When your ran your shell command in a terminal, one that was not part of HA, was is successful?”

stty -F /dev/ttyUSB0 9600 && echo -e "SZx2\r\n" > /dev/serial/by-id/usb-FTDI_FT232R_USB_UART_A10PF0PH-if00-port0

Would this assist with sending commands?

1 Like