Goodwe rest sensor for multiple json elements

I’ve added in the following so i can get an update every 5mins.

import datetime
from datetime import timedelta
MIN_TIME_BETWEEN_UPDATES = timedelta(minutes=5)
1 Like

Can you share the information? I have some time until Monday to work on this. :slight_smile:

Works awesome man! Thanks @TimmyBankers

I added the code in this repository (cleaned up a bit).

Also found out that the scraping interval can be configured with config setting: scan_interval, and no code changes are required.

I have 2 inverters but sensor is showing status only one of them :frowning:

@jojoro, I think the json parsing part of the code just takes the first element of a list somewhere. This means the current code only supports the first inverter. Feel free to update the code. :slight_smile:

Hello Everyone. I wish I could contribute, your work is amazing.
I am however a complete beginner. I have managed to get this working though.
Is it possible to display only some of the many attributes on the UI ?
Lets say PV voltage and current for example.

Hello all,
I am also very new to Home Assistant, only a few weeks.
I have also managed to get this working.
It is possible to display only some atrributes on the UI.
I use this method:
platform: template
sensors:
invertersn:
value_template: “{{ states.sensor.sems_portal.attributes.sn }}”
pvvoltage1:
value_template: “{{ states.sensor.sems_portal.attributes.vpv1 }}”
pvvoltage2:
value_template: “{{ states.sensor.sems_portal.attributes.vpv2 }}”
I don’t know if this is the correct method but it will display the attributes sn,vpv1, vpv2
I hope this will help you a little more.

Hallo Bart

Thank you very much, it work perfectly

Hello,
You can use also the custom:state-attribute-element to get this info out of the sensor.sems_portal
(so that it wouldn’t create a sensor for every attribute you want to show)

https://github.com/custom-cards/state-attribute-element

Kind regards,

Bart

Thanks Bart,

This works great!
Do you know if there is a way to return the value from each attribute as a number rather than as a text string?

I’d like to be able to graph the output over a period of time.

27%20pm

Just create a sensor.
See below for my implementation (the spellingmistakes are intentional!)

##########################################################################
## Goodwe Inverter sensor
##########################################################################
sensor:
  - platform: sems
    username: 'your_id'
    password: 'your_pw'
    scan_interval: 900
  - platform: template
    sensors:
      pv_eday:
        value_template: '{{ states.sensor.sems_portal.attributes.eday }}'
        unit_of_measurement: 'kWh'
        friendly_name: "PV productie vandaag"
      pv_temperature:
        value_template: '{{ states.sensor.sems_portal.attributes.tempperature }}'
        unit_of_measurement: '°C'
        friendly_name: "Temperatuur Inverter"
      pv_thismonthetotle:
        value_template: '{{ states.sensor.sems_portal.attributes.thismonthetotle }}'
        unit_of_measurement: 'kWh'
        friendly_name: "Totaal deze maand"
      pv_lastmonthetotle:
        value_template: '{{ states.sensor.sems_portal.attributes.lastmonthetotle }}'
        unit_of_measurement: 'kWh'
        friendly_name: "Totaal t/m vorige maand"
      pv_output_power:
        value_template: '{{ states.sensor.sems_portal.attributes.outputpower }}'
        unit_of_measurement: 'W'
        friendly_name: "PV power"

Issues after upgrading to 0.92? See here: https://github.com/TimSoethout/goodwe-sems-home-assistant/issues/3

Did this work for you? I cant get it working. Could you possible share you files?

I see I made a small typing mistake, the first needed { is not shown, sorry about that.

{
  "domain": "sems",
  "name": "Goodwe SEMS scraper",
  "documentation": "https://github.com/TimSoethout/goodwe-sems-home-assistant",
  "dependencies": [],
  "codeowners": [],
  "requirements": []
}

The issue-text on github has also been corrected.

Thanks, I had already added the { but I also made a typo I now corrected. It’s working again.

Any plans to change this from a scraper to a REST API call?
Documentation:
http://au.sems.com.cn:82/swagger/ui/index

E.g.

curl -X POST --header 'Accept: application/json' --header 'token: {"uid": "[redacted]","timestamp": 1558143769193,"token": "[redacted]","client": "web","version": "","language": "en-GB" }' 'http://au.semsportal.com:82/api/v2/Common/GetApis'

Payload

{
  "language": "en-gb",
  "function": null,
  "hasError": false,
  "msg": "success",
  "code": "0",
  "data": [
    "http://au.semsportal.com:82/api",
    "http://eu.semsportal.com:82/api",
    "http://hk.semsportal.com:82/api",
    "http://192.168.1.114:8080/api",
    "http://192.168.1.114:8888/api",
    "http://192.168.90.32:8821/api"
  ],
  "components": {
    "para": "{}",
    "langVer": 4,
    "timeSpan": 0,
    "api": "http://au.semsportal.com:82/api/v2/Common/GetApis"
  }

I’ve used the native REST API… limitation here is I can’t authenticate first to get the token, and then query, so token is set in config (not sure if this times out, so best would be to write a proper sensor to authenticate as required. I think it will invalidate the token once you log into the site manually. Also I look at specific array elements, better to loop through them within a proper sensor component. As test case, I am extracting the entire data payload (i.e. you can see it from Developer Tools > States) but only parse 3 of them (the ones I am interested in) Also converting W to kW. Note I am in Australia, hence I am using the au API. Again, not something I would use as the token can get invalidated due to the limitations of using the REST component, and not a custom component.

my configuration.yaml

# get token here http://au.semsportal.com:82/swagger/ui/index#!/CommonController/CommonController_CrossLogin_0  > v2 > POST /api/v2/Common/CrossLogin
# get powerStationId by logging into SEMS portal, the url would end with it, e.g. https://www.semsportal.com/PowerStation/PowerStatusSnMin/abcdef01-ab12-abdb-abcd-01ab12bc2367
  - platform: rest
    name: GoodWe Inverter
    json_attributes:
      - data
    resource: http://au.semsportal.com:82/api/v2/PlantManage/GetPlantMonitor
    headers:
      Content-Type: application/json
      Accept: application/json
      token: '{"uid": "[redacted]","timestamp": 1558147862443,"token": "[redacted]","client": "web","version": "","language": "en" }'
    method: POST
    payload: '{"powerStationId": "[redacted]" }'
    value_template: '{{ value_json.data.location }}'

  - platform: template
    sensors:
      goodwe_inner_temperature:
        friendly_name: Inner Temperature
        value_template: '{{ states.sensor.goodwe_inverter.attributes.data.snIndexs[0].indexs[4].rowValue | float | round(2) }}'
        unit_of_measurement: "°C"
      goodwe_output_power:
        friendly_name: 'Output Power'
        value_template: '{{ states.sensor.goodwe_inverter.attributes.data.snIndexs[0].indexs[5].rowValue | float / 1000 | round(2) }}'
        unit_of_measurement: "kW"
        entity_id: sensor.goodwe_inverter
      goodwe_output_voltage:
        friendly_name: Output Voltage
        value_template: '{{ states.sensor.goodwe_inverter.attributes.data.snIndexs[0].indexs[6].rowValue | round(2) }}'
        unit_of_measurement: "V"
        entity_id: sensor.goodwe_inverter

I’ve created a new custom component which uses the SEMS REST API. Its an ‘API adaptation’ of the component from TimmyBankers (above). You can find it here: https://github.com/hesselonline/sems, let me know if you have any issues (or not;))

1 Like

Thank you @hesselonline, your component is working very well!