Hi,
Sorry if this is not the correct forum to post, not sure where to put this.
I have a script that pulls data from my solarpanel production and has up until a week ago working great.
Do to some issues with upgrading to python, the script started to fail.
Now I have downgraded and the script is again able to fetch data from my solarpanel inverter.
The problem is that the script won't update the HS3 devices any more.
Is there anyone that could take a look at this code and see if there is any obvious problems?
I'm out of ideas.
I get no error when I run the script.
Sorry if this is not the correct forum to post, not sure where to put this.
I have a script that pulls data from my solarpanel production and has up until a week ago working great.
Do to some issues with upgrading to python, the script started to fail.
Now I have downgraded and the script is again able to fetch data from my solarpanel inverter.
The problem is that the script won't update the HS3 devices any more.
Is there anyone that could take a look at this code and see if there is any obvious problems?
I'm out of ideas.
I get no error when I run the script.
PHP Code:
#!/usr/bin/python
import requests
import urllib, urllib2
#config
username = 'XXX' #your username
password = 'XXX' #your password
domain = 'm.ginlong.com' #domain
plantId = 'XXX' #plant id
lan = '2' #lanuage (2 = English)
#Homeseer settings
hs_host = 'localhost'
hs_port = '80'
hs_url = 'JSON'
hs_ActualPower = '183' #refid of new device
hs_etoday = '190' #refid of new device
hs_etotal = '192'
# Create session for requests
session = requests.session()
#building url
url = 'http://'+domain+'/cpro/login/validateLogin.json'
params = {
"userName": username,
"password": password,
"lan": lan,
"domain": domain,
"userType": "C"
}
#login call
resultData = session.post(url, params=params)
resultJson = resultData.json()
if resultJson['result'].get('isAccept') == 1:
print("Login Succesfull!")
else:
print("Login Failed!!")
Exit()
# Get plant details
url = 'http://'+domain+'/cpro/epc/plantDetail/showPlantDetailAjax.json'
params = {
'plantId': int(plantId)
}
cookies = {'language': lan}
resultData = session.get(url, params=params, cookies=cookies)
resultJson = resultData.json()
TodayIncome = resultJson['result']['plantAllWapper']['plantData'].get('incomeTotal')
ActualPower = resultJson['result']['plantAllWapper']['plantData'].get('power')
etoday = resultJson['result']['plantAllWapper']['plantData'].get('energyToday')
etotal = resultJson['result']['plantAllWapper']['plantData'].get('energyTotal')
multiply='1000.0'
etotal1000 = float(etotal) * float(multiply)
etotalstr=str(etotal1000)
#logging values
print('TodayIncome: ' + str(TodayIncome))
print('ActualPower: ' + str(ActualPower))
print('etoday: ' + str(etoday))
print('etotal: ' + str(etotal))
print('etotal 1000: ' + str(etotalstr))
#uploading values to Homeseer
url = ("http://" + hs_host + ":" + hs_port + "/" + hs_url+ "?request=controldevicebyvalue&ref=" + hs_ActualPower+ "&value=" + str(ActualPower))
urllib.urlopen(url)
url = ("http://" + hs_host + ":" + hs_port + "/" + hs_url+ "?request=controldevicebyvalue&ref=" + hs_etoday+ "&value=" + str(etoday))
urllib.urlopen(url)
url = ("http://" + hs_host + ":" + hs_port + "/" + hs_url+ "?request=controldevicebyvalue&ref=" + hs_etotal+ "&value=" + str(etotal))
urllib.urlopen(url)
Comment