Converting APSystems data to Home Assistant locally

Hi all,

I have a APSystems installation which I would like to connect to my Home Assistant installation.

I have searched the forum, but only found people who had a different ECU than mine. I do not start at nothing though, because I’m coming from Domoticz and already foudn and adjusted a script that generates a output like this:

1 Serial: 404000825373-A,
1 Power: 6,
1 Freq: 50.0,
1 Temp: 14,

To me this seems some usable data, since the ‘Power’ indicates the current power in Watts.

How can I convert this data in to a Home Assistant sensor which I can also use for the Energy dashboard feature?

Help is much appreciated!

How does your script deliver its output, mqtt, rest, other?

Via a ‘regular’ shell. I run it with python. I previously ran it via Node-RED and someone helped processing the data to prepare it for Domoticz, then sent it to the API.

How would I do this with Home Assistant?

Which ECU do you have?
How do you get these data?
If you can’t use the ECU custom integration you may be able to use command_line, rest or modbus integrations

I have the ECU-3. I indeed can’t use the other integration because that relies on having the ECU booted into setup mode.

How can I process the script outputs in to sensors in Home Assistant? I can dump the output to a file, it that’s easier to work with.

Could you post your script and the output?
You should be able to use the command_line integration and then parse the result

The output is in my first message, just 24 of those sections. How would I parse the output and integrate it in to different devices?

You may try something like this (24 times):

sensor:
  - platform: command_line
    name: "Microinverter 1 Serial"
    command: "your command"
    value_template: '{{ (value|regex_findall("1 Serial:\s*([\d\.]*-[\D]*),"))[0] }}'

  - platform: command_line
    name: "Microinverter 1 Power"
    command: "your command"
    value_template: '{{ (value|regex_findall("1 Power:\s*([\d\.]*),"))[0] }}'
    unit_of_measurement: "W"

  - platform: command_line
    name: "Microinverter 1 Frequence"
    command: "your command"
    value_template: '{{ (value|regex_findall("1 Freq:\s*([\d\.]*),"))[0] }}'
    unit_of_measurement: "Hz"

  - platform: command_line
    name: "Microinverter 1 Temperature"
    command: "your command"
    value_template: '{{ (value|regex_findall("1 Temp:\s*([\d\.]*),"))[0] }}'
    unit_of_measurement: "°C"

I have added the lines, replacing the command with a simple ‘cat output.txt’ for easy debugging.

When checking the config, I recieved the following error:

> Invalid config for [sensor.command_line]: [device_class] is an invalid option for [sensor.command_line]. Check: sensor.command_line->device_class. (See ?, line ?).
> Invalid config for [sensor.command_line]: [device_class] is an invalid option for [sensor.command_line]. Check: sensor.command_line->device_class. (See ?, line ?).
> Invalid config for [sensor.command_line]: [device_class] is an invalid option for [sensor.command_line]. Check: sensor.command_line->device_class. (See ?, line ?).

When commenting out the device_class and restarting, I got no errors but I could not find any devices, integrations or entities.

I’m sorry if I skipped some step or done something wrong, I’m still very new to Home Assistant :wink:

You are right for device_class I made a mistake and updated my code.
You should have at least 4 entities and one named sensor.microinverter_1_power. If not, you should have errors in logs

Thank you. I have updated the code, I again recieve a error, but a different one:

Error loading /config/configuration.yaml: while parsing a block mapping
in "/config/configuration.yaml", line 3, column 1
expected <block end>, but found '-'
in "/config/configuration.yaml", line 18, column 1

Note that this is my first and only modification to the configuration.yaml file. I have pasted the code below the stuff that was already there.

Could you post all your configuration.yaml?

Sure, here it is:

# Loads default set of integrations. Do not remove.
default_config:

# Load frontend themes from the themes folder
frontend:
  themes: !include_dir_merge_named themes

# Text to speech
tts:
  - platform: google_translate

automation: !include automations.yaml
script: !include scripts.yaml
scene: !include scenes.yaml

