Serial output from energy monitor into HA raspberry pi

Hi

I’m trying to get serial data from this energy monitor to work in HA, I have tested and can read the output using raspbian, but on my pi4 I am using HA OS

It outputs like this:

"pi@raspberrypi:~ $ cat /dev/ttyAMA0

11 2.94 12.55 0.05 244.34 0.159 1.20 8.29 0.03 244.20 0.121 16.25 30.73 0.13 244.31 0.521"

Which according to the documentation is:

NodeID Realpower1 ApparentPower1 Irms1 Vrms1 PowerFactor1 Realpower2 ApparentPower2 Irms2 Vrms2 PowerFactor2 Realpower3 ApparentPower3 Irms3 Vrms3 PowerFactor3

my yaml config looks like this:

  - platform: serial
    serial_port: /dev/ttyAMA0
    baudrate: 115200

  - platform: template
    sensors:
      my_nodeid_sensor:
        friendly_name: NodeID
        unit_of_measurement: "W"
        value_template: "{{ states('sensor.serial_sensor').split(' ')[1] | float }}"
      my_realpower1_sensor:
        friendly_name: Realpower1
        unit_of_measurement: "W"
        value_template: "{{ states('sensor.serial_sensor').split(' ')[2] | float }}"
      my_apparentpower1_sensor:
        friendly_name: ApparentPower1
        unit_of_measurement: "W"
        value_template: "{{ states('sensor.serial_sensor').split(' ')[3] | float }}"
      my_lrms1_sensor:
        friendly_name: Irms1
        unit_of_measurement: "W"
        value_template: "{{ states('sensor.serial_sensor').split(' ')[4] | float }}"
      my_vrms1_sensor:
        friendly_name: Vrms1
        unit_of_measurement: "W"
        value_template: "{{ states('sensor.serial_sensor').split(' ')[5] | float }}"
      my_powerfactor1_sensor:
        friendly_name: PowerFactor1
        unit_of_measurement: "W"
        value_template: "{{ states('sensor.serial_sensor').split(' ')[6] | float }}"
      my_realpower2_sensor:
        friendly_name: Realpower2
        unit_of_measurement: "W"
        value_template: "{{ states('sensor.serial_sensor').split(' ')[7] | float }}"
      my_apparentpower2_sensor:
        friendly_name: ApparentPower2
        unit_of_measurement: "W"
        value_template: "{{ states('sensor.serial_sensor').split(' ')[8] | float }}"
      my_lrms2_sensor:
        friendly_name: Irms2
        unit_of_measurement: "W"
        value_template: "{{ states('sensor.serial_sensor').split(' ')[9] | float }}"
      my_vrms2_sensor:
        friendly_name: Vrms2
        unit_of_measurement: "W"
        value_template: "{{ states('sensor.serial_sensor').split(' ')[10] | float }}"
      my_powerfactor2_sensor:
        friendly_name: PowerFactor2
        unit_of_measurement: "W"
        value_template: "{{ states('sensor.serial_sensor').split(' ')[11] | float }}"
      my_realpower3:
        friendly_name: Realpower3
        unit_of_measurement: "W"
        value_template: "{{ states('sensor.serial_sensor').split(' ')[12] | float }}"
      my_apparentpower3_sensor:
        friendly_name: ApparentPower3
        unit_of_measurement: "W"
        value_template: "{{ states('sensor.serial_sensor').split(' ')[13] | float }}"
      my_lrms3_sensor:
        friendly_name: Irms3
        unit_of_measurement: "W"
        value_template: "{{ states('sensor.serial_sensor').split(' ')[14] | float }}"
      my_vrms3_sensor:
        friendly_name: Vrms3
        unit_of_measurement: "W"
        value_template: "{{ states('sensor.serial_sensor').split(' ')[15] | float }}"
      my_powerfactor3_sensor:
        friendly_name: PowerFactor3
        unit_of_measurement: "W"
        value_template: "{{ states('sensor.serial_sensor').split(' ')[16] | float }}"

If I enter

 {{ states('sensor.serial_sensor') }}

Into developer tools - template, I get:

Result type: string
 
 unknown

It seems that it is not reading the serial data at all for some reason, I have spent hours trying to figure this out!

Please please post your code properly.

Is that better?

Thank you yes

How big does that serial output get? There are 90 characters in the sample output. You are getting close to the 128 char limit for a sensor.

Does the user running HA have access to the serial device?

Is the serial device definitely at /dev/AMA0?

The creator of the energy monitor has just written a guide after contacting them which has solved my issue!

http://lechacal.com/wiki/index.php?title=Homeassistant

1 Like