Collect Inverter data from Solarman API

Yes, new version of Hassio doesnt let you restart system anymore if code isnt validated.

New finding… I dont see solarmanpv data in mqtt explorer…
1

And incase you’re wondering what I wrote for mqtt

mqtt:
    sensor:
        - name: "roof tank"
          state_topic: "tele/roof_tank/SENSOR"

        - state_topic: "solarmanpv/station/generationPower"
          name: "solarmanpv_station_generationPower"
          unique_id: "generatedPower"
          unit_of_measurement: "Wh"
          device_class: energy
          state_class: measurement
        
        - state_topic: "solarmanpv/inverter/deviceState"
          name: "solarmanpv_inverter"
          unique_id: "solarmanpv_inverter"
          json_attributes_topic: "solarmanpv/inverter/attributes"
        
        - state_topic: "solarmanpv/logger/deviceState"
          name: "solarmanpv_logger"
          unique_id: "solarmanpv_logger"
          json_attributes_topic: "solarmanpv/logger/attributes"

Then I guess you know what to do :grinning:…fix MQTT messaging

MQTT Explorer starts showing data when I use following entries from github instead of yours

        - name: "solarmanpv_station_generationPower"
          state_topic: "solarmanpv/station/generationPower"
          unit_of_measurement: "W"
          state_class: measurement

        - name: "solarmanpv_inverter"
          state_topic: "solarmanpv/inverter/deviceState"
          json_attributes_topic: "solarmanpv/inverter/attributes"
        
        - name: "solarmanpv_logger"
          state_topic: "solarmanpv/logger/deviceState"
          json_attributes_topic: "solarmanpv/logger/attributes"

whereas yours were

        - state_topic: "solarmanpv/station/generationPower"
          name: "solarmanpv_station_generationPower"
          unique_id: "generatedPower"
          unit_of_measurement: "Wh"
          device_class: energy
          state_class: measurement
       
        - state_topic: "solarmanpv/inverter/deviceState"
          name: "solarmanpv_inverter"
          unique_id: "solarmanpv_inverter"
          json_attributes_topic: "solarmanpv/inverter/attributes"
        
        - state_topic: "solarmanpv/logger/deviceState"
          name: "solarmanpv_logger"
          unique_id: "solarmanpv_logger"
          json_attributes_topic: "solarmanpv/logger/attributes"

Do you see any visible mistake ?

I need another set of eyes on this. Can anyone help please?

I’m trying to retrieve the inverter stats using realTime - see 4.5 / page 81 of the Solarman Open API.

The following curl:

curl --request POST \
  --url 'https://api.solarmanpv.com/station/v1.0/realTime?appId=20...&language=en&=' \
  --header 'Authorization: bearer eyJ...' \
  --header 'Content-Type: application/json' \
  --data '{"stationId": 269....}'

Behaves and returns:

{
    "code": null,
    "msg": null,
    "success": true,
    "requestId": "eef76a37edf3bd2e",
    "generationPower": 0.0,
    "usePower": 561.0,
    "gridPower": null,
    "purchasePower": null,
    "wirePower": 0.0,
    "chargePower": null,
    "dischargePower": 598.0,
    "batteryPower": 598.0,
    "batterySoc": 87.0,
    "irradiateIntensity": null,
    "lastUpdateTime": 1664042387.000000000
}

But

  - platform: rest
    resource: https://api.solarmanpv.com/station/v1.0/realTime?appId=20..&language=en&=
    method: POST
    name: solarman_inverter_data
    scan_interval: 60
    headers:
     Authorization: bearer eyJ...
     Content-Type: application/json
    payload: '{  "stationId": 269...}'
    json_attributes:
      - dataList
    value_template: 'OK'

…isn’t returning anything (nothing in the logs). Can anyone identify the problem between the keyboard and seat? Grateful to all who even reads!

Edit: Problem solved by specifying the requested params. Data much more useful now!!!

