Skip to content

Commit

Permalink
Life time energy sensor fixes
Browse files Browse the repository at this point in the history
Added checks for the life time value. Only report new data (10 min interval).
Removed 1 request that was not needed but caused HTTP errors.
  • Loading branch information
ProudElm committed Nov 8, 2022
1 parent 76aaa20 commit 9378890
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 4 deletions.
2 changes: 1 addition & 1 deletion custom_components/solaredgeoptimizers/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,5 @@
"@proudelm"
],
"iot_class": "cloud_polling",
"version": "1.1.1"
"version": "1.1.2"
}
19 changes: 17 additions & 2 deletions custom_components/solaredgeoptimizers/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@
)
import logging

from datetime import datetime, timedelta

SCAN_INTERVAL = UPDATE_DELAY

_LOGGER = logging.getLogger(__name__)
Expand All @@ -56,7 +58,6 @@ async def async_setup_entry(
"""Add an solarEdge entry."""
# Add the needed sensors to hass
client = hass.data[DOMAIN][entry.entry_id][DATA_API_CLIENT]

site = await hass.async_add_executor_job(client.requestListOfAllPanels)

_LOGGER.info("Found all information for site: %s", site.siteId)
Expand Down Expand Up @@ -177,14 +178,21 @@ def update(self):
)
_LOGGER.error("The response was: %s", response)
else:
lifetimeenergy = json.loads(self._client.getLifeTimeEnergy())
lifetimeenergy = json.loads(response)
waarde = (
float(
lifetimeenergy[str(self._paneelobject.paneel_id)][
"unscaledEnergy"
]
)
) / 1000

# weird first time after reboot value is None
if self._attr_native_value is not None:
if waarde <= self._attr_native_value:
_LOGGER.debug("No new value for life time energy found.")
# waarde = self._attr_native_value

except Exception as err:
_LOGGER.error(
"Error updating life time energy data for panel: %s",
Expand Down Expand Up @@ -227,6 +235,13 @@ def update(self):
# print(paneel_info)
# {'Current [A]': '7.47', 'Optimizer Voltage [V]': '39.75', 'Power [W]': '253.00', 'Voltage [V]': '33.88'}

# We only update the sensor when the data is 'new'
timetocheck = datetime.now() - timedelta(hours=0, minutes=10)

if paneel_info.lastmeasurement < timetocheck:

return

waarde = ""

if paneel_info is not None:
Expand Down
8 changes: 7 additions & 1 deletion custom_components/solaredgeoptimizers/solaredgeoptimizers.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
from jsonfinder import jsonfinder
import logging
from requests import Session
from datetime import datetime, timedelta

_LOGGER = logging.getLogger(__name__)

Expand Down Expand Up @@ -306,8 +307,13 @@ def __init__(self, paneelid, json_object):
self.serialnumber = json_object["serialNumber"]
self.paneel_id = paneelid
self.paneel_desciption = json_object["description"]
self.lastmeasurement = json_object["lastMeasurementDate"]
rawdate = json_object["lastMeasurementDate"]
# Tue Nov 01 16:53:41 GMT 2022
self.lastmeasurement = datetime.strptime(
rawdate, "%a %b %d %H:%M:%S GMT %Y"
)
self.model = json_object["model"]

self.manufacturer = json_object["manufacturer"]

# Waarden
Expand Down

0 comments on commit 9378890

Please sign in to comment.