HA send serial data to arduino over USB

Hi there

I’m new to Home Assistant, i started to use it yesterday and i would like to know if i could send serial data throught USB to my arduino.

Let me explain, I have an arduino with a RF433mHz module and physical switches who controll all the lamp of my living room. I would like to be able to control them with HAss as weel.

Can HAss send serial ober USB to my arduino so that it can send the right RF code ?


Hi, did you ever get an answer or work out a solution to this problem?
I am also attempting to do the same, I have a 4X4 LED Cube thats attached to an Arduino board that I configured to listen to commands via serial and display the current weather. (simple letters represent weather , r = rain, b = blue sky etc)
I’d love for my HA to be able to write serial commands to the cube via an automation script or similar

Hi Will,

I didnt get a solution to work out, cause i used an esp8266 instead of an arduino so i send my messages throught wifi via MQTT.

But for your problem the only solution seems to have a python script with Pyserial. And then i guess you can talk to the python with HASS.
Or maybe just a python script who send a letter in serial and then close, in HASS you should be able to launch this script with a command line switch i guess.

Let me know if you make it work

if you edit the arduinocode and make a mysensors gateway from it you can use mysensors to get data to your arduino.

Sounds like the simplest solution should be to create some scripts that works from the command line and call them from HA using shell_command

I don’t know for sure, but it might be possible to send some characters directly to the serial port too, with a shell command like:

echo -e -n "\x41\x54\x0a" > /dev/ttyUSB0 

http://defindit.com/ascii.html has an ascii->hex table.

If you want to pipe chars you probably need to set the baud rate aswell. sudo stty -F /dev/ttyUSB0 9600


Thanks team. Looks like I can simply write echo -e -n “s” > /dev/ttyACM1 using shell_command as above.

Next issue I have is trying to write a script or automation around it.
I might start another thread for this next bit as my original question has been answered clearly enough for me to get to the next step.

Thank you team

Actually, it worked via putty, but when running my script via HA it must have sent something other than my requested letter as it showed my default animation.
echo -e -n "\x73" > /dev/ttyACM1
echo -e -n "s" > /dev/ttyACM1
both show s on the terminal, and play the correct animation on the cube.

Any way to see what HA is actually sending via ACM1?
If I can send via terminal without setting the baud rate, should I be ok not setting in HA?

My shell command config:
shell_command: cube_clear: echo -e -n "\x73" > /dev/ttyACM0 cube_cloud: echo -e -n "c" > /dev/ttyACM0 cube_mostcloud: echo -e -n "p" > /dev/ttyACM0 cube_rain: echo -e -n "r" > /dev/ttyACM0 cube_wind: echo -e -n "w" > /dev/ttyACM0 cube_nightcloud: echo -e -n "o" > /dev/ttyACM0 cube_clearnight: echo -e -n "n" > /dev/ttyACM0 cube_lasers: echo -e -n "l" > /dev/ttyACM0 cube_dblcube: echo -e -n "b" > /dev/ttyACM0 cube_fade: echo -e -n "q" > /dev/ttyACM0

1 Like

Hi guys, I was having an issue where HA would send a shell command but the Arduino Uno wouldn’t action it. The problem was the uno was halting the program because there was no serial feed back. I opened an SSH session and ran “cat -v /dev/ttyACM0” and that allowed the uno to continue the program, even though there is actually no serial feed back from the uno (the SSH session just remains blank).
So I’ve inserted the cat command prior to the initial command using a pipe “|” to seperate them and it now seems to work okay. Example below:

  platform: command_line
        command_on: 'cat -v /dev/ttyACM0 | echo -e -n "<PatioLight,Off>" > /dev/ttyACM0'
        command_on: 'cat -v /dev/ttyACM0 | echo -e -n "<PatioLight,On>" > /dev/ttyACM0'    

Hope this helps someone :slight_smile:

1 Like

Maybe me.

I was enamored by screen shots over at openHAB and tried to figure out how to make openHAB2 the front end for my home-built Arduino-over-USB system. Their documentation is written by folks whose first language is NOT English. So I’m here now, and this thread is extremely similar to what I need.

Question: Have you got a nice-looking browser-rendered front end working for this? My system is entirely functional, but only at the CLI level. I want to get to a nice-looking Dashboard GUI level now. Thanks!!!

My system: Ubuntu 15.10 CLI with self-designed shell scripting link to USB-connected Arduino running self-written thermostat code (DHT11 & DHT22 capable) with pin control-via-serial-commands sketch. Data sent to server from Arduino is captured by a daemonized ‘cat’ command with logfile storage. I’m able to grep the logfile to view the furnace cycle timings, etc. The ‘cat’ daemon replaces the word “timestamp_this” from Arduino with current date/time. SSH into server allows me full control over all Arduino pins via a set of control and query commands I wrote into the sketch. Linux ‘at’ commands schedule coffee maker and front porch light electrical supply. I’m heavy into writing Arduino interrupt code, so I can make it monitor for pin changes, etc. and alert the server. By careful coding to avoid memory leaks and fragmentation, the Arduino has given me perfect reliability for a couple years, so I couldn’t be more pleased with how I have everything connected and task-assigned. I have a degree in electronics, so I’m saavy enough to be bothered by the common ground going through the USB port, but that is my only layout concern.

Hi Kenneth,
I have HomeAssistant running on a raspberry pi, on hassbian which is basically Linux. The front end is totally GUI through a web browser. It does take a bit of setting up getting used to YAML scripting.
Theres quite a few guides and Configs shared on the website which are helpful to get things up and running.
I use direct rasperrypi USB to one Arduino with no feed back. I have another on the network that does a bunch of remote tasks that I control over MQTT.

Yes, I haven’t worked with it at all and figure I’ll need to do some studying of those guides. Right now, I’m giving another chance to openHAB just to make sure I’m being fair. Made more progress so I’m encouraged…

Thanks for your reply!

Hi I think it can make my day. I got a beetle arduino plugged on my Odroid C4. I want to control a switch like u did. Do you have the associated arduino code ? where you connected your relay (pin ?)


EDIT… I wrote a small arduino and it works flawless :slight_smile: Thanks