Anyone using the deye/sunsynk inverter with batteries?

I searched the web for information on the solarman API capabilities but can’t find anything so far. Biggest question I have is if it possible to instruct the battery to charge and discharge through an api call.

Any thoughts/experiences are much appreciated!

Wow can you tell us exactly what rest api you added to configuration yaml? and do you use a template to put data up in energy dashboard? how ?

Thanks in advance

Thanks! It worked very well :smiley:

Hello Skully!
Thanks for the method proposed but I have a problem I cannot get out.
At step 4, I get the following message:
{
“code”: “2101006”,
“msg”: “invalid param”,
“success”: false,
“requestId”: “ee42a0ebadbe7a10”
}
And I do not understand how to proceed. I have checked all the input proposed without success.
A question: DeviceSn is the serial number of the inverter or the logger?
I have tried both with the same result.
Any suggestion? Thanks in advance

Hi, I have the same problem. Have you been able to figure it out yet?

Sincere apologies for my very late reply… been distracted with a building job that needed finishing before autumn turns to winter. I’m a bit ashamed to be honest that you asked for help and I didn’t quicker.

I get real time data as follows. Sensors:

  - platform: rest
    resource: https://api.solarmanpv.com/station/v1.0/realTime?appId=...&language=en&=
    method: POST
    name: solarman_inverter_data
    scan_interval: 60
    headers:
     Authorization: bearer ..---
     Content-Type: application/json
    payload: '{ "stationId": "" }'
    json_attributes:
      - batteryPower
      - batterySoc
      - chargePower
      - dischargePower
      - generationPower
      - gridPower
      - usePower
      - wirePower
    value_template: 'OK'

  - sensor:
      - name: "solarman_inverter_generationPower"
        unit_of_measurement: "W"
        state: "{{ state_attr('sensor.solarman_inverter_data','generationPower') | round(2, default=0) }}"
        unique_id:  solarman_inverter_generationPower
        device_class: "power"
        state_class: "measurement"

etc for charge/discharge power… Then meter it:

  - platform: integration
    source: sensor.solarman_inverter_generationPower
    name: integral_solarman_inverter_generationPower
    unit_prefix: k
    round: 3
    method: left

  meter_solarman_inverter_generationpower_hourly:
    source: sensor.integral_solarman_inverter_generationpower
    cycle: hourly
  meter_solarman_inverter_generationpower_daily:
    source: sensor.integral_solarman_inverter_generationpower
    cycle: daily

Apexchart does nice job of plotting.

I’m ultimately still going to read the data directly using another pi and modbus. I need winter and time for that though… For now it’s good enough.

Oh no no its completely okay. Thanks to the delay I got to learn you can request update time decrease to 1 minute from 5-10 minutes (default) by emailing Solarman team. Its not real time but pretty close to it directly on Solarman app without any effort.

Let me try your provided configuration and get back with more questions!

Thanks again!

Following steps above my API access has been working just fine…

Today stopped working though (renewed access token not that long ago) …

I’ve gone to renew the token again today as per step 2 but i get error as below. Just me? have they revoked my API access or others have the same?

‘{
“code”: “xxx”,
“msg”: “appId insufficient allowance”,
“success”: false,
“requestId”: “xxx”
}’

EDIT: Hmm possibly ignore me … seems I somehow got my id & key mixed up … Working now again.

A search for Deye inverters brought me on this post. Can those inverters be integrated with home assistant?

My exact model is

SUN-12K-SG04LP3

Hmmm I am again getting this same error. This time no confusion regarding my id & key … Anyone else have the same? I’ve emailed support to confirm my API access is still OK.

Also is there a way to know more sensors ?

Specifically I wish to know when is charging the battery and when is getting current from the vbbattery

@goancea, I’m very happy with this solution which obtains data locally from the solar datalogger, without having to use a cloud api and without having to readout the inverter with its specific modbus registers. Your solution works really well and I imagine it will be useful for many similar (rebranded) data loggers / wifi sticks: Solarman, Solis, Sofar, Omnik, AEG, Deye, etc!

