Solar data (apsystems) to homeassistant

Hello,

I am trying to get my solar generated data from apsystems ema to homeassistant. Now i am doing this with a script that does a curl on the apsystems api and sends the data to pvoutput. In homeassistant I have the pvoutput configured and reads the data from there. But that are a couple of steps and I want to make this proces shorter.

When I do a cURL command in the commandline:

curl -H “Content-Type: application/x-www-form-urlencoded” http://api.apsystemsema.com:8073/apsema/v1/ecu/getPowerInfo -d ecuId=XXXXXXXXXXX -d filter=power -d date=20200406

Then I get the following JSON output:

{"data":{"time":"[\"05:36:25\",\"05:41:25\",\"05:46:25\",\"05:51:25\",\"05:56:25\",\"06:01:25\",\"06:06:25\",\"06:11:25\",\"06:16:25\",\"06:21:25\",\"06:26:25\",\"06:31:25\",\"06:36:25\",\"06:41:25\",\"06:46:25\",\"06:51:25\",\"06:56:25\",\"07:01:25\",\"07:06:25\",\"07:11:25\",\"07:16:25\",\"07:21:25\",\"07:26:25\",\"07:31:25\",\"07:36:25\",\"07:41:25\",\"07:46:25\",\"07:51:25\",\"07:56:25\",\"08:01:25\",\"08:06:25\",\"08:11:25\",\"08:16:25\",\"08:21:25\",\"08:26:25\",\"08:31:25\",\"08:36:25\",\"08:41:25\",\"08:46:25\",\"08:51:25\",\"08:56:25\",\"09:01:25\",\"09:06:25\",\"09:11:25\",\"09:16:25\",\"09:21:25\",\"09:26:25\",\"09:31:25\",\"09:36:25\",\"09:41:25\",\"09:46:25\",\"09:51:25\",\"09:56:25\",\"10:01:25\",\"10:06:25\",\"10:11:25\",\"10:16:25\",\"10:21:25\",\"10:26:25\",\"10:31:25\",\"10:36:25\",\"10:41:25\",\"10:46:25\",\"10:51:25\"]","power":"[\"6\",\"7\",\"14\",\"14\",\"15\",\"24\",\"31\",\"39\",\"46\",\"56\",\"70\",\"75\",\"83\",\"102\",\"115\",\"138\",\"395\",\"694\",\"789\",\"846\",\"892\",\"932\",\"968\",\"1012\",\"1044\",\"1078\",\"1111\",\"1137\",\"1169\",\"1195\",\"1217\",\"1235\",\"1253\",\"1279\",\"1298\",\"1317\",\"1328\",\"1210\",\"1335\",\"1371\",\"1382\",\"1393\",\"1400\",\"1407\",\"1416\",\"1429\",\"1452\",\"1470\",\"1493\",\"1519\",\"1538\",\"1561\",\"1593\",\"1617\",\"1648\",\"1674\",\"1706\",\"1732\",\"1763\",\"1788\",\"1817\",\"1849\",\"1872\",\"1893\"]"},"code":"1"}

Is it possible to use cURL or the restful sensor within Homeassistant in import these JSON data?

Maybe someone can push me in the right direction to fix this.

Did you try the rest sensor and the command line sensor yet?

Couple of pointers for the restful sensor:

You’re going to need a formatted date template in the resource by the look of that URL.

resource_template: "http://api.apsystemsema.com:8073/apsema/v1/ecu/getPowerInfo -d ecuId=XXXXXXXXXXX -d filter=power date={{ as_timestamp(now())|timestamp_custom('%Y''%m''%d', true) }}"

Also your result is way longer than the 255 character limit allowed for states. So it will have to be placed in an attribute.

Matching up the time and power values is going to be fun too.

I have no idea how you would use that sort of result.

1 Like

i use scrape to recover data

my sensor:

  • platform: scrape
    resource: http://192.168.0.26/
    select: " tr:nth-child(2) > td"
    name : Lifetime_generation
    value_template: ‘{{ ((value.split(" ")[0]) | replace (“KW”, “”)) }}’
    unit_of_measurement: “kWh”

    Request every hour

    scan_interval: 60

  • platform: scrape
    resource: http://192.168.0.26/
    select: " tr:nth-child(3) > td"
    name : Last System Power
    value_template: ‘{{ ((value.split(" ")[0]) | replace (“W”, “”)) }}’
    unit_of_measurement: “W”
    scan_interval: 60

  • platform: scrape
    resource: http://192.168.0.26/
    select: " tr:nth-child(4) > td"
    name : Generation of Current Day
    value_template: ‘{{ ((value.split(" ")[0]) | replace (“KW”, “”)) }}’
    unit_of_measurement: “kWh”
    scan_interval: 60

  • platform: scrape
    resource: http://192.168.0.26/
    select: " tr:nth-child(7) > td"
    name : Last Number of Inverters Online
    scan_interval: 60

