Collect Inverter data from Solarman API

Hello,

No, is not working , I have the same issue but I do not think is from the way we collect data, because if I look at the sensor data I see the correct data

In above picture , 10.68 is the state in HA and on the logger Yield today10.87 kWh

I really do not know what is the problem.

I removed all the other sensors from Energy Dashboard , just to test:

Any thoughts are welcomed :slight_smile:

I hope there will be a implementation to HACS for this one day. This is quiete complicated for a noob like me.

1 Like

Hi Skully,
thanks for sharing your knowledge on the Solarman API.
As far as I understand OAuth 2.0 API architecture, appID and appSecret are means to identify your app at the Solarman API. It’s not a credential in that sense. For security, you pass the user’s credentials and receive a token which from there on identifies your user.
Customer service at solarmanpv has become very hesitant to provide appID and appSecret for new apps meanwhile, because apparently a lot of projects on gitHub misunderstood this fact such that now every user is requesting an own appID from their service desk.

Your app can use the access_token for all further API calls on the other functions as long as the token has not expired. Logically, you can also skip the appId parameter in your example where you call device/v1.0/currentData. The documentation provided by solarmanpv is quite clear in that.

How much further experience have you gained with this API? Have you meanwhile found out how to use the refresh_token? As soon as the access_token has expired, this should be used to obtain a new refresh_token in order to save the need to re-communicate the user’s credentials again.
I tried with grant_type=refresh_token&refresh_token=<resfresh-token> as defined per OAuth spec, but I failed to get it work.

Regards,
stedon81

What do I add in template/or anywhere else to use/show Battery data in the Energy Dashboard?

I thought I went past that step but it appears the data ain’t pulling via mqtt. How do we debug this?

Also, No webdata_now_p parameter data :frowning:

Any idea why?

All, sorry to hear all the issues. Like my previous response, https://github.com/lechk82/solarman-mqtt is working like a charm for a couple of months already:

  • no issues with expiring tokens
  • no issues with timings
    it just works flawlessly!

In short:

  1. Follow the link above
    I’m using the docker-compose method. If you do as well, make sure the config.jason file is located at the correct location. Use the logging to see the output. It should be something similar like:

    oh btw, if the DeviceState = 1, the sun is shining :grinning:, DeviceState = 3: Inverter is offline
  2. The config.jason formatting is not that well documented, please use the following:
{
  "name": "Trannergy",
  "url": "api.solarmanpv.com",
  "appid": "<id>",
  "secret": "<secret>",
  "username": "<username>",
  "passhash": "<hased password>",
  "stationId": <stationid>,
  "inverterId": "<inverterid>",
  "loggerId": "<loggerid>",
  "debug" : false,
  "mqtt":{
    "broker": "<broker ip>",
    "port": 1883,
    "topic": "solarmanpv",
    "username": "<broker username>",
    "password": "<broker password>"
  }
}
  1. Install, if you havent already, a MQTT broker like: MQTT - Home Assistant
  2. Do use something like MQTT-Explorer to see if the messages are coming in like:
  3. Add the following in your configuration.yaml:
mqtt:
  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"

sensor:
  - platform: template
    sensors:
      solarmanpv_inverter_device_state:
        unique_id: "inverter_device_state"
        value_template: >-
          {% set mapper =  {
              '1' : 'Online',
              '2' : 'Failure',
              '3' : 'Offline'} %}
          {% set state =  states.sensor.solarmanpv_inverter.state %}
          {{ mapper[state] if state in mapper else 'Unknown' }}

  - platform: template
    sensors:
      solarmanpv_logger_device_state:
        unique_id: "logger_device_state"
        value_template: >-
          {% set mapper =  {
              '1' : 'Online',
              '2' : 'Failure',
              '3' : 'Offline'} %}
          {% set state =  states.sensor.solarmanpv_logger.state %}
          {{ mapper[state] if state in mapper else 'Unknown' }}
          
