Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Andremain evohome heating r1.1 #79606

Open
wants to merge 27 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
8600155
Add files via upload
mihaiberindei Dec 5, 2022
a126699
update
mihaiberindei Dec 8, 2022
7829a36
Update enlighten-solar-system-1.groovy
mihaiberindei Dec 8, 2022
02e2150
Update enlighten-solar-system-1.groovy
mihaiberindei Dec 8, 2022
e3adee8
Merge branch 'SmartThingsCommunity:master' into master
mihaiberindei Dec 8, 2022
453751c
Update enlighten-solar-system-1.groovy
mihaiberindei Dec 9, 2022
d90d6b0
Add files via upload
mihaiberindei Dec 9, 2022
5a39018
Add files via upload
mihaiberindei Dec 9, 2022
01c611b
Add files via upload
mihaiberindei Dec 9, 2022
afcab44
Update enlighten-solar-system-1.groovy
mihaiberindei Dec 9, 2022
89b5c5d
Update enlighten-solar-system-1.groovy
mihaiberindei Dec 9, 2022
2f0e3dc
grid
mihaiberindei Dec 9, 2022
19b3790
Update enlighten-solar-system-1.groovy
mihaiberindei Dec 9, 2022
ea784c0
Update enlighten-solar-system-1.groovy
mihaiberindei Dec 9, 2022
c569133
Create Fusion solar huawei
mihaiberindei Dec 9, 2022
5a1f0da
Create Huawei
mihaiberindei Dec 9, 2022
35fdd5e
Update enlighten-solar-system-1.groovy
mihaiberindei Dec 9, 2022
32098fa
Update enlighten-solar-system-1.groovy
mihaiberindei Dec 9, 2022
573b0cb
Update enlighten-solar-system-1.groovy
mihaiberindei Dec 10, 2022
73fa33a
Update enlighten-solar-system-1.groovy
mihaiberindei Dec 10, 2022
8e19909
Update enlighten-solar-system-1.groovy
mihaiberindei Dec 10, 2022
848bc8c
Evohome (Connect) 2.3
mihaiberindei Jan 17, 2023
77eda21
new
mihaiberindei Jan 17, 2023
1440c35
Create Evohome (Connect) 2.3
mihaiberindei Jan 17, 2023
88200a1
new
mihaiberindei Jan 17, 2023
0c8de8f
Rename Evohome (Connect) 2.3 to evohome-connect1.groovy
mihaiberindei Jan 18, 2023
1e08cd2
Create evohome-connect.groovy
mihaiberindei Jan 18, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1,680 changes: 1,680 additions & 0 deletions devicetypes/Evohome (Connect) 2.3

Large diffs are not rendered by default.

214 changes: 214 additions & 0 deletions devicetypes/Fusion solar huawei
Original file line number Diff line number Diff line change
@@ -0,0 +1,214 @@
'''
Before running this source file make sure you follow the instructions
from https://forum.huawei.com/enterprise/en/communicate-with-fusionsolar-through-an-openapi-account/thread/591478-100027?page=3

You can't access Fusion Solar devices without an OpenAPI account previously created.
'''

import requests
import json
import sys

'''
OpenAPI URLs
@login_url : Login url for POST method.
@logout_url : Logout url for POST method.
@get_station_list_url : Get stations list url for POST method.
@real_time_data_url : Power station info url for POST method.
'''
login_url = 'https://eu5.fusionsolar.huawei.com/thirdData/login'
logout_url = 'https://eu5.fusionsolar.huawei.com/thirdData/logout'
get_station_list_url = 'https://eu5.fusionsolar.huawei.com/thirdData/getStationList'
real_time_data_url = 'https://eu5.fusionsolar.huawei.com/thirdData/getStationRealKpi'


'''
OpenAPI variables.

@username : OpenAPI username.
@password : OpenAPI password.
@xsrf_token : Session token returned by login method.
@plant_name : Plant name to be interrogated.
@station_code : Station code returned by get statil list method
'''
username = ''
password = ''
xsrf_token = ''
plant_name = ''
station_code = ''

def read_credentials():
"""
Function to read OpenAPI credentials (username/password).
"""
global username
global password

