Solar Panels support - SolarmanPV

Hi, I’ve python script to get data from SolarmanPV portal. (http://www.solarmanpv.com/portal/Terminal/TerminalDefault.aspx)

I use it on my home webserver but this script cannot be run in Home Assistant. This script needs hashlib (this can be done without this liblary by make hash externally) and xml.etree. It’s very simple API call.

It will be great to have inverter data in HA :slight_smile:

script:

import urllib.request, hashlib
from xml.etree import ElementTree as ET

#config
username = ‘’ #portal username
password = ‘’ #portal password
baseURL = ‘http://www.solarmanpv.com:18000/SolarmanApi#API url
stationid = ‘’ #station id, key=xxxxx from portal address

m = hashlib.md5()
m.update(password.encode(‘utf-8’))

#request url with hashed password
requestURL = baseURL+‘/serverapi/Login?username=’+username+‘&password=’+m.hexdigest()+‘&key=apitest&client=iPhone’

#login call
root = ET.parse(urllib.request.urlopen(requestURL)).getroot()
token = root.find(‘token’).text

#info url
infoURL = baseURL+‘/serverapi/Data?key=apitest&username=’+username+‘&stationid=’+stationid+‘&token=’+token

#login call
infoRoot = ET.parse(urllib.request.urlopen(infoURL)).getroot()

#find data
income = infoRoot.find(‘income’)

#get data
ActualPower = income.find(‘ActualPower’).text
etoday = income.find(‘etoday’).text
etotal = income.find(‘etotal’).text
TotalIncome = income.find(‘TotalIncome’).text

#convert
ActualPower1000 = float(ActualPower) / float (‘1000.0’)
etotal1000 = float(etotal) / float(‘1000.0’)
etotalfloat = float(etotal)
etotal1000str=str(round(etotal1000,2))
etotalstr= str(round(etotalfloat,2))
actualpowerstr=str(round(ActualPower1000,2))

#logging values
print ('ActualPower kW: '+actualpowerstr)
print ('etoday kWh: '+etoday)
print ('etotal KWh: '+etotalstr)
print ('etotal MWh: '+etotal1000str)

Have you tried to get done with https://www.home-assistant.io/integrations/rest/ ?
or perhaps: https://www.home-assistant.io/integrations/scrape/