Could you please format your pasted code correctly.

my apsystem.yaml

  • platform: scrape
    resource: http://192.168.0.26/
    select: " tr:nth-child(2) > td"
    name : Lifetime_generation
    value_template: ‘{{ ((value.split(" ")[0]) | replace (“KW”, “”)) }}’
    unit_of_measurement: “kWh”
    scan_interval: 60
  • platform: scrape
    resource: http://192.168.0.26/
    select: " tr:nth-child(3) > td"
    name : Last System Power
    value_template: ‘{{ ((value.split(" ")[0]) | replace (“W”, “”)) }}’
    unit_of_measurement: “W”
    scan_interval: 60
  • platform: scrape
    resource: http://192.168.0.26/
    select: " tr:nth-child(4) > td"
    name : Generation of Current Day
    value_template: ‘{{ ((value.split(" ")[0]) | replace (“KW”, “”)) }}’
    unit_of_measurement: “kWh”
    scan_interval: 60
  • platform: scrape
    resource: http://192.168.0.26/
    select: " tr:nth-child(7) > td"
    name : Last Number of Inverters Online
    scan_interval: 60

Hi @olivep, I got your way to retrieve apsystems data, but did not get the value on my sensor.
I know nothing about the select section you use, but tried using yours once I thing you are using APSYSTEMS EMA as well, aren’t you?

I am testing just TODAY ENERGY using this:

  - platform: scrape
    resource: https://apsema.com/ema/intoYc1000DemoUser.action
    select: "tr:nth-child(4)>td"
    name: Energia Hoje
    value_template: '{{ ((value.split(" ")[0]) | replace ("KW", "")) }}'
    unit_of_measurement: "kWh"
    scan_interval: 600

Got this log error:
“Unable to extract data from HTML for Energia Hoje”

Can you explain me how to locate that value from the website?
Thanks

I do not work with the web app but directly on the ecu from where the ip address

Oh I see… so it is posible accessing ECU… I’m not home now to test it, but how can I learn about this line:

select: “tr:nth-child(4)>td”

Thanks!

Did not get access to ECU, I need to try changing the network router!!!

By now, I tryed scraping EMA and almost got success!!!

  - platform: scrape
    resource: https://apsema.com/ema/intoYc1000DemoUser.action
    name: Energia Hoje
    select: "#today"
    unit_of_measurement: "kWh"
    scan_interval: 3600

Unfortunatly the website takes 500ms to load data, and the scrape takes the value “0” that is showed before that loading!!!

On the web page select the value to be scrapped then right click mouse and inspect

Thanks. I got it working, but it does not get the correct value, once it takes the “0” value that is showed some milliseconds before the correct numbers…
I will try the ECU way this weekend.
Thanks again.

Unfortunatly my ecu does not have a web interface. Model ECU-R (image)
Can’t connect throught local ip adress…
It connects only via phone app.
What is your ECU?

my ECU is ecu-3.
I see that the ecu-r has the zigbee have you tried something on this side?
and in the notice
4.1 Connection to the ECU-R via the wireless LAN
• Open the Wi-Fi settings on your smartphone, select the point
access ECU-R.
• When connecting to the ECU-R via wireless LAN, the password by
default is “88888888”.
• Open the ECUAPP.
• Check that the ECUAPP is connected to the ECU-R on the home page.

so you have local access

Thanks for the try but:

  1. Zigbee function is just for talk between Microinverters and ECU. I found nothing on this side.

  2. The local access works this way:
    Ecu creates an access point for a few minutos when pressed the lateral button. Just to connect the ECU app to make the initial setup. It is a momentary state that won’t work more than 10 minutes and there is no open port to connect other way than ECU app.

I think the only way is throught PVOUTPUT service with a script making data upload using APSYSTEMS api.

Hi.

Thanks for providing the code.

This, select: “tr:nth-child(4)>td” didn't work for me, it was giving me a pseudo-class error.

This code worked for me:

select: "td:nth-of-type(3)"  

Thanks !!

Knowledge about this topic for ECU-R users continues here: APsystems APS ECU R local inverters data pull