I slightly tweaked some of the code, and also added in a “template sensor”, so that the solar power production can be added to the Home Assistant “Energy Dashboard”.

# Solarman local logger
sensor:
  - name: solarmanlocal_power_solar_now
    platform: command_line  
    command: curl -s -u admin:admin http://192.168.1.241/status.html | grep -E "\webdata_now_p(\s|$)" | cut -d'"' -f 2
    unit_of_measurement: 'W'
    scan_interval: 10
  - name: solarmanlocal_power_solar_today
    platform: command_line  
    command: curl -s -u admin:admin http://192.168.1.241/status.html | grep -E "\webdata_today_e(\s|$)" | cut -d'"' -f 2
    unit_of_measurement: 'kWh'
    scan_interval: 60
  - name: solarmanlocal_power_solar_total
    platform: command_line  
    command: curl -s -u admin:admin http://192.168.1.241/status.html | grep -E "\webdata_total_e(\s|$)" | cut -d'"' -f 2
    unit_of_measurement: 'kWh'
    scan_interval: 60
    
template:
  sensor:
  - name: "solarmanlocal_production_daily"
    state: "{{ states('sensor.solarmanlocal_power_solar_total')}}"
    unit_of_measurement: kWh
    device_class: energy
    state_class: total_increasing
    unique_id: solarmanlocal_production_daily

As a note to other users, of which you are probably already aware: “webdata_today_e” gives unreliable values which sometimes decrease throughout the day, which should not technically be possibly and does not match up with the other two variables, best to avoid using this variable.

I’ve also validated the above code and mechanism (curling data via webinterface of the solar datalogger) and it matches up very well with the power readings of my meter (my solar panels are alone on their own phase in my meter).

Thanks for that!

Is there a way to include the locally pulled data into the Home Assistant Energy dashboard, e.g. to display the hourly Solar production?

For pulling data via WLAN from the inverter, I’ve been using this HA integration:

However, in the Energy dashboard the bar chart for hourly Sorlar production starts off with a negative value in the morning.
The value of previous day total seems to be stored overnight. When the inverter starts up the next day, the value seems to be reset to zero by subtracting the previous day’s solar production.

Have not found a solution for this issue yet.
With a helper entitity (Utility meter) I could also not get it to work.

Maybe somebody has found a solution for this or has an idea?
Would like to avoid going over the Solarman cloud and prefer to do it based on locally pulled data (via LAN).

1 Like

I have the exact problem like you. With an no name inverter and solarman logger with was older, everything worked perfect. No negative values in the morning or any other problems. But, I’ve changed my inverter with an INVT IMARS, witch has a newer solarman logger, and had the exact problems like you. So I was forced to don’t use the read data directly from logger method and to use the API method. Data are a little late that direct data collecting … but … at least is working correctly. I’ve tried also utility meter reset, calibrate … etc but no go. It seams that the software of the loggers are different and some of them are connecting to older solarman platform (the ones that are working ok with direct data reading solution ), and other to newer solarman platform (the ones that are giving bad values at start and at stop of the inverter). I could not find any solution to modify logger firmware also, I would like to try with an older firmware, but … no go also. So until someone find a good solution to get rid of those bad data at start and stop of the inverter … I will use API method.

Hello, I sent API access request to Solarman a week ago but no response so far. How long did you wait?

Just to document it here as well:

I ran into following response when getting the bearer token:

{"code":"2101025","msg":"{\"error\":\"invalid_request\",\"error_description\":\"\",\"code\":\"AUTH_INVALID_USERNAME_OR_PASSWORD\",\"param\":null}","success":false,"requestId":"4b47a1cf11111111","access_token":null,"token_type":null,"refresh_token":null,"expires_in":null,"scope":null,"uid":null}%  

In my case the password at Solarman was too long and contained special characters. A 16 character ASCII password did the trick.