Can anyone provide me some basic Serial config and write/read samples for developing a custom intgeration? I would like to communicate via Serial port with an Arduino based board. I really would like to know how I can simply write and read to serial port from my custom integration.
Since i used to run my HA on a virtual HyperV machine.
This limited my options, as a serial port wasn’t available. I also didn’t want to end up pulling long cables either.
So I used serial2tcp and i ended up sending/receiving tcp with a EspHome module flashed with JeeLab
Let me clarify a bit what I would like to achieve. I made this RF USB dongle to wirelessly control mechanical home ventilations.
This will be connected to my Raspberry Pi and shows up as a virtual com port. To communicate with this USB dongle, I need to implement serial read and write commands. I would like to make my own custom HA integration for this. I already looked at: Link. But I think here it is not clear how to write to serial port?
At this moment, the USB dongle runs Firmata to communicate with HA, not optimal.
The idea of Firmata is to have control over Arduino’s IO’s in HA, that is not what I want to achieve, I would like to control and read out the actual the fan speed, this is done by sending RF messages with my onboard RF chip and report back to HA via Firmata. Currently I have to use the Firmata “light” entity for this, since I have to have an analog value. Instead I would like to use the FAN entity. Besides it seems that my implementation seems to lose connection after a few days for some reason, cannot find the reason for that. It might be much simpler to implement lightweight response/request communication protocol for sending/requesting FAN speed.
I thought it should be doable to create my own custom integration, since there are other integrations using serial read/write as well.
could you tell me, how you reach the sending and receiving data on the Serial port?
I have exactly the same issue like you - I want my own integration for my own device, which communicates with UART.
I have started with this example integraion detailed_hello_world_push
and try now to customize this for me with serial communication.
I would be very happy, if you (or someone) could help me!
Thank you for your answer!!
I have copied the 3 files in my custom_components folder, a new folder “serial”.
# Example configuration.yaml entry
- platform: serial
in the configuration.yaml and restart HA.
After I send something via UART, I get the following Log:
Integration: serial (documentation, issues)
First occurred: 01:11:55 (1 occurrences)
Last logged: 01:11:55
Error while reading serial device /dev/serial0: device reports readiness to read but returned no data (device disconnected or multiple access on port?)
Traceback (most recent call last):
File "/usr/src/homeassistant/homeassistant/components/serial/sensor.py", line 202, in serial_read
line = await reader.readline()
File "/usr/local/lib/python3.10/asyncio/streams.py", line 525, in readline
line = await self.readuntil(sep)
File "/usr/local/lib/python3.10/asyncio/streams.py", line 617, in readuntil
File "/usr/local/lib/python3.10/asyncio/streams.py", line 502, in _wait_for_data
File "/usr/local/lib/python3.10/site-packages/serial_asyncio/__init__.py", line 115, in _read_ready
data = self._serial.read(self._max_read_size)
File "/usr/local/lib/python3.10/site-packages/serial/serialposix.py", line 595, in read
serial.serialutil.SerialException: device reports readiness to read but returned no data (device disconnected or multiple access on port?)
I found out that the port is already used by nodered.
(My “Integration” is currently in nodered and this used the port).
When I stop nodered (also don’t start with boot), the error ’ device reports readiness to read but returned no data’ isn’t there anymore.
Now I try to find a serial-message I send, but I can’t find it…
(I changed the Baudrate in the sensor.py and the rest of the settings should work for me.)
I think the line CONF_SERIAL_PORT = “serial_port” says, that the serial_port: /dev/serial0 from the configuration.yaml should be used - am I correct?