Read data from UART RX pin and send value to HA

Hi, I have a separate Arduino controller that measures spare power from my solar panels and pulses the immersion heater on & off.

This controller transmitts the spare power reading via the Arduino’s serial port. I would like to get that power back into home assistant. Can I use the UART function of the ESPHome.

I cant find many examples on reading data in, I can format the data leaving the Arduino. Therefore the ESP8266 can know what to expect.

Kind regards, Dave

https://esphome.io/custom/uart.html

Hi, could I please have some advise to how to “read” / “see” values in esphome/homeassistant?

I have the PZEM platform showing V, A, Hz etc… correctly.

Now I have connected a real MODBUS RTU to my esphome and I off course get strange values every second. I would like to see the RAW serial data that gets received to see if I can translate that to sensors in HA.

The MODBUS values come from a solar inverter.

I really have googled any topic about modbus / esphome but it is VERY SCARS…

My config:

uart:
  tx_pin: D1
  rx_pin: D2
  baud_rate: 9600
  stop_bits: 1

And this give me CORRECT values when I use a real PZEM (of course):

  - platform: pzemac
    update_interval: 1s
    current:
      name: "${esp_name} A"
    voltage:
      name: "${esp_name} V"
    power:
      name: "${esp_name} W"
      unit_of_measurement: W
      id: "${esp_name}_W"
      icon: mdi:flash-outline
    frequency:
      name: "${esp_name} Hz"
    power_factor:
      name: "${esp_name} Pf"
    energy:
      name: "${esp_name} Wh"

Main question: How can I see the RAW serial data on pin D1 / D2?

I might then be able to use:

EDIT: I also have a hard time understanding how to use above link …

Currently with the MODBUS connected to pzem config I get totally weird values :-):