print ("Enter OpenAPI Credentials")
username = input("Username: ")
password = input("Password: ")


def openapi_login():
"""
Perform login to OpenAPI account.

Requires username and passowrd and return session token in response cookie.
"""

global xsrf_token
login_obj = {
"userName" : username,
"systemCode" : password
}

# Send login request
response = requests.post(
login_url,
json = login_obj,
cookies = {"web-auth" : "true", "Cookie_1" : "value"},
timeout = 3600
)

# Inspect login response
try:
json_status = json.loads(response.content)
if json_status['success'] == False:
print ("ERROR: Login Failed")
sys.exit()

print ("INFO: Login Successfully")

except ValueError:
print ("ERROR: Login unexpected response from server")

# Get session cookie (xsrf-token)
cookies_dict = response.cookies.get_dict()
if "XSRF-TOKEN" not in cookies_dict:
print ("ERROR: XSRF-TOKEN not found in cookies")
sys.exit()

xsrf_token = cookies_dict.get("XSRF-TOKEN")
print ("XSRF-TOKEN: %s" % xsrf_token)

def openapi_get_station_list():
"""
Read station list for current user.

Require session token.
"""
global station_code
global plant_name
plant_obj = {}

# Send get station list request
response = requests.post(
get_station_list_url,
json = plant_obj,
cookies = {"XSRF-TOKEN" : xsrf_token, "web-auth" : "true"},
headers = {"XSRF-TOKEN": xsrf_token},
timeout = 3600
)

# Inspect response
try:
json_plant = json.loads(response.content)
if json_plant['success'] == False:
print ("ERROR: Get Station List Failed")
openapi_logout()
sys.exit()

except ValueError:
openapi_logout()
print ("ERROR: Get station list unexpected response from server")
sys.exit()

# read plant name
plant_name = input("Enter plant name: ")

print ("INFO: Stations list:")
# plant name lookup inside plants list
for station in json_plant['data']:
if "stationName" not in station:
print ("ERROR: Unknown format in get station list response")
openapi_logout()
sys.exit()

print ("INFO: Station name : %s; Station code : %s" % (station.get('stationName'), station.get('stationCode')))
if station.get('stationName') == plant_name:
station_code = station.get('stationCode')

if station_code == '':
print ("ERROR: Plant name %s not found in station list" % plant_name)


# OpenAPI Read Station Real TimeData
def openapi_real_time_data():
rtime_obj = { "stationCodes" : station_code }

# Send real time data request
response = requests.post(
real_time_data_url,
json = rtime_obj,
cookies = {"XSRF-TOKEN" : xsrf_token, "web-auth" : "true"},
headers = {"XSRF-TOKEN": xsrf_token},
timeout = 3600
)

# Evaluate real time response
try:
json_rtime = json.loads(response.content)
if json_rtime['success'] == False:
print ("ERROR: Real Time Information Failed")
openapi_logout()
sys.exit()

except ValueError:
openapi_logout()
print ("ERROR: Plant list unexpected response from server")


print ("INFO: Real time data for %s station:" % plant_name)
# Print values
for data_obj in json_rtime['data']:
map_obj = data_obj.get('dataItemMap')
print ("Day power : %s" % map_obj.get('day_power'))
print ("Month power : %s" % map_obj.get('month_power'))
print ("Total power : %s" % map_obj.get('total_power'))
print ("Health State : %s" % map_obj.get('real_health_state'))


def openapi_logout():
"""
Perform logout to OpenAPI account.

Requires session token.
"""
logout_obj = { "xsrfToken" : xsrf_token }

# Send logout request
response = requests.post(
logout_url,
json = logout_obj,
cookies = {"XSRF-TOKEN" : xsrf_token, "web-auth" : "true"},
headers = {"XSRF-TOKEN": xsrf_token}
)

# Inspect logout response
try:
json_status = json.loads(response.content)
if json_status['success'] == False:
print ("ERROR: Logout Failed")
sys.exit()

print ("INFO: Logout Successfully")
except ValueError:
print ("ERROR: Logout unexpected response from server")


if __name__ == "__main__":
read_credentials()
openapi_login()
openapi_get_station_list()
openapi_real_time_data()
openapi_logout()
Binary file not shown.
Loading