TimSoethout / goodwe-sems-home-assistant

Sensor for Home Assistant pulling data from the GoodWe SEMS API for solar panel production metrics.
87 stars 35 forks source link

More than 1 inverter #10

Closed jojoro1 closed 3 years ago

jojoro1 commented 4 years ago

How to get data from second inverter?

TimSoethout commented 4 years ago

Hi @jojoro1 , this is currently not possible, since you can only add one converter via configuration.

If we want to support this, I guess we should allow to configure multiple station id's and create separate sensors for them. Feel free to create a pull request for this.

TimSoethout commented 4 years ago

https://github.com/TimSoethout/goodwe-sems-home-assistant/blob/master/custom_components/sems/sensor.py#L36 should be called multiple times with different station id configuration.

spaya1 commented 4 years ago

Hi Tim,

I use this plugin with one inverter and I love it, I’m in the process of extending the system with a second inverter and I saw that it’s not possible by default with this plugin. I was wondering if you ever got to update the code to add multiple inverters. I have no clue about coding so want to know if it would be possible to add the functionality.

Appreciate if you can let me know so that when it’s not possible I look for a different brand of inverter that can be integrated in HA, so that I can run them both in HA as a single sensor.

Thx for the time and for keeping this alive.

Sergio

TimSoethout commented 4 years ago

Hi Sergio, I did not add this to the code yet, simply because I do not need the feature myself at the moment. Of course anyone is free to add it, and I will gladly merge it. Adding multiple inverters is definitely possible and useful. I might do it when I have some spare time, but don't count on it. Also I can't test myself if it works or not, since I do not have two inverters.

Ideally the configuration should not have to change for people just having one inverter: so simple config for single device and some more involved for more: devices: [ list of inverter configs ]. Although I'm not sure if this style is idiomatic style for home assistant components.

Also what do you think such a feature would look like from a user perspective?

@spaya1 , maybe for you a quick fix (hack) could be:

I have not tested this, but it just might work.

spaya1 commented 4 years ago

Hi Tim,

Thanks for coming back so fast. I have tried the hack but it failed.

I have copied the sems folder to sems2 , so now in custom component I have both folders.

I have duplicated config to look like this:

I dont have yet the second inverter, so I have copied the same station id twice.

I get two errors:

Error 1: Logger: homeassistant.components.sensor Source: custom_components/sems2/sensor.py:57 Integration: Sensor (documentation, issues) First occurred: 10:28:36 AM (1 occurrences) Last logged: 10:28:36 AM

Error while setting up sems2 platform for sensor Traceback (most recent call last): File "/usr/src/homeassistant/homeassistant/helpers/entity_platform.py", line 186, in _async_setup_platform await asyncio.gather(pending) File "/usr/src/homeassistant/homeassistant/helpers/entity_platform.py", line 295, in async_add_entities await asyncio.gather(tasks) File "/usr/src/homeassistant/homeassistant/helpers/entity_platform.py", line 445, in _async_add_entity entity.async_write_ha_state() File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 297, in async_write_ha_state self._async_write_ha_state() # type: ignore File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 320, in _async_write_ha_state state = self.state File "/config/custom_components/sems2/sensor.py", line 57, in state return self._attributes['status'] KeyError: 'status'

Error2: Logger: custom_components.sems2.sensor Source: custom_components/sems2/sensor.py:118 Integration: sems2 (documentation) First occurred: 10:28:36 AM (1 occurrences) Last logged: 10:28:36 AM

Unable to fetch data from SEMS. 'NoneType' object is not subscriptable

TimSoethout commented 4 years ago

Maybe you need to change https://github.com/TimSoethout/goodwe-sems-home-assistant/blob/master/custom_components/sems/manifest.json also to sems2?

spaya1 commented 4 years ago

Hi Tim, i did change it before restarting HA. { "domain": "sems2", "name": "Goodwe SEMS API", "documentation": "https://github.com/TimSoethout/goodwe-sems-home-assis$ "dependencies": [], "codeowners": ["@TimSoethout"], "requirements": []

TimSoethout commented 4 years ago

I'm not sure what goes wrong here. You could try turning on debug logging and see if it gives us more information: https://www.home-assistant.io/integrations/logger/

spaya1 commented 4 years ago

Hi Tim,

It seems that sems2 is working now but sems is not :)

I added this:

logger: default: info logs: homeassistant.components.sems: debug

I am getting this new error:

Logger: custom_components.sems.sensor Source: custom_components/sems/sensor.py:118 Integration: sems (documentation) First occurred: 11:28:51 AM (1 occurrences) Last logged: 11:28:51 AM

Unable to fetch data from SEMS. HTTPSConnectionPool(host='www.semsportal.com', port=443): Read timed out. (read timeout=30)

TimSoethout commented 4 years ago

You can add homeassistant.components.sems2: debug as well for more info.

It seems that the api does not like 2 requests (for the same inverter) at the same time maybe?

spaya1 commented 4 years ago

Hi Tim,

I have added it, but it doesnt add any new information besides what I have added earlier:

Error 1:

Logger: homeassistant.components.sensor Source: custom_components/sems2/sensor.py:57 Integration: Sensor (documentation, issues) First occurred: 11:45:07 AM (1 occurrences) Last logged: 11:45:07 AM

Error while setting up sems2 platform for sensor Traceback (most recent call last): File "/usr/src/homeassistant/homeassistant/helpers/entity_platform.py", line 186, in _async_setup_platform await asyncio.gather(pending) File "/usr/src/homeassistant/homeassistant/helpers/entity_platform.py", line 295, in async_add_entities await asyncio.gather(tasks) File "/usr/src/homeassistant/homeassistant/helpers/entity_platform.py", line 445, in _async_add_entity entity.async_write_ha_state() File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 297, in async_write_ha_state self._async_write_ha_state() # type: ignore File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 320, in _async_write_ha_state state = self.state File "/config/custom_components/sems2/sensor.py", line 57, in state return self._attributes['status'] KeyError: 'status'

Error 2:

Logger: custom_components.sems2.sensor Source: custom_components/sems2/sensor.py:118 Integration: sems2 (documentation) First occurred: 11:45:07 AM (1 occurrences) Last logged: 11:45:07 AM

Unable to fetch data from SEMS. 'NoneType' object is not subscriptable

I tried to install the mqtt2sems plugin, it works but it makes my HA system crash, (had to restart my raspberry 3 times in the mean time, so I disabled it for now) so want to continue your route if possible.

TimSoethout commented 4 years ago

Oke. Well it should be definitely possible, but ideally we have someone with 2 inverters already to try this out. Maybe the SEMS API system blocks simultaneous logins or requests. Or it is because you're using the same inverter id twice.

Also this hack is taking too much effort already compared to just implementing multiple inverters correctly. :P If I have some free time tonight, I might start implementing it. :)

spaya1 commented 4 years ago

Well if its too much work i can go with Growatt for the same price, so I could interface both brands under one sensor, would prefer Goodwe as it has higher efficiency, but I also dont want to force it. In any case, they said it would take 4 weeks before they are able to install so there is time to continue playing :)

spaya1 commented 4 years ago

Hello Tim, hope you are fine. I got the second inverter installed :)

As expected it only reads one. I have setup both inverters under the same plant, and under the sems sensor in HA it only detects the first inverter (new one) and the old one has dissappeared.

In the sems application it does detect the increase in power as you can see below.

image

TimSoethout commented 4 years ago

That makes sense, because we only add the values of the first inverter: jsonResponseFinal["data"]["inverter"][0]["invert_full"].items()

To show the other inverters, we would need to add the values of all inverters, by looping over `jsonResponseFinal["data"]["inverter"], which should be a list of inverters. But how should we name the values?

The first seems more proper, but also harder to implement if we don't want to do multiple API request per plant.

spaya1 commented 4 years ago

For me the ideal case is when you have n sensors, so SEMS_Portal_n, that way you can monitor the inverters separately, and add them together under one sensor if you want.

I dont expect many people to have more than 2 inverters, I also think having two inverters is not common (in my case it was 350e vs 950e to go for 2 inverters vs 1 big one).

Option two is possible, you just need to call the right attribute under a new sensor and you are done right?

Eg:

Inverter1: states.sensor.sems_portal.attributes["outputpower"] Inverter2: states.sensor.sems_portal.attributes["outputpower_2"]

TimSoethout commented 4 years ago

I'm building a new version in this branch: https://github.com/TimSoethout/goodwe-sems-home-assistant/tree/%2310-multiple-inverters%2Basync

It is not finished, but it should display multiple inverters. Their names are the inverters serial numbers for now, but I plan to change this.

Can you test if it indeed adds multiple devices for each of your inverters?

spaya1 commented 4 years ago

Hi Tim, good morning.

Thanks for the effort, I have loaded the branch but see the same sensors created with only the new inverter showing (same as before).

Do the sensors have a different name now? I have a GW2000-ns and GW2000-xs, when I search in the state tab for "2000" I only get returned GW2000-xs in the sems_portal sensor.

TimSoethout commented 4 years ago

They should have diffeerent names. If you enable debug logging you should see something like this in the logs: DEBUG (MainThread) [custom_components.sems.sensor] Found inverter attribute GoodweName X3000SSNXXXXX

spaya1 commented 4 years ago

Hi Tim,

I must be doing wrong, I have set it up under sems3, and this is my config:

logger: default: info logs: homeassistant.components.sems3: debug

I have extended the log and all I can see with sems is this:

2020-05-29 08:20:53 WARNING (MainThread) [homeassistant.loader] You are using a custom integration for sems3 which has not been tested by Home Assistant. This component might cause stability problems, be sure to disable it if you experience issues with Home Assistant.

2020-05-29 08:20:55 INFO (MainThread) [homeassistant.components.sensor] Setting up sensor.sems3

but beyond this, there is no more info

spaya1 commented 4 years ago

nvm my logger was wrongly configured...

2020-05-29 08:28:57 DEBUG (SyncWorker_6) [custom_components.sems3.sensor] REST Response Recieved 2020-05-29 08:28:57 DEBUG (SyncWorker_6) [custom_components.sems3.sensor] Updated attribute sn: ---- 2020-05-29 08:28:57 DEBUG (SyncWorker_6) [custom_components.sems3.sensor] Updated attribute powerstation_id: ---- 2020-05-29 08:28:57 DEBUG (SyncWorker_6) [custom_components.sems3.sensor] Updated attribute name: ---- 2020-05-29 08:28:57 DEBUG (SyncWorker_6) [custom_components.sems3.sensor] Updated attribute model_type: GW2000-XS

This is the only one it finds

TimSoethout commented 4 years ago

You should see something like this:

2020-05-28 22:23:38 DEBUG (MainThread) [custom_components.sems.sensor] REST Response Received
2020-05-28 22:23:38 DEBUG (MainThread) [custom_components.sems.sensor] Found inverter attribute GoodweName SNXXXXX
2020-05-28 22:23:38 DEBUG (MainThread) [custom_components.sems.sensor] Found inverter attribute GoodweName SNXXXXX (Second inverter)
2020-05-28 22:23:38 DEBUG (MainThread) [custom_components.sems.sensor] Finished fetching SEMS Portal data in 0.557 seconds

(maybe with sems3 for you).

Are you sure you are running the new version? Those "update attribute XXXX" for each attribute should not be visible in the new version. You have to use the specific branch #10-multiple-inverters+async, and not master

spaya1 commented 4 years ago

Hi Tim,

I am pretty sure I do, I have opened the file and compared with the branch code.

I have reset again and now get a new error:

Logger: homeassistant.util.async Source: util/async.py:120 First occurred: 8:55:39 (4 occurrences) Last logged: 8:56:39

Detected I/O inside the event loop. This is causing stability issues. Please report issue to the custom component author for sems3 doing I/O at custom_components/sems3/sensor.py, line 63: _LoginURL, headers=login_headers, data=login_data, timeout=_RequestTimeout) Detected I/O inside the event loop. This is causing stability issues. Please report issue to the custom component author for sems3 doing I/O at custom_components/sems3/sensor.py, line 98: _PowerStationURL, headers=headers, data=data, timeout=_RequestTimeout)

It does show the info you mentioned earlier in the log, but no sensor created for this.

2020-05-29 09:02:25 DEBUG (MainThread) [custom_components.sems3.sensor] REST Response Received 2020-05-29 09:02:25 DEBUG (MainThread) [custom_components.sems3.sensor] Found inverter attribute NAMENEWPV SN 2020-05-29 09:02:25 DEBUG (MainThread) [custom_components.sems3.sensor] Found inverter attribute NAMEOLDPV SN 2020-05-29 09:02:25 DEBUG (MainThread) [custom_components.sems3.sensor] Finished fetching SEMS Portal data in 1.049 seconds

Error in detail shows this ( i have made xxx in some token areas to avoid issues)

020-05-29 09:02:24 DEBUG (MainThread) [customcomponents.sems3.sensor] SEMS - Getting API token 2020-05-29 09:02:24 WARNING (MainThread) [homeassistant.util.async] Detected I/O inside the event loop. This is causing stability issues. Please report issue to the custom component author for sems3 doing I/O at custom_components/sems3/sensor.py, line 63: _LoginURL, headers=login_headers, data=login_data, timeout=_RequestTimeout) 2020-05-29 09:02:24 DEBUG (MainThread) [custom_components.sems3.sensor] Login JSON response {'hasError': False, 'code': 0, 'msg': 'Success', 'data': {'uid': '6b226682-xxxxx', 'timestamp': 1590735744636, 'token': 'ec7889e5d9b6c461105dxxxx', 'client': 'web', 'version': '', 'language': 'en'}, 'components': {'para': None, 'langVer': 69, 'timeSpan': 0, 'api': 'http://eu.semsportal.com:82/api/Auth/GetToken', 'msgSocketAdr': 'https://eu-xxzx.semsportal.com'}, 'api': 'https://eu.semsportal.com/api/'} 2020-05-29 09:02:24 DEBUG (MainThread) [custom_components.sems3.sensor] SEMS - API Token received: SemsApiToken(requestTimestamp=1590735744636, requestUID='6b226682-7001-4acd-855cxxxxxx', requestToken='ec7889e5d9b6c461105d8xxxxx') 2020-05-29 09:02:24 DEBUG (MainThread) [custom_components.sems3.sensor] update called. 2020-05-29 09:02:24 DEBUG (MainThread) [customcomponents.sems3.sensor] SEMS - Making Power Station Status API Call 2020-05-29 09:02:24 WARNING (MainThread) [homeassistant.util.async] Detected I/O inside the event loop. This is causing stability issues. Please report issue to the custom component author for sems3 doing I/O at custom_components/sems3/sensor.py, line 98: _PowerStationURL, headers=headers, data=data, timeout=_RequestTimeout) 2020-05-29 09:02:25 DEBUG (MainThread) [custom_components.sems3.sensor] REST Response Received 2020-05-29 09:02:25 DEBUG (MainThread) [custom_components.sems3.sensor] Found inverter attribute NAMENEWPV SN 2020-05-29 09:02:25 DEBUG (MainThread) [custom_components.sems3.sensor] Found inverter attribute NAMEOLDPV SN 2020-05-29 09:02:25 DEBUG (MainThread) [custom_components.sems3.sensor] Finished fetching SEMS Portal data in 1.049 seconds

TimSoethout commented 4 years ago

I have to fix those IO warnings still, but they should not keep it from working. This is indeed the output I expected.

It should have the two new devices with the SN's as names now. Weird that you don't get them. Since your log indicate it should be working as expected (for now).

spaya1 commented 4 years ago

A new reboot, and they show up :)

Are these names end state? Then I can start building my sensors around them :)

Thanks!! πŸ‘

TimSoethout commented 4 years ago

Nice. Probably I will make the names something like sems{plantName}{inverterName}.

Does that make sense?

On Fri, May 29, 2020, 09:33 spaya1 notifications@github.com wrote:

A new reboot, and they show up :)

Are these names end state? Then I can start building my sensors around them :)

Thanks!! πŸ‘

β€” You are receiving this because you modified the open/close state. Reply to this email directly, view it on GitHub https://github.com/TimSoethout/goodwe-sems-home-assistant/issues/10#issuecomment-635812361, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAEQZ3G4U46RU3JG2C2KJUDRT5QN3ANCNFSM4JQ6HYBA .

spaya1 commented 4 years ago

Yes, it does!

Also because I cannot show attributes for the new sensors, and I dont know if its related to the name.

In template: {{states.sensor.92000ssn18bwXXXX.attributes.pac}} should show 1400

but shows

Error rendering template: TemplateSyntaxError: expected token 'end of print statement', got 'ssn18bwXXXX'

TimSoethout commented 4 years ago

I don't know why that doesn't work, this seems to work: {{states.sensor['XXXSNXXX'].attributes.pac}}

My gut feeling says that python does not like names/variables to start with a number.

TimSoethout commented 4 years ago

Note that the state of the sensor now represents the pac instead of the on/off status:

{{states.sensor['XXXSNXXX'].state}} == {{states.sensor['XXXSNXXX'].attributes.pac}}

spaya1 commented 4 years ago

Ah that is great. I see that there is someone else facing something similar:

https://community.home-assistant.io/t/issue-with-template-in-binary-sensor/8687/8

So I will wait until the new sensors names are merged and will use those :)

spaya1 commented 4 years ago

Hi Tim,

I managed to do what I wanted πŸ‘

I had to do a bit of setup.

Eg:

sensors:

pv1_outputpower: value_template: "{{ (states.sensor['92000ssn18xxxx'].state | float) | round(2) /1000 }}" unit_of_measurement: 'kW' friendly_name: "PV1 Power Generation Now" pv2_outputpower: value_template: "{{ (states.sensor['52000ssx202xxxx'].state | float) | round(2) /1000 }}" unit_of_measurement: 'kW' friendly_name: "PV2 Power Generation Now" pv1_outputpowertoday: value_template: "{{ (states.sensor['92000ssn18xxxx'].attributes.eday | float) | round(2)}}" unit_of_measurement: 'kWh' friendly_name: "PV1 Power Generation today" pv2_outputpowertoday: value_template: "{{ (states.sensor['52000ssx202xxxx'].attributes.eday | float ) | round(2)}}" unit_of_measurement: 'kWh' friendly_name: "Power Generation today"

Automation (the sensors were not updating for some reason)

alias: update pvsystem description: '' trigger:

Result: (Grafana)

image

wishie commented 3 years ago

@spaya1 do you have any batteries? I have found SEMSPortal to make a complete mess of the data when using 2 inverters in 1 plant.. I ended up splitting mine into 2 separate plants.

wishie commented 3 years ago

@TimSoethout do I need to manually change any files to include 'sems2' in the config etc still, or can I just provide a list of stationids in the sems config?

spaya1 commented 3 years ago

Hi @TimSoethout hope you are fine. I am hoping you can help me. As of yesterday and with the new update of home assistant, custom components where Hassio detects I/O inside the event loop errors mean that the component gets disabled. Updating to the latest version of your component means I lose the access to the second inverter (I get the SEMS Portal sensor pointing to the first inverter of the plant). I was wondering if you could help me regain the functionality you once created for me.

thanks!

spaya1 commented 3 years ago

@spaya1 do you have any batteries? I have found SEMSPortal to make a complete mess of the data when using 2 inverters in 1 plant.. I ended up splitting mine into 2 separate plants.

Hi, sorry I missed your message, I dont have any batteries, and for some reason for me it works (worked) well. I had the same data in Sems portal as in Hassio, as well as being able to breakdown the data per inverter in the plant.

TimSoethout commented 3 years ago

Hi, I was writing an async version of the plugin a while back. This might also fix the I/O in event loop issue you're describing. If I have time, I will try look at it tonight.

spaya1 commented 3 years ago

Hi, I was writing an async version of the plugin a while back. This might also fix the I/O in event loop issue you're describing. If I have time, I will try look at it tonight.

That would be great, let me know if I can help!

TimSoethout commented 3 years ago

So, I was trying to work on this tonight, but it already took my whole evening just setting up a hass development environment (using VSCode and docker). Also I'm not sure how I can easily embed this repo in this environment since the docker setup does not seem to support symlinks. This might take a bit longer than expected...

spaya1 commented 3 years ago

Sorry to hear, I do have my hassio on a docker environment in the rbpi4 let me know if you need me to test something.

Thanks again.

TimSoethout commented 3 years ago

Yes thanks. I was trying to set up a proper development setup (separate from my home/production system) using https://developers.home-assistant.io/docs/development_environment. Turns out a lot of things can be wrong and need to be setup before you can actually start coding. :P

On Wed, 14 Apr 2021 at 08:54, spaya1 @.***> wrote:

Sorry to hear, I do have my hassio on a docker environment in the rbpi4 let me know if you need me to test something.

Thanks again.

β€” You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/TimSoethout/goodwe-sems-home-assistant/issues/10#issuecomment-819276712, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAEQZ3F4TLFBXXUJKNMXSM3TIU3ZTANCNFSM4JQ6HYBA .

TimSoethout commented 3 years ago

Ok, I just finished a working version of this on branch #10-multiple-inverters+async. Feel free to test. If I find some more time I will release a beta version + update documentation.

spaya1 commented 3 years ago

Hi Tim,

thanks for the work, I loaded the branch, and I get the following error:

Logger: homeassistant.components.sensor Source: helpers/entity_platform.py:128 Integration: Sensor (documentation, issues) First occurred: 5:46:48 PM (1 occurrences) Last logged: 5:46:48 PM

The semstest platform for the sensor integration does not support platform setup. Please remove it from your config.

This is my config (same as before, I edited the manifest to ensure it detects it):

TimSoethout commented 3 years ago

It now uses gui config via integrations. I think you need to remove existing config, and maybe keep only sems: to make sure HA picks up the custom component.

On Wed, Apr 14, 2021, 17:49 spaya1 @.***> wrote:

Hi Tim,

thanks for the work, I loaded the branch, and I get the following error:

Logger: homeassistant.components.sensor Source: helpers/entity_platform.py:128 Integration: Sensor (documentation, issues) First occurred: 5:46:48 PM (1 occurrences) Last logged: 5:46:48 PM

The semstest platform for the sensor integration does not support platform setup. Please remove it from your config.

β€” You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/TimSoethout/goodwe-sems-home-assistant/issues/10#issuecomment-819623174, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAEQZ3AUUHF3MVPRHZQWGBDTIW2PDANCNFSM4JQ6HYBA .

spaya1 commented 3 years ago

Hi Tim,

What I get:

Setup failed for sems: No setup or config entry setup function defined. 6:17:58 PM – (ERROR) setup.py

Logger: homeassistant.setup Source: setup.py:163 First occurred: 6:17:58 PM (1 occurrences) Last logged: 6:17:58 PM

Setup failed for sems: No setup or config entry setup function defined.

image

image

I have also restored the manifest to sems

image

TimSoethout commented 3 years ago

Your setup seems to be fine. The integration should show up.

image

I'm currently trying to also setup again with the code from scratch to see if I missed something.

spaya1 commented 3 years ago

Hi Tim,

I managed to get it to load as a platform. However I get a sensor called SEMS portal where I only see a single inverter.

I used to get 2 sensors, one per inverter.

image

this used to be my calculation: pv_outputpower: value_template: "{{ ((states.sensor['92000xxx'].state | float) + (states.sensor['52000xxx'].state | float)) | round(2) /1000 }}" unit_of_measurement: 'kW'

TimSoethout commented 3 years ago

sems_portal is name used the old version (based on current master branch). Are you sure, you're using the code from the #10-multiple-inverters+async branch?

spaya1 commented 3 years ago

Hi Tim,

Pretty sure, is there a way to check in the code?

image
TimSoethout commented 3 years ago

You indeed have the correct code, since you have the config_flow file and translations folder... Hmm.. Not sure what is happening. Is the sems_portal sensor maybe an old one still registered in HA?

Can you try removing all of sems mentions from your configuration file? It seems it is not needed after all. Is it now possible to add the integration via gui?

spaya1 commented 3 years ago

Will try now, but I never had the sems_portal sensor before.