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

Add optimizer data to solaredge_local #26708

Merged
merged 38 commits into from Sep 21, 2019
Merged
Show file tree
Hide file tree
Changes from 29 commits
Commits
Show all changes
38 commits
Select commit Hold shift + click to select a range
369ffec
making SENSOR_TYPES universal
scheric Sep 18, 2019
c96622b
bump solaredge-local version 0.2.0
scheric Sep 18, 2019
6f52bcd
add maintenance data
scheric Sep 18, 2019
ef84887
add calculations for optimizer data
scheric Sep 18, 2019
0b2b6a5
add new sensors
scheric Sep 18, 2019
7853971
add statistics lib
scheric Sep 18, 2019
b04fc92
update sensor data setting
scheric Sep 18, 2019
6f3d985
making api requests universal
scheric Sep 18, 2019
e4c1dd5
fix Cl
scheric Sep 18, 2019
69833d0
Update requirements_all.txt
scheric Sep 18, 2019
8d68271
fix temperature
scheric Sep 18, 2019
e2c438f
fix f-strings
scheric Sep 19, 2019
6b093a1
Style guidelines
scheric Sep 19, 2019
b16b631
shortening line length
scheric Sep 19, 2019
508df81
PEP8 test
scheric Sep 19, 2019
17a0642
flake8
scheric Sep 19, 2019
fc4ea07
Black test
scheric Sep 19, 2019
53f5002
revert line length to 80
scheric Sep 19, 2019
22dfd77
Repair line 12
scheric Sep 19, 2019
23b5020
black
scheric Sep 19, 2019
720002b
style change
scheric Sep 19, 2019
a98fb2d
Black
scheric Sep 19, 2019
a95e52e
black using pip
scheric Sep 19, 2019
34d7454
fix for pylint
scheric Sep 19, 2019
1b2224b
added proper variable name
scheric Sep 19, 2019
0a45102
for loop cleanup
scheric Sep 20, 2019
cba6539
fix capitals
scheric Sep 20, 2019
064948a
Update units
scheric Sep 20, 2019
b32e740
black
scheric Sep 20, 2019
f34ddda
add check for good connection to inverter
scheric Sep 20, 2019
5ebd462
Roundig large numbers
scheric Sep 20, 2019
c82d6fd
Add myself to codeowners
scheric Sep 20, 2019
f3fdcd5
Fix layout manifest
scheric Sep 20, 2019
e65c237
Fix layout manifest
scheric Sep 20, 2019
d504ef3
Update manifest.json
scheric Sep 20, 2019
ab14af1
repair manifest layout
scheric Sep 20, 2019
0234bda
remove newline in manifest
scheric Sep 20, 2019
0d1435a
add myself to CODEOWNERS
scheric Sep 20, 2019
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 2 additions & 2 deletions homeassistant/components/solaredge_local/manifest.json
Expand Up @@ -4,5 +4,5 @@
"documentation": "",
"dependencies": [],
"codeowners": ["@drobtravels"],
scheric marked this conversation as resolved.
Show resolved Hide resolved
"requirements": ["solaredge-local==0.1.4"]
}
"requirements": ["solaredge-local==0.2.0"]
}
134 changes: 96 additions & 38 deletions homeassistant/components/solaredge_local/sensor.py
@@ -1,19 +1,20 @@
"""
Support for SolarEdge Monitoring API.

For more details about this platform, please refer to the documentation at
https://home-assistant.io/components/sensor.solaredge_local/
"""
"""Support for SolarEdge-local Monitoring API."""
import logging
from datetime import timedelta
import statistics

from requests.exceptions import HTTPError, ConnectTimeout
from solaredge_local import SolarEdge
import voluptuous as vol


from homeassistant.components.sensor import PLATFORM_SCHEMA
from homeassistant.const import CONF_IP_ADDRESS, CONF_NAME, POWER_WATT, ENERGY_WATT_HOUR
from homeassistant.const import (
CONF_IP_ADDRESS,
CONF_NAME,
POWER_WATT,
ENERGY_WATT_HOUR,
TEMP_CELSIUS,
)
import homeassistant.helpers.config_validation as cv
from homeassistant.helpers.entity import Entity
from homeassistant.util import Throttle
Expand All @@ -24,9 +25,10 @@
# Supported sensor types:
# Key: ['json_key', 'name', unit, icon]
SENSOR_TYPES = {
"lifetime_energy": [
"energyTotal",
"Lifetime energy",
"current_power": ["currentPower", "Current Power", POWER_WATT, "mdi:solar-power"],
"energy_this_month": [
"energyThisMonth",
"Energy this month",
ENERGY_WATT_HOUR,
"mdi:solar-power",
],
Expand All @@ -36,19 +38,48 @@
ENERGY_WATT_HOUR,
"mdi:solar-power",
],
"energy_this_month": [
"energyThisMonth",
"Energy this month",
ENERGY_WATT_HOUR,
"mdi:solar-power",
],
"energy_today": [
"energyToday",
"Energy today",
ENERGY_WATT_HOUR,
"mdi:solar-power",
],
"current_power": ["currentPower", "Current Power", POWER_WATT, "mdi:solar-power"],
"inverter_temperature": [
"invertertemperature",
"Inverter Temperature",
TEMP_CELSIUS,
"mdi:thermometer",
],
"lifetime_energy": [
"energyTotal",
"Lifetime energy",
ENERGY_WATT_HOUR,
"mdi:solar-power",
],
"optimizer_current": [
"optimizercurrent",
"Avrage Optimizer Current",
"A",
"mdi:solar-panel",
],
"optimizer_power": [
"optimizerpower",
"Avrage Optimizer Power",
POWER_WATT,
"mdi:solar-panel",
],
"optimizer_temperature": [
"optimizertemperature",
"Avrage Optimizer Temperature",
TEMP_CELSIUS,
"mdi:solar-panel",
],
"optimizer_voltage": [
"optimizervoltage",
"Avrage Optimizer Voltage",
"V",
"mdi:solar-panel",
],
}

PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend(
Expand All @@ -66,18 +97,16 @@ def setup_platform(hass, config, add_entities, discovery_info=None):
ip_address = config[CONF_IP_ADDRESS]
platform_name = config[CONF_NAME]

# Create new SolarEdge object to retrieve data
# Create new SolarEdge object to retrieve data.
api = SolarEdge(f"http://{ip_address}/")

# Check if api can be reached and site is active
# Check if api can be reached and site is active.
try:
status = api.get_status()

status.energy # pylint: disable=pointless-statement
_LOGGER.debug("Credentials correct and site is active")
except AttributeError:
_LOGGER.error("Missing details data in solaredge response")
_LOGGER.debug("Response is: %s", status)
_LOGGER.error("Missing details data in solaredge status")
_LOGGER.debug("Status is: %s", status)
return
except (ConnectTimeout, HTTPError):
_LOGGER.error("Could not retrieve details from SolarEdge API")
Expand Down Expand Up @@ -111,7 +140,7 @@ def __init__(self, platform_name, sensor_key, data):
@property
def name(self):
"""Return the name."""
return "{} ({})".format(self.platform_name, SENSOR_TYPES[self.sensor_key][1])
return f"{self.platform_name} ({SENSOR_TYPES[self.sensor_key][1]})"

@property
def unit_of_measurement(self):
Expand Down Expand Up @@ -147,21 +176,50 @@ def __init__(self, hass, api):
def update(self):
"""Update the data from the SolarEdge Monitoring API."""
try:
response = self.api.get_status()
_LOGGER.debug("response from SolarEdge: %s", response)
except (ConnectTimeout):
status = self.api.get_status()
_LOGGER.debug("Status from SolarEdge: %s", status)
except ConnectTimeout:
_LOGGER.error("Connection timeout, skipping update")
return
except (HTTPError):
_LOGGER.error("Could not retrieve data, skipping update")
except HTTPError:
_LOGGER.error("Could not retrieve status, skipping update")
return

try:
self.data["energyTotal"] = response.energy.total
self.data["energyThisYear"] = response.energy.thisYear
self.data["energyThisMonth"] = response.energy.thisMonth
self.data["energyToday"] = response.energy.today
self.data["currentPower"] = response.powerWatt
_LOGGER.debug("Updated SolarEdge overview data: %s", self.data)
except AttributeError:
_LOGGER.error("Missing details data in SolarEdge response")
maintenance = self.api.get_maintenance()
_LOGGER.debug("Maintenance from SolarEdge: %s", maintenance)
except ConnectTimeout:
_LOGGER.error("Connection timeout, skipping update")
return
except HTTPError:
_LOGGER.error("Could not retrieve maintenance, skipping update")
return

temperature = []
voltage = []
current = []
power = 0

for optimizer in maintenance.diagnostics.inverters.primary.optimizer:
if not optimizer.online:
continue
temperature.append(optimizer.temperature.value)
voltage.append(optimizer.inputV)
current.append(optimizer.inputC)

if not voltage:
temperature.append(0)
voltage.append(0)
current.append(0)
else:
power = statistics.mean(voltage) * statistics.mean(current)
self.data["energyTotal"] = status.energy.total
self.data["energyThisYear"] = status.energy.thisYear
self.data["energyThisMonth"] = status.energy.thisMonth
self.data["energyToday"] = status.energy.today
self.data["currentPower"] = status.powerWatt
self.data["invertertemperature"] = status.inverters.primary.temperature.value
self.data["optimizertemperature"] = statistics.mean(temperature)
self.data["optimizervoltage"] = statistics.mean(voltage)
self.data["optimizercurrent"] = statistics.mean(current)
self.data["optimizerpower"] = power
2 changes: 1 addition & 1 deletion requirements_all.txt
Expand Up @@ -1779,7 +1779,7 @@ snapcast==2.0.10
socialbladeclient==0.2

# homeassistant.components.solaredge_local
solaredge-local==0.1.4
solaredge-local==0.2.0

# homeassistant.components.solaredge
solaredge==0.0.2
Expand Down