[14:41:56][D][pzemac:049]: PZEM AC: V=0.1 V, I=8716.288 A, P=216.9 W, E=6815744.0 Wh, F=87.1 Hz, PF=0.00
[14:41:56][V][sensor:013]: 'pzem016modbus V': Received new state 0.100000
[14:41:56][D][sensor:092]: 'pzem016modbus V': Sending state 0.10000 V with 1 decimals of accuracy
[14:41:56][V][sensor:013]: 'pzem016modbus A': Received new state 8716.288086
[14:41:56][D][sensor:092]: 'pzem016modbus A': Sending state 8716.28809 A with 3 decimals of accuracy
[14:41:56][V][sensor:013]: 'pzem016modbus W': Received new state 216.899994
[14:41:56][D][sensor:092]: 'pzem016modbus W': Sending state 216.89999 W with 1 decimals of accuracy
[14:41:56][V][sensor:013]: 'pzem016modbus - Dagverbruik': Received new state 2048.702393
[14:41:56][D][sensor:092]: 'pzem016modbus - Dagverbruik': Sending state 2.04870 kWh with 3 decimals of accuracy
[14:41:56][V][sensor:013]: 'pzem016modbus Wh': Received new state 6815744.000000
[14:41:56][D][sensor:092]: 'pzem016modbus Wh': Sending state 6815744.00000 Wh with 0 decimals of accuracy
[14:41:56][V][sensor:013]: 'pzem016modbus Hz': Received new state 87.099998
[14:41:56][D][sensor:092]: 'pzem016modbus Hz': Sending state 87.10000 hz with 1 decimals of accuracy
[14:41:56][V][sensor:013]: 'pzem016modbus Pf': Received new state 0.000000
[14:41:56][D][sensor:092]: 'pzem016modbus Pf': Sending state 0.00000  with 2 decimals of accuracy
[14:41:57][D][pzemac:049]: PZEM AC: V=0.1 V, I=8650.752 A, P=216.8 W, E=6684672.0 Wh, F=90.0 Hz, PF=0.00
[14:41:57][V][sensor:013]: 'pzem016modbus V': Received new state 0.100000
[14:41:57][D][sensor:092]: 'pzem016modbus V': Sending state 0.10000 V with 1 decimals of accuracy
[14:41:57][V][sensor:013]: 'pzem016modbus A': Received new state 8650.751953
[14:41:57][D][sensor:092]: 'pzem016modbus A': Sending state 8650.75195 A with 3 decimals of accuracy
[14:41:57][V][sensor:013]: 'pzem016modbus W': Received new state 216.800003
[14:41:57][D][sensor:092]: 'pzem016modbus W': Sending state 216.80000 W with 1 decimals of accuracy
[14:41:57][V][sensor:013]: 'pzem016modbus - Dagverbruik': Received new state 2048.762695
[14:41:57][D][sensor:092]: 'pzem016modbus - Dagverbruik': Sending state 2.04876 kWh with 3 decimals of accuracy
[14:41:57][V][sensor:013]: 'pzem016modbus Wh': Received new state 6684672.000000
[14:41:57][D][sensor:092]: 'pzem016modbus Wh': Sending state 6684672.00000 Wh with 0 decimals of accuracy
[14:41:57][V][sensor:013]: 'pzem016modbus Hz': Received new state 90.000000
[14:41:57][D][sensor:092]: 'pzem016modbus Hz': Sending state 90.00000 hz with 1 decimals of accuracy
[14:41:57][V][sensor:013]: 'pzem016modbus Pf': Received new state 0.000000
[14:41:57][D][sensor:092]: 'pzem016modbus Pf': Sending state 0.00000  with 2 decimals of accuracy
[14:41:58][D][pzemac:049]: PZEM AC: V=0.1 V, I=8650.752 A, P=219.8 W, E=6684672.0 Wh, F=90.5 Hz, PF=0.00
[14:41:58][V][sensor:013]: 'pzem016modbus V': Received new state 0.100000
[14:41:58][D][sensor:092]: 'pzem016modbus V': Sending state 0.10000 V with 1 decimals of accuracy
[14:41:58][V][sensor:013]: 'pzem016modbus A': Received new state 8650.751953
[14:41:58][D][sensor:092]: 'pzem016modbus A': Sending state 8650.75195 A with 3 decimals of accuracy
[14:41:58][V][sensor:013]: 'pzem016modbus W': Received new state 219.800003
[14:41:58][D][sensor:092]: 'pzem016modbus W': Sending state 219.80000 W with 1 decimals of accuracy
[14:41:58][V][sensor:013]: 'pzem016modbus - Dagverbruik': Received new state 2048.823730
[14:41:58][D][sensor:092]: 'pzem016modbus - Dagverbruik': Sending state 2.04882 kWh with 3 decimals of accuracy
[14:41:58][V][sensor:013]: 'pzem016modbus Wh': Received new state 6684672.000000
[14:41:58][D][sensor:092]: 'pzem016modbus Wh': Sending state 6684672.00000 Wh with 0 decimals of accuracy
[14:41:58][V][sensor:013]: 'pzem016modbus Hz': Received new state 90.500000
[14:41:58][D][sensor:092]: 'pzem016modbus Hz': Sending state 90.50000 hz with 1 decimals of accuracy
[14:41:58][V][sensor:013]: 'pzem016modbus Pf': Received new state 0.000000
[14:41:58][D][sensor:092]: 'pzem016modbus Pf': Sending state 0.00000  with 2 decimals of accuracy
[14:41:59][D][pzemac:049]: PZEM AC: V=0.1 V, I=8781.824 A, P=220.5 W, E=6750208.0 Wh, F=93.6 Hz, PF=0.00
[14:41:59][V][sensor:013]: 'pzem016modbus V': Received new state 0.100000
[14:41:59][D][sensor:092]: 'pzem016modbus V': Sending state 0.10000 V with 1 decimals of accuracy
[14:41:59][V][sensor:013]: 'pzem016modbus A': Received new state 8781.824219
[14:41:59][D][sensor:092]: 'pzem016modbus A': Sending state 8781.82422 A with 3 decimals of accuracy
[14:41:59][V][sensor:013]: 'pzem016modbus W': Received new state 220.500000
[14:41:59][D][sensor:092]: 'pzem016modbus W': Sending state 220.50000 W with 1 decimals of accuracy

This is the right link to help you:

The text sensor that is created in these instructions will contain what your UART receives, line by line.
The readings are also monitored in the log, so you should see the incoming data immediately. Just adapt the baud rate and it should work. Here is an example output from my log. It is from an ESPHome MCU that runs basically only the above Custom UART code together with the standard initial ESPHome settings:

[08:13:39][D][text_sensor:015]: 'uart_readline': Sending state 'Hello World'

The serial source for that transmission was another ESPHome MCU that sends data every single second using:

uart.write: "Hello World\r\n"