Serial Sensor Stops after a while

Hello, I have a Home Assistant isnstallation on a Raspbery PI and I am trying to get vallues from a power sensor ( Current Cost ENVI,EnviR) connected with a USB serial interface:

 dmesg output:
    pl2303 1-1.5:1.0: pl2303 converter detected
    usb 1-1.5: pl2303 converter now attached to ttyUSB0

The system work for some time and then stops. I have noticed that the messages arriving in the serial port are in the form:

<msg><src>CC128-v1.48</src><dsb>02191</dsb><time>15:11:19</time><tmpr>23.5</tmpr><sensor>0</sensor><id>01008</id><type>1</type><ch1><watts>00535</watts></ch1></msg>

but some times the sensors send historical data as follows:

<msg><src>CC128-v1.48</src><dsb>02191</dsb><time>15:13:30</time><hist><dsw>02191</dsw><type>1</type><units>kwhr</units><data><sensor>0</sensor><h150>1.057</h150><h148>1.028</h148><h146>0.928</h146><h144>1.101</h144></data><data><sensor>1</sensor><h150>0.000</h150><h148>0.000</h148><h146>0.000</h146><h144>0.000</h144></data><data><sensor>2</sensor><h150>0.000</h150><h148>0.000</h148><h146>0.000</h146><h144>0.000</h144></data><data><sensor>3</sensor><h150>0.000</h150><h148>0.000</h148><h146>0.000</h146><h144>0.000</h144></data><data><sensor>4</sensor><h150>0.000</h150><h148>0.000</h148><h146>0.000</h146><h144>0.000</h144></data><data><sensor>5</sensor><h150>0.000</h150><h148>0.000</h148><h146>0.000</h146><h144>0.000</h144></data><data><sensor>6</sensor><h150>0.000</h150><h148>0.000</h148><h146>0.000</h146><h144>0.000</h144></data><data><sensor>7</sensor><h150>0.000</h150><h148>0.000</h148><h146>0.000</h146><h144>0.000</h144></data><data><sensor>8</sensor><h150>0.000</h150><h148>0.000</h148><h146>0.000</h146><h144>0.000</h144></data><data><sensor>9</sensor><h150>0.000</h150><h148>0.000</h148><h146>0.000</h146><h144>0.000</h144></data></hist></msg>

and I suspect that when this message arrives the sensor stops reading more data… (maybe a buffer overflow???)
my setup for the sensor is:

sensor:
  - platform: serial
    --my-rx-message-buffer-size=2046
    serial_port: /dev/serial/by-id/usb-Prolific_Technology_Inc._USB-Serial_Controller-if00-port0
    baudrate: 57600
    scan_interval: 0
  - platform: template
    sensors:
      my_power_sensor:
        friendly_name: PowerConsumption
        unit_of_measurement: "Watt"
        value_template: "{{ states('sensor.serial_sensor').split('<watts>')[1].split('</watts>')[0]}}"
      my_temperature_sensor:
        friendly_name: Temperature
        unit_of_measurement: "°C"
        value_template: "{{ states('sensor.serial_sensor').split('<tmpr>')[1].split('</tmpr>')[0]}}"
      my_sensor_time:
        friendly_name: Time
        unit_of_measurement: ""
        value_template: "{{ states('sensor.serial_sensor').split('<time>')[1].split('</time>')[0]}}"

I have also connected an arduino to send fake data (not historical data) hisin another serial sensor and it works fine.
Also when monitorring the serial port with picocon, all data are recevied to the piccom console!
Any help

I worked with this guy for a while and he came up with a fix for it. You can read the whole thread.

Basically, the serial integration isn’t catching an exception and closes completely until you restart HA.

I just checked and I don’t think he ever did manage making a pull request for the fix. I’ll go ahead and do that…but it will take a few weeks before it would make it into a build.

Creating a custom component is pretty easy. You just copy the entire folder to your config folder in custom_components, then modify copy the code I linked into the original sensor.py and restart HA.

Custom components with the same name will override built-in ones.

Hey. I made a pull request with the fix, see here: https://github.com/home-assistant/core/pull/33067#discussion_r396034508
But there was some polishing-up required as per the thread, but I have not got around to do it yet! :frowning:
I hope I’ll get to it these days…

1 Like

Pull request merged.
I’ll be available in some of the next releases.

1 Like

Nice work!

1 Like

Hi @jocnnor,

Did this pull request really merge? I am facing this very issue.

1 Like