APsystems APS ECU R local inverters data pull

will give it a try… will be quick

btw… the issue in this topic from ahof, revolves around the ECU not responding and requiring to close the connection after each query. Is this something we can include in the code?

async def async_query_ecu(self):
self.reader, self.writer = await asyncio.open_connection(self.ipaddr, self.port)
_LOGGER.info(f"Connected to {self.ipaddr} {self.port}")

cmd = self.ecu_query
self.ecu_raw_data = await self.async_send_read_from_socket(cmd)

self.process_ecu_data()

self.writer.close()
self.reader, self.writer = await asyncio.open_connection(self.ipaddr, self.port)
_LOGGER.info(f"Connected to {self.ipaddr} {self.port}")

cmd = self.inverter_query_prefix + self.ecu_id + self.inverter_query_suffix
self.inverter_raw_data = await self.async_send_read_from_socket(cmd)


self.writer.close()
self.reader, self.writer = await asyncio.open_connection(self.ipaddr, self.port)
_LOGGER.info(f"Connected to {self.ipaddr} {self.port}")

cmd = self.inverter_signal_prefix + self.ecu_id + self.inverter_signal_suffix
self.inverter_raw_signal = await self.async_send_read_from_socket(cmd)

self.writer.close()

data = self.process_inverter_data()
data["ecu_id"] = self.ecu_id
data["today_energy"] = self.today_energy
data["lifetime_energy"] = self.lifetime_energy
data["current_power"] = self.current_power

return(data)

def query_ecu(self):

sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
sock.connect((self.ipaddr,self.port))

sock.sendall(self.ecu_query.encode('utf-8'))
self.ecu_raw_data = sock.recv(self.recv_size)

self.process_ecu_data()

sock.shutdown(socket.SHUT_RDWR)
sock.close()
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
sock.connect((self.ipaddr,self.port))

cmd = self.inverter_query_prefix + self.ecu_id + self.inverter_query_suffix
sock.sendall(cmd.encode('utf-8'))
self.inverter_raw_data = sock.recv(self.recv_size)

sock.shutdown(socket.SHUT_RDWR)
sock.close()
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
sock.connect((self.ipaddr,self.port))

cmd = self.inverter_signal_prefix + self.ecu_id + self.inverter_signal_suffix
sock.sendall(cmd.encode('utf-8'))
self.inverter_raw_signal = sock.recv(self.recv_size)

sock.shutdown(socket.SHUT_RDWR)
sock.close()

data = self.process_inverter_data()

data["ecu_id"] = self.ecu_id
data["today_energy"] = self.today_energy
data["lifetime_energy"] = self.lifetime_energy
data["current_power"] = self.current_power


return(data)

100% correct, you deserve a :+1:

Great, it works with the new unit constant. Only thing now is to add the data source for ECU’s energy production to the list to enable the “add solar production”. It’s not in the list and the cause revers to https://developers.home-assistant.io/docs/core/entity/sensor#long-term-statistics
image
There is no parameter from the ECU-R integration that is listed here above.

We could include that but it’s really strange that I haven’t had this problem at all, and been querying it non-stop for months now. Is there something different about this setup?

Which sensor needs the state_class addition? is that sensor.ecu_lifetime_energy? or should it be the daily production one?

Looking at it a little more I think it should be daily production, but also needs a last_reset indicator - which should be pretty easy to do. Once I upgrade to August release, I can get these changes pushed into the repo after I had a chance to do a little testing.

It should be a kWh parameter, so it might need a calculation from current energy production in Watts somehow. But it’s all a bit hasty analysis, the addition in HA looks great.

That would be great! Remember to add the calVer correction to correct version display from HACS.

kinda lol… i did a template months back for daily solar energy to combine with P1 datas

utility_meter:
  daily_solar_energy:
    source: sensor.ecu_today_energy
    cycle: daily

that one is available and to select in energy config and does a reset over day switch. So we can see if this is the right way to go tomorrow and see if that addition is good for the integration

1 Like

his ECU has other kind of firmware, atleast version greater then ours somehow
“Version”: “ECU_R_PRO_2.0.0”. With the disconnect port it started working

I tried to add the template but I must do something wrong. How do you implement this on HA? (and by the way does it work!). I’m curious to see it working!

yeah… template is the wrong word, sorry. Its the utility meter integration, where you can addthis as item. Just copy paste as main node in config yaml.

currently it looks like this, will do some value validations later as the power consumed from grid is netto instead of absolute

some time later

Nice! I managed to add the script now, let’s see how it works out in the next view hours. Thnx!

Kevin, how did you make the pop card with Voltage details per inverter? Can you share? Is done with card-mod?

Kevin, I found out that the ECU with 2.0 software doesnt work well with a open connection and multiple queries. When I closed them and reopen them for each query, it worked.
Other issue: my HA crashed because the ECU was also in a wrong state. After restart it worked again. Before restarting the ECU it reported after a query for hundreds like below (increment for each UID)

“UID17413”: {
“UID”: “’”,
“Online”: false,
“Type”: “Unknown”
},
“UID17414”: {
“UID”: “’”,
“Online”: false,
“Type”: “Unknown”
},
“UID17415”: {
“UID”: “’”,
“Online”: false,
“Type”: “Unknown”
},
“UID17416”: {
“UID”: “’”,
“Online”: false,
“Type”: “Unknown”
},
“UID17417”: {
“UID”: “’”,
“Online”: false,
“Type”: “Unknown”
},
“UID17418”: {
“UID”: “’”,
“Online”: false,
“Type”: “Unknown”
}
Can we make the integration more robust when ECU respons is not what HA integration suspect?

Even with two solarpanels things are starting to show now (after two hours), this is looking great. You can also add the Forecast.Solar integration. It will plot the forecast on the solar production graph.
image

What do you mean by this, can you be more specific?

that forecastes i activated too yesterday. Predicting 28Kwh for today, that wont happen :slight_smile: . Will play with that setup too. I’m still not convinced the energy overview from HA is correct for my situation also.
lots of calculating to do :slight_smile:

Did you not forget to specify the maximum output power of your solarpanel grid? But indeed it’s a prediction and I think they will improve things now that they’ve combined the graphs. Frenck has solarpanels :smiley: (but uses SolarEdge though)