Collect Inverter data from Solarman API

Hey folks, I have figured it out a way how to extract the relevant device info from the massive json file and output these data in csv format for further analysis.

Let’s say the massive json file is stored in DEVICE_DATE:

DEVICE_DATA=$(curl --request POST --url "${API_HOST}/device/v1.0/historical?appId=${APP_ID}&language=en" --header "Authorization: Bearer ${ACCESS_TOKEN}" --header "Content-Type: application/json" --data '{"deviceSn": "'"$DEVICE_SN"'","timeType": 5,"startTime": "'"${START_TIME}"'","endTime": "'"${END_TIME}"'"}')

I used the following to extract my relevant device info from DEVICE_DATA and output it to an external file in csv format.

echo "Time,Total Power Generation(W),Total Grid Power(W),Total Consumption Power(W),Battery Power(W),SoC(%)" > "${RELEVANT_DEVICE_DATA_FILE}"
echo "${DEVICE_DATA}" | jq -r '
    .paramDataList[].dataList | reduce .[] as $item ({};
        if $item.name == "System Time" then . + {SystemTime: $item.value}
      elif $item.name == "Total Power Generation" then . + {TotalPowerGeneration: $item.value}
      elif $item.name == "Total Grid Power" then . + {TotalGridPower: $item.value}
      elif $item.name == "Total Consumption Power" then . + {TotalConsumptionPower: $item.value}
      elif $item.name == "Battery Power" then . + {BatteryPower: $item.value}
      elif $item.name == "SoC" then . + {SOC: $item.value}
      else . end)
      | [.SystemTime, .TotalPowerGeneration,.TotalGridPower,.TotalConsumptionPower,.BatteryPower,.SOC]
      | @csv | gsub("\""; "")' >> "${RELEVANT_DEVICE_DATA_FILE}"

This works brilliantly for me.

The name of each item may be different for your inverter. So check that out from the dataList in the massive json file. You could list all the item’s names using the following command:

echo $DEVICE_DATA | jq -r '.paramDataList[].dataList[].name'

I’m coming across an issue when I get to step 4 in the top post

I get the following error

{
“msg”: “auth invalid token”,
“code”: “2101019”,
“success”: false,
“requestId”: “a613fd6218b7f2b2”
}

I have the app token from step 3 but can’t see where I’m going wrong

Edit:: I’ve resolved the API issue so looks to be working, however the next part is getting it integrated to Energy Dashboard, I’m stuck at this part now.

I’m up to step 7 in post number 1 I can’t see my sensor I created following the steps provided, what am I doing wrong?

I can see on the json path finder the item I want which is Cumulative Production (Active) which is line 91, should the value template in the Home assistant config file show the following?

value_template: “{{ value_json.dataList[91].value }}”

Edit: In the energy dashboard for the solar production i can see * sensor.cumulative_production_active but i get the following error:

Entity not defined

Check the integration or your configuration that provides:

  • sensor.cumulative_production_active

What am I missing?

Hi everyone!

I created a custom integration to collect the data from the API:

Works for me, but give it a try if you are interested. I will see if I can integrate any feedback.

Bonjour Daspilker, j’ai ajouter ton intégration et je ne comprend pas sa me marque dans la case diagnostic 14 entité desactiver?

Hi Daniel Im experimenting with diagnostic file. I want to create another entity of Inverter state. It is possible?

Thank you Skully, et al. Great thread and instructions.

I’m stuck I think at the last hurdle.

I’ve got the key from Solarman and can get to the data using https://reqbin.com/curl so I know I have access.

I can see the path and value in json path finder.

But…I can’t get HA to get and/or display a value.

I feel this is a formatting issue with how I’ve set up configuration.yaml

Sage guidance needed please…

think you might be missing the actual dataList/json_attributes in your sensor…so everything is working as you have it set up but you are not actually bringing in the dataList anywhere…

add this to your template and you should be up and running
(add it in line with headers and payload:)

json_attributes:
      - dataList
1 Like

Isn’t that in the last line of my configuration.yaml. ?

No, that’s just a single value you are showing in the sensor…if you want to bring back all of the data from the API you’d either need multiple sensors or to capture it into the attributes of this sensor (and then split out the values you want to see using more template sensors)…that’s what’s working for me anyway

1 Like

Got it! Some of the posts above show the token wrapped in " or ’ in configuration.yaml which is what I’d done. Removed these and ta dA!

Now off to add all the other sensors.

1 Like

Hello,
I am trying to obtain the beartoken with the request:

curl --location --request POST 'https://globalapi.solarmanpv.com/account/v1.0/token?appId=APPID&language=en' \
  --header 'Content-Type: application/json' \
  --data-raw '{
  "appSecret": "xxxx",
  "email": "xxxxx",
  "password": "xxxxxxx"
}'

Unfortunately, I always get this response.

{
    "code": "2101009",
    "msg": "appId or api is locked",
    "requestId": "xxxxxxx",
    "success": false
}

Do I need to unlock the API somewhere?

you probably forgot to hash the password: Collect Inverter data from Solarman API - #183 by Tomasz1

also: don’t forget to insert the APPid in the first line.

Great, that worked. It was the missing ID. I’m trying to download the data, but unfortunately I’m getting a similar error again.

curl --request POST \
  --url 'https://api.solarmanpv.com/device/v1.0/currentData?appId=3xxxxx2&language=en&=' \
  --header 'Authorization: bearer eyJhbGxxxxxxxxxxx' \
  --header 'Content-Type: application/json' \
  --data '{
	"deviceSn": "SPxxxxx8"
}'

{
    "code": "2101009",
    "msg": "appId or api is locked",
    "success": false,
    "requestId": "93cb470ace86f55ad7b1e87918bca603"
}

Does anyone have any ideas?

THX

I found my mistake.

The URL was incorrect:

You have to use:

'https://globalapi.solarmanpv.com/device/v1.0/curre

I’ve made some updates to this, that includes more metrics that suits my inverter.

You can find it at GitHub - sofarbattery/home-assistant-solarman-api: Solarman API integration for Home Assistant

Basically I’ve updated home-assistant-solarman-api/custom_components/solarman_api/sensor.py at 13890fb5deb8157afe47757d1bfcbdc146c85793 · sofarbattery/home-assistant-solarman-api · GitHub

Today I tried again using this method to collect sensors from my solarman installation after getting a not available error. This happens always after a couple of months.
This method did work for years for me.
But today step 2 is giving a timeout and not giving result.
Beside this step 1 is creating constantly a different bearer
Someone experencing the same?
Is there a solution?

EDIT: it is running again. I quess it was a hickup at solarman API
I did install GitHub - daspilker/home-assistant-solarman-api: Solarman API integration for Home Assistant also.
That is working nice!