Integracja chmury s...
 
Powiadomienia
Wyczyść wszystko

Integracja chmury solarman z domoticzem

1 Wpisów
1 Użytkownicy
1 Reactions
171 Wyświetleń
kniazio
(@kniazio)
Wpisów: 210
Pomocny Donator 2K21
Autor tematu
 

Może komuś się przyda

Aby zintegrować dowolny falownik który współpracuje z chmurą globalapi.solarmanpv.com trzeba napisać na adres customerservice@solarmanpv.com prośbę o odblokowanie API

W odpowiedzi otrzymamy regulamin. Należy odpisać, że przeczytaliśmy i że się zgadzamy.

W kolejnej odpowiedzi otrzymamy :
API ID:xxxxxxxxxxxx
API Secret: xxxxxxxxxxxxxxxxxxx
Dane te będziemy potrzebować do naszego skryptu

W domoticzu tworzymy czujnik "Electric(Instant+Counter) i w skrypcie podajemy jego IDX
Oto skrypt xxx.py który umieszczamy w katalogu /domoticz/scripts/python

Nadajemy skryptowi prawa wykonywalności oraz dodajemy do Crontab wykonanie skryptu np. co 5 minut

#!/usr/bin/env python3

import http.client, urllib.request, json, hashlib
from datetime import datetime

#Trannergy account details
apiSite   = "globalapi.solarmanpv.com"
appID     = "xxxxxxxxxxx"		#Change to your own appID, to be provided from Trannergy/Solarman
appSecret = "xxxxxxxxxx"		#Change to your own appSecret, to be provided from Trannergy/Solarman
email     = "xxxxxxxxxxx"		#Change to your own account name/mail address
password  = b"xxxxxxxxxxxxx"		#Change password to your own, maintain the b in front of the password as password need to be binary

conn      = http.client.HTTPSConnection(apiSite)
password = hashlib.sha256(password).hexdigest()

#domoticz settings
domoticz_host           = "xxxxxxxxx" #ip adress of the domoticz host
domoticz_port           = "xxxx"
domoticz_url            = "json.htm"
domoticz_ActualPower    = "xxx" #idx of new device

#Request access token, manaul chapter/routine 2.1
payload = json.dumps({
  "appSecret": appSecret,
  "email": email,
  "password": password
})
headers = {
  'Content-Type': 'application/json'
}
conn.request("POST", "/account/v1.0/token?appId="+appID+"&language=en", payload, headers)
res = conn.getresponse()
data = json.loads(res.read())
accesstoken = data['access_token']
print("Accesstoken :" +accesstoken)

#Request current power + lastupdate time + stationID, manual chapter/routine 4.4
payload = json.dumps({
  "page": 1,
  "size": 20
})
headers = {
  'Content-Type': 'application/json',
  'Authorization': 'bearer '+accesstoken
}
conn.request("POST", "/station/v1.0/list?language=en", payload, headers)
res = conn.getresponse()
data = json.loads(res.read())
stationID = str(data['stationList'][0]['id'])
currentpower = str(data['stationList'][0]['generationPower'])
lastupdatetime = int(data['stationList'][0]['lastUpdateTime'])
lastupdatetime = str(datetime.fromtimestamp(lastupdatetime))
print("Current Power :"+currentpower+"W")
print("Last update time :"+lastupdatetime)
print("StationID :"+stationID)

#Request deviceID + deviceSN, manual chapter/routine 4.2
payload = json.dumps({
  "deviceType": "INVERTER",
  "page": 1,
  "size": 10,
  "stationId": stationID
})
headers = {
  'Content-Type': 'application/json',
  'Authorization': 'bearer '+accesstoken
}
conn.request("POST", "/station/v1.0/device?language=en", payload, headers)
res = conn.getresponse()
data = json.loads(res.read())
deviceID = str(data['deviceListItems'][0]['deviceId'])
deviceSN = str(data['deviceListItems'][0]['deviceSn'])
print('Device serial : '+deviceSN)
print('Device ID : '+deviceID)

#Total generated power, manual chapter/routine 3.3
payload = json.dumps({
  "deviceSn": deviceSN,
  "deviceId": deviceID
})
headers = {
  'Content-Type': 'application/json',
  'Authorization': 'bearer '+accesstoken
}
conn.request("POST", "/device/v1.0/currentData?language=en", payload, headers)
res = conn.getresponse()
data = json.loads(res.read())
multiply='1000.0'
totalgenpower = float(data['dataList'][23]['value']) * float(multiply)
totalgenpower = str(totalgenpower)
print("Total generated power: " +totalgenpower+"W")

#uploading values to domoticz
url = ("http://" + domoticz_host + ":" + domoticz_port + "/" + domoticz_url+ "?type=command&param=udevice&idx=" + domoticz_ActualPower+ "&nvalue=0&svalue=" + currentpower+ ";" + totalgenpower)
urllib.request.urlopen(url)
print(url)
 
Dodane : 23/06/2024 8:55 pm
pawell32 reacted
Udostępnij: