-
Notifications
You must be signed in to change notification settings - Fork 4
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
Ha historical sensor (and MFA support) #9
base: main
Are you sure you want to change the base?
Conversation
Signed-off-by: Olivier Mehani <[email protected]>
…acts fixes: LeighCurran#6 Signed-off-by: Olivier Mehani <[email protected]>
Tariffs 31, 41, 61 and 62 are a wild guess, and totally untested. fixes: LeighCurran#6 some more Signed-off-by: Olivier Mehani <[email protected]>
Neither STATE_CLASS_TOTAL_INCREASING nor STATE_CLASS_MEASUREMENT work well for the ca. 9am reset that seems to happen for daily summary data. The `last_reset` time is set to whenever a value changes. This means this is liable to a bug where a value will be missed it it is the same as the previous day. Signed-off-by: Olivier Mehani <[email protected]>
52121d9
to
679547f
Compare
Signed-off-by: Olivier Mehani <[email protected]>
Signed-off-by: Olivier Mehani <[email protected]>
679547f
to
df87dec
Compare
Signed-off-by: Olivier Mehani <[email protected]>
When LeighCurran/AuroraPlusHA#9 is merged Signed-off-by: Olivier Mehani <[email protected]>
When LeighCurran/AuroraPlusHA#9 is merged Signed-off-by: Olivier Mehani <[email protected]>
Signed-off-by: Olivier Mehani <[email protected]>
The AuroraApi proxies everything to the session, or swallows the error transparently. This is not the behaviour that the Throttle wrapper expects, as it needs to use a _throttle attribute on the wrapped object. We add a special case in the proxy juuuuust for this. Signed-off-by: Olivier Mehani <[email protected]>
Signed-off-by: Olivier Mehani <[email protected]>
Signed-off-by: Olivier Mehani <[email protected]>
c715e32
to
52f80a8
Compare
@LeighCurran I'm still letting this soak on my HA instance (see #6), but I think this is now pretty much good to go. |
Hum, no... I think my Throttle handling has broken something... |
Signed-off-by: Olivier Mehani <[email protected]>
Signed-off-by: Olivier Mehani <[email protected]>
Im not sure if its my system, or if its the last commit to show only available tariffs - But I seem to have lost my tariff sensors this morning, and no amount of removing and adding the integration seems to be able to get them back. |
Dammit. Likely my changes, sorry.
I noticed that the API tends to return no data for a while for the previous day once it ticks over to the new day. That includes the tariffs.
When that's the case, the integration should refuse to start, and get retried later by HA.
Do you have something in your logs that says as much?
--
Olivier Mehani ***@***.***>
Sent from my mobile, please excuse my brevity.
|
No need to be sorry - thats the joys of testing new things! I cant see anything related to the component in the logs anywhere - Did I need to change the logging level somewhere? I tried in the config.yaml file, but that hasnt seemed to have helped - But I might have the code wrong |
I rolled back to the previous version, then tried to roll forward once the data for yesterday was available. Same thing happened where it marked all sensors apart from kilowatt hour, estimated balance and dollar value usage. |
Ok, the data's in now. It looks like it takes most of the next day before the API has the next-day data.
Try restarting your instance now, it should now have the some data, including tariffs.
I have an idea to make this more resilient. That'll require adding a feature to the AuroraPlus Python module. I'll have a go at this later today.
--
Olivier Mehani ***@***.***>
Sent from my mobile, please excuse my brevity.
|
Cool. I think you're good to go now!
I've had it running for about a week with no new changes required, so I think it's pretty solid now. The only issue seems to be data in Aurora being slow to show up (up to multiple days).
Let's see how you fare. Barring install issues that you had due to running forked code, the rest should be smooth now.
--
Olivier Mehani ***@***.***>
Sent from my mobile, please excuse my brevity.
|
Yep. All looking good so far - Thanks heaps for your help (and patience). Out of interest how far back should it be grabbing historical data? |
tl;dr: it only looks as far as the most recent day with data.
The Aurora+ API lags a bit before it has data, so it tells you whether data is available or not for each day.
If data is not available, the AuroraPlusHA historical sensors will try the day before, all the way to the latest day that has some data available. If the AuroraPlus API makes multiple days available at once (or within an hour, which is the refresh period), the integration will only look at the latest, and not go backwards any further.
The HistoricalState then only insert data that is newer than the last recorded data, and ignores older data, even if it was previously missing.
There might be a way to play further with recorder to 1) find gaps in statistics, 2) query those from the Aurora+ API and 3) backfill the data in he recorder. However, I don't think it's natively supported by the HistoricalState, so would be tricky to implement.
I concluded I could live with some occasional gaps (;
--
Olivier Mehani ***@***.***>
Sent from my mobile, please excuse my brevity.
|
Ok. @LeighCurran I think we're in a good place. I've been running this for a few weeks with no issue and have been getting data reliably from the historical sensors and into the Energy dashboard. This is still running with my patched version of AuroraPlus 1.1.6 from, as 1.5.0 didn't appear to be in the repo. The patch LeighCurran/AuroraPlus@1021685 is simple enough that I think it should be fine to cherry-pick onto 1.5.0 (give or take some automatic linting) if need be. If you're happy with merging LeighCurran/AuroraPlus#1 there, I can then point the dependency back to the next PyPi version here, and we can merge this here, too. |
Usage: 1. obtain an `access_token` following instructions at [0] 2. update the secrets to use an empty username (`''`), and the `access_token` as the password [0] https://github.com/shtrom/AuroraPlus/tree/oauth-mfa-token\#obtain-a-token Signed-off-by: Olivier Mehani <[email protected]>
@slothking87 I just pushed an interim fix to support MFA https://github.com/shtrom/AuroraPlus/tree/oauth-mfa-token to this branch. Instructions are in this commit 7e277e5 You might have to redo the dance to trash your previous state and pull a new version of the dependency library |
I feel like Im missing something very obvious - But I cant get it to work. When loading the URL mentioned in a web browser, I do get a generic error page, but with this message which makes me think Im missing something somewhere "Sorry, but we're having trouble signing you in. |
Yeah, the url should have been generated with a code challenge...
Can you show me the code you used, and the url (this one is safe to share as it's protected by the code_challenge so it's locked to your code, but feel free to edit parts out if you want)
--
Olivier Mehani ***@***.***>
Sent from my mobile, please excuse my brevity.
|
Excuse the noob questions - So the process is to run the commands as they are listed and that opens the correct link? Edit 2: So to make this work again - I update the details in the HA config file with username: '' and password being the big long string above? |
Ok, so this URL should be pasted back into the Then, yes, update your HA secrets to have |
PS: be careful about posting In this case, the secret is protected by the |
so close! I got the extra information, but getting the usual authentication error inside home assistant. How much of that final string is whats needed for the access token? Traceback (most recent call last): |
Ok, same thing here on my non-test HA deployment. Hold tight. |
You need to redo what you did there #9 (comment) to get the new version of the auroraplus lib. Ah! Here's the command to run #9 (comment) |
Ok, that didn't work. But I realised existing instances do need an update in the I also had to delete and remove and reinstall the previous install of the
You can check with
that it corresponds to the version at https://github.com/shtrom/AuroraPlus/blob/oauth-mfa-token/auroraplus/__init__.py |
Hmmm, Im still getting the same error as before with the no service agreement ID. Ill have a better play over the weekend - Im probably doing something wrong somewhere |
As usual, Aurora had a wobble just when I was testing, but it came good today, so it works on mine. If you still have the Worse case scenario, just delete the |
Bingo - That worked!!!!!! IF anyone uses supervised HA on a RPI like I do, You can run the pip commands via an add on (https://github.com/home-assistant/addons-development). Just add the command (pip install git+https://github.com/shtrom/AuroraPlus@oauth-mfa-token in this case) under the pypi option, save, then start the add on and it does the rest for you. keep an eye on the logs tab to see when its done. |
Awesome! I still need to work out how to make HA fetch and record the token, rather than having to put it in manually, but that's a good functional workaround in the meantime. |
Ok, it looks like the If so, that'll make the need for a way to refresh the token more pressing... If that's indeed something that the Aurora+ Web UI supports. Otherwise, we'll have to at least streamline the process of obtaining a new token. |
Fixes Traceback (most recent call last): File /usr/src/homeassistant/homeassistant/loader.py, line 842, in get_platform cache[full_name] = self._import_platform(platform_name) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File /usr/src/homeassistant/homeassistant/loader.py, line 859, in _import_platform return importlib.import_module(f{self.pkg_path}.{platform_name}) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File /usr/local/lib/python3.11/importlib/init.py, line 126, in import_module return _bootstrap._gcd_import(name[level:], package, level) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File , line 1204, in _gcd_import File , line 1176, in _find_and_load File , line 1147, in _find_and_load_unlocked File , line 690, in _load_unlocked File , line 940, in exec_module File , line 241, in _call_with_frames_removed File /config/custom_components/auroraplus/sensor.py, line 39, in from homeassistant_historical_sensor import ( File /usr/local/lib/python3.11/site-packages/homeassistant_historical_sensor/init.py, line 39, in raise SystemError(msg) SystemError: Running HomeAssistant 2024.1.2, Minimum required version >=2023.6.0 See [0], [1] [0] ldotlopez/ha-historical-sensor#12 [1] https://github.com/LeighCurran/AuroraPlus/pull/3\#issuecomment-1884213483 Signed-off-by: Olivier Mehani <[email protected]>
@slothking87 re: LeighCurran/AuroraPlus#3 (comment) I just updated the ha-historical-sensor as per ldotlopez/ha-historical-sensor#12, and pushed it. This should fix your issue on 2024.1.2, but you'll have to do the usual dance of trashing the old python dep to and make sure the new one is installed. |
It lasted until the 25th! Sound like a... 29 day lifetime? I'm renewing it today, so I guess we'll see on the 26th of Feb? |
(psst, have a try at #11 for a UI-based configuration of the access token). |
Fix for #6 (historical sensor), and also #10 (mfa)