-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
302b0c2
commit 4a963aa
Showing
11 changed files
with
689 additions
and
169 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
# Name: solar.py | ||
# Author: Jan Leenders | ||
# Description: | ||
# Defines the function(s) to get the solar data (only for supported systems). Currently: | ||
# enphase | ||
# fronius | ||
# | ||
|
||
import requests | ||
import json | ||
|
||
session = requests.Session() # setup a session on behalf of requests to solar system | ||
|
||
def get_datapoint(solar_system, solar_request_path ): | ||
return_value= {'actual': 0.0, 'total': 0.0} | ||
|
||
try: | ||
if solar_system == 'enphase': | ||
watt_production_data = session.get(solar_request_path + '/api/v1/production').text | ||
return_value['actual'] = json.loads(watt_production_data)["wattsNow"] | ||
return_value['total'] = float(json.loads(watt_production_data)["wattHoursLifetime"]) / 1000 # should be in kWh | ||
if solar_system == 'fronius': | ||
watt_production_data = session.get(solar_request_path + | ||
'/solar_api/v1/GetInverterRealtimeData.cgi?Scope=System&DataCollection=CommonInverterData').text | ||
return_value['actual'] = json.loads(watt_production_data)["Body"]["Data"]["PAC"] | ||
return_value['total'] = float(json.loads(watt_production_data)["Body"]["Data"]["TOTAL_ENERGY"]) / 1000 # should be in kWh | ||
|
||
except Exception: | ||
pass | ||
|
||
return return_value |
Oops, something went wrong.