template:
  - sensor:
    - name: "Solarman energy daily"
      unique_id: "solarman_energy_daily"
      unit_of_measurement: 'kWh'
      state: "{{ state_attr('sensor.solarmanpv_inverter', 'Daily_Production_(Active)') }}"
      device_class: energy
      state_class: total_increasing
      attributes:
        last_reset: '1970-01-01T00:00:00+00:00'

  - sensor:
    - name: solarmanpv_inverter_dc_voltage_pv1
      unique_id: "solarmanpv_inverter_dc_voltage_pv1"
      unit_of_measurement: 'V'
      state: "{{ state_attr('sensor.solarmanpv_inverter', 'DC_Voltage_PV1') }}"
      state_class: measurement

  - sensor:
    - name: solarmanpv_inverter_dc_current_pv1
      unique_id: "solarmanpv_inverter_dc_current_pv1"
      unit_of_measurement: 'A'
      state: "{{ state_attr('sensor.solarmanpv_inverter', 'DC_Current_PV1') }}"
      state_class: measurement

  - sensor:
    - name: solarmanpv_inverter_dc_voltage_testing
      unique_id: "solarmanpv_inverter_dc_current_testing"
      unit_of_measurement: 'V'
      state: "{{ state_attr('sensor.solarmanpv_inverter', 'DC_Voltage_PV1') }}"
      state_class: measurement
      unit_of_measurement: 'A'
      state: "{{ state_attr('sensor.solarmanpv_inverter', 'DC_Current_PV1') }}"
      state_class: measurement

  - sensor:
    - name: solarmanpv_inverter_dc_voltage_pv2
      unique_id: " solarmanpv_inverter_dc_voltage_pv2"
      unit_of_measurement: 'V'
      state: "{{ state_attr('sensor.solarmanpv_inverter', 'DC_Voltage_PV2') }}"
      state_class: measurement

  - sensor:
    - name: solarmanpv_inverter_dc_current_pv2
      unique_id: "solarmanpv_inverter_dc_current_pv2"
      unit_of_measurement: 'A'
      state: "{{ state_attr('sensor.solarmanpv_inverter', 'DC_Current_PV2') }}"
      state_class: measurement
      
  - sensor:
    - name: solarmanpv_inverter_dc_power_pv1
      unique_id: "solarmanpv_inverter_dc_power_pv1"
      unit_of_measurement: 'W'
      state: "{{ state_attr('sensor.solarmanpv_inverter', 'DC_Power_PV1') }}"
      state_class: measurement
      
  - sensor:
    - name: solarmanpv_inverter_dc_power_pv2
      unique_id: "solarmanpv_inverter_dc_power_pv2"
      unit_of_measurement: 'W'
      state: "{{ state_attr('sensor.solarmanpv_inverter', 'DC_Power_PV2') }}"
      state_class: measurement
      
  - sensor:
    - name: solarmanpv_inverter_total_production
      unique_id: "solarmanpv_inverter_total_production"
      unit_of_measurement: 'kWh'
      state: "{{ state_attr('sensor.solarmanpv_inverter', 'Cumulative_Production_(Active)') }}"
      state_class: total_increasing
      
  - sensor:
    - name: solarmanpv_inverter_daily_production
      unique_id: "solarmanpv_inverter_daily_production"
      unit_of_measurement: 'kWh'
      state: "{{ state_attr('sensor.solarmanpv_inverter', 'Daily_Production_(Active)') }}"
      state_class: total_increasing

  - sensor:
    - name: solarmanpv_inverter_ac_radiator_temp
      unique_id: "solarmanpv_inverter_ac_radiator_temp"
      unit_of_measurement: '°C'
      state: "{{ state_attr('sensor.solarmanpv_inverter', 'Temperature-_Inverter') }}"
      state_class: measurement
      
  - sensor:
    - name: solarmanpv_inverter_ac_voltage_1
      unique_id: "solarmanpv_inverter_ac_voltage_1"
      unit_of_measurement: 'V'
      state: "{{ state_attr('sensor.solarmanpv_inverter', 'AC_Voltage_R/U/A') }}"
      state_class: measurement

  - sensor:
    - name: solarmanpv_inverter_ac_current_1
      unique_id: "solarmanpv_inverter_ac_current_1"
      unit_of_measurement: 'A'
      state: "{{ state_attr('sensor.solarmanpv_inverter', 'AC_Current_R/U/A') }}"
      state_class: measurement

  - sensor:
    - name: solarmanpv_inverter_ac_voltage_2
      unique_id: "solarmanpv_inverter_ac_volgage_2"
      unit_of_measurement: 'V'
      state: "{{ state_attr('sensor.solarmanpv_inverter', 'AC_Voltage_S/V/B') }}"
      state_class: measurement

  - sensor:
    - name: solarmanpv_inverter_ac_current_2
      unique_id: "solarmanpv_inverter_ac_current_2"
      unit_of_measurement: 'A'
      state: "{{ state_attr('sensor.solarmanpv_inverter', 'AC_Current_S/V/B') }}"
      state_class: measurement

  - sensor:
    - name: solarmanpv_inverter_ac_voltage_3
      unique_id: "solarmanpv_inverter_ac_voltage_3"
      unit_of_measurement: 'V'
      state: "{{ state_attr('sensor.solarmanpv_inverter', 'AC_Voltage_T/W/C') }}"
      state_class: measurement

  - sensor:
    - name: solarmanpv_inverter_ac_current_3
      unique_id: "solarmanpv_inverter_ac_current_3"
      unit_of_measurement: 'A'
      state: "{{ state_attr('sensor.solarmanpv_inverter', 'AC_Current_T/W/C') }}"
      state_class: measurement

  - sensor:
    - name: solarmanpv_inverter_ac_output_frequency
      unique_id: "solarmanpv_inverter_ac_output_frequency"
      unit_of_measurement: 'Hz'
      state: "{{ state_attr('sensor.solarmanpv_inverter', 'AC_Output_Frequency_R') }}"
      state_class: measurement
  1. Configure the energy dashboard, something like this:

As the energy dashboard refreshes on top of the hour, it could take up to 2 hours to get visuals on your dashboard as only a full hour is being visualised!

Good Luck :grinning:

1 Like

Thank you so much for the guide !

Why this though? Any idea?

Configuration file updated as per your guide.

This is most likely caused by not having the full 1-2 hours of data available to be reflected in the dashboard. After ignoring this for 2 hours, do you still see the errors?

Yea the error msg is same even though the data is there on solarman portal and container log isnt showing anything wrong either.

Please check:

template:
  - sensor:
    - name: "Solarman energy daily"
      unique_id: "solarman_energy_daily"
      unit_of_measurement: 'kWh'
      state: "{{ state_attr('sensor.solarmanpv_inverter', 'Daily_Production_(Active)') }}"
      device_class: energy
      state_class: total_increasing
      attributes:
        last_reset: '1970-01-01T00:00:00+00:00

This is a bit different than the mentioned in the tutorial of Lechk82. Also please check if you are running the latest HA version as there have been a few changes in how to configure MQTT sensors

Copied rom your code above… I was thinking to add battery attributes but I guess that challenge comes later :smiley:

Home Assistant 2022.9.5
Supervisor 2022.09.1
Frontend 20220907.2 - latest

You however added a space in attribute name before (Active) where as it states differently on github documentation.

Uhmm, I know formatting is key. Did you validate the configuration.yaml file? And checked to entity state? (Under development tools)

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