I’m trying to configure the serial sensor, which sends data from 40 sensor values separated with space every 2 seconds as a string. I haven’t managed to do so where the serial sensor is only returning the unknown state. Via terminal, I can easily see data coming in with the command: minicom -D /dev/ttyAMA0, but for some unknown reason, the serial sensor and template created sensor state stays at unknown status. Can anyone suggest what I’m missing/forgetting on this setup?
Currently, only half of the sensors are enabled so the length is not the issue. When everything is enabled serial response is designed to be between 200 to 250 characters.
Yep, that value template was my last try to get this working. Without it when the sensor is the sensor.rpict state status is still unknown
When I play with Developer Tools - Template area and try to put statements there
{{ states('sensor.rpict') }}
I get the result that the state is unknown. And if I put the following statement there:
{{ states('sensor.rpict').split(' ')[1] }}
I will get an error message of list object has no element 1
So now I’m wondering that do I need to somehow enable serial data reading inside of Home Assistant to get it working (SSH to server and using terminal serial reading works).
Yep, you were right on your hunch that this was caused over-long serial response. with that value_template limitation, I got main sensor values coming visible at HA.
Thanks for helping in this serial case.
Now I just need to figure out how to get around this limitation.
I have been struggling with getting a functional serial sensor as well. I have the same symptom, in that I can use minicom and see the serial data being received. Short “this is a test” data is sent by a separate computer using putty. I can even send data to that other computer using shell_command.
Unfortunately, message size does not appear to be my issue. My applogies in advance for any formatting issues or other faux pas. Posting here because “The solution doesn’t work for” me.
An interesting update:
I formatted several test messages within docklight. Some messages are successful, others are not. It would appear that the ONLY successful messages include a \n (line feed) at the end. If line feed is included mid-message, the sensor will report the character sent preceding the line feed.
Indeed, if a message was sent without line feed, that message stays in buffer until line feed:
e.g.
sends: this is a test
sensor = “unknown”
sends: this is a second test \n
sensor = “this is a testthis is a second test”
“{{ value[:250] }}” was not a necessary condition for these short test messages