#APsystems
- sensor:
  - platform: command_line
    name: "Microinverter 1 Serial"
    command: "cat /config/output.txt"
    value_template: '{{ (value|regex_findall("1 Serial:\s*([\d\.]*-[\D]*),"))[0] }}'

  - platform: command_line
    name: "Microinverter 1 Power"
    command: "cat /config/output.txt"
    value_template: '{{ (value|regex_findall("1 Power:\s*([\d\.]*),"))[0] }}'
    unit_of_measurement: "W"

  - platform: command_line
    name: "Microinverter 1 Frequence"
    command: "cat /config/output.txt"
    value_template: '{{ (value|regex_findall("1 Freq:\s*([\d\.]*),"))[0] }}'
    unit_of_measurement: "Hz"

  - platform: command_line
    name: "Microinverter 1 Temperature"
    command: "cat /config/output.txt"
    value_template: '{{ (value|regex_findall("1 Temp:\s*([\d\.]*),"))[0] }}'
    unit_of_measurement: "°C"



Oups my fault: you must remove the - in front of sensor:

Thank you, I think it is working, I have 4 entities now.

Now that this is working, I have 3 questions:
-Is it possible to add some flag so I can use the created devices in the Energy dashboard?
-How can I create a new entity which combines the power of all modules?
-I need to run a Python script in order to get the output. What would be the easiest way to do this? Run the script on another VM and scp the output to HA? Or somehow get python to function within HA?

The energy dashboard uses energy entities (in kWh). I think that you won’t be able to use those entities as it is in Watt.

Go to settings, Devices & Services, Helpers then create a new helper type “group”, “sensor group”. Add a name, all your power entities, and select “Sum” as Type.
This will create a new entity which will be the sum of all your power entities. For example: sensor.power_summation

Then in your config folder, create a file named customize.yaml.
In this file, add:

sensor.power_summation:
  state_class: measurement
  device_class: power

Then in your configuration.yaml file, add this:

homeassistant:
  customize: !include customize.yaml

Then restart Home Assistant.

Then, you will be able to create a new helper type utility_meter that will create an energy sensor in kWh that you will be able to add to the energy dashboard.

I don’t know if this will work but you can try to put the script in your config folder, then run it in a new command_line sensor:

sensor:
  - platform: command_line
    name: "Microinverter output"
    command: "python3 /path/to/script/your-script.py"
    value_template: '{{ value }}'

Your script will run every minute and create your file output.txt that will be read be your other 24 command_line sensors.

Hi Makai,

Sorry for my late response, it was quite a lot of work copying and modifying all lines to get all inverters to show up.

I followed your instructions, and I how have a group that summarizes the inverters, I also have a utility meter with the expected results, but I am not able to select it in the Energy Dashboard. Do you have any idea what is going on?

As to how I’m reading the file, I have another VM set up to run the script and scp it to the Home Assistant VM. Python wasn’t available so this was the easiest solution for now.

Hi Phenix56,

To be able to add this new entity to the Energy Dashboard, it needs some attributes. You can check these in Developer Tools > States and search for your utility_meter entity. It needs state_class = total_increasing and device_class = energy.
If these are missing, edit your customize.yaml file to add this:

sensor.<your sensor name>:
  state_class: total_increasing
  device_class: energy

and restart HA

Hi Makai,

Just to get this straight:

  • I have a sensor group with all solar panels added
  • I have a utility meter.

In the customize.yaml I have used the sensor ID of the utility meter. Is this correct?
When I go to the utility meter sensor, it shows the power in W, not kWh. I am also not able to add the sensor to the Energy Dashboard.

I also noticed in your instructions earlier I had to set the device_class to power. Now I need to set it to energy, correct?

Am I doing everything right?

Your entity which is the sum of all your power sensor (from the group helper) should be in W and have state_class: measurement and device_class: power.
The sensor from the utility_meter should be in Wh or kWh and have state_class: total_increasing and device_class: energy