watchforstock / evohome-client

Python client to access the Evohome web service
Apache License 2.0
88 stars 52 forks source link

add ability to get DHW status in evohomeclient2 #113

Closed lukewest closed 3 years ago

lukewest commented 3 years ago

Add the ability to get the status of the DHW. With (a lot of) help from @jzwack

zxdavb commented 3 years ago

Hey this is great! I'll add it to evohome-async & test it there.

lukewest commented 3 years ago

Glad you like it…. I hope it doesn’t call the Honeywell backend too many times.

The evohomeclient2 is supposed to look for OAuth credentials before trying again, but in my (very simplistic) testing it doesn’t seem to work.

I had help from Joe Zwack

L Luke West Mobile UK: +44 (0)7901 853188 Mobile NL: +31 6 10 00 16 86 Skype: luk3.w35t luke@novadrine.com

On 7 Oct 2020, at 11:30, David Bonnes notifications@github.com wrote:

Hey this is great! I'll add it to evohome-async https://github.com/zxdavb/evohome-async & test it there.

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/watchforstock/evohome-client/pull/113#issuecomment-704846413, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAA5JVZGISVZ52SZOF2QIO3SJQ7NFANCNFSM4SHAQQDA.

zxdavb commented 3 years ago

Glad you like it…. I hope it doesn’t call the Honeywell backend too many times. The evohomeclient2 is supposed to look for OAuth credentials before trying again, but in my (very simplistic) testing it doesn’t seem to work.

If the client is running, it will use a cached token (i.e. authentication), so things will be 'OK', regardless of the number of API calls (i.e. authorization).

Unless you pass a saved token to the client when you restart it, it has to get a new token (i.e. authentication).

The idea is that you save the token before you stop the client (it's an couple of instance attributes), so that you can use it next time you start the client. If the token has expired in the interim, then it's no bother to get a new one, because it won't exceed the authorization rate limits.

If you restart the client often enough, without passing it a saved token, then you'll be sure to exceed the authorization rate limit.

zxdavb commented 3 years ago

I had help from Joe Zwack

Where did he end up? We lost sight of him.

lukewest commented 3 years ago

He is at Residio. Joseph.Zwack@resideo.com

L Luke West Mobile UK: +44 (0)7901 853188 Mobile NL: +31 (0)6 10 00 16 86 Skype: luk3.w35t luke@novadrine.com

On 7 Oct 2020, at 12:34, David Bonnes notifications@github.com wrote:

 I had help from Joe Zwack

Where did he end up? We lost sight of him.

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub, or unsubscribe.

jzwack commented 3 years ago

I'm still here, everyone! I'm just busy all the time. Haha.

jzwack commented 3 years ago

The problem here wasn't the polling as much as it was the constant getting of tokens, which generates 429 errors which then generates alerts on our side. We ended up locking luke's account. Then we managed to connect.

lukewest commented 3 years ago

:-)

Me…?! Dos-ing a site…. Nah….

L Luke West Mobile UK: +44 (0)7901 853188 Mobile NL: +31 6 10 00 16 86 Skype: luk3.w35t luke@novadrine.com

On 7 Oct 2020, at 15:04, Joe Zwack notifications@github.com wrote:

The problem here wasn't the polling as much as it was the constant getting of tokens, which generates 429 errors which then generates alerts on our side. We ended up locking luke's account. Then we managed to connect.

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/watchforstock/evohome-client/pull/113#issuecomment-704958436, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAA5JV3AQUKIUSPLKQIED5LSJRYNBANCNFSM4SHAQQDA.

zxdavb commented 3 years ago

@lukewest Next time, we can show you how to re-use cached tokens - just ask!

lukewest commented 3 years ago

The repo owner needs to remove the emails from the PR on git - they contain a lot of personal info - mostly mine!

L

On 7 Oct 2020, at 17:16, David Bonnes notifications@github.com wrote:

@lukewest https://github.com/lukewest Next time, we can show you how to re-use cached tokens - just ask!

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/watchforstock/evohome-client/pull/113#issuecomment-705043724, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAA5JV7KKHJ4HEHHOLPFYM3SJSH4VANCNFSM4SHAQQDA.

zxdavb commented 3 years ago

@lukewest just edit the comments.

lukewest commented 3 years ago

Glad you like it…. I hope it doesn’t call the Honeywell backend too many times. The evohomeclient2 is supposed to look for OAuth credentials before trying again, but in my (very simplistic) testing it doesn’t seem to work.

If the client is running, it will use a cached token (i.e. authentication), so things will be 'OK', regardless of the number of API calls (i.e. authorization).

Unless you pass a saved token to the client when you restart it, it has to get a new token (i.e. authentication).

The idea is that you save the token before you stop the client (it's an couple of instance attributes), so that you can use it next time you start the client. If the token has expired in the interim, then it's no bother to get a new one, because it won't exceed the authorization rate limits.

If you restart the client often enough, without passing it a saved token, then you'll be sure to exceed the authorization rate limit.

Thanks for the info - I need to see how to do that

If I have a script which logs in and gets the hotwater status.. 1) how do I save the token 2) how do I reuse the saved token "next" time At the moment OpenHab calls the script every 5 minutes, which means I'm on the watch list and trigger the Honeywell auth connection limit

lukewest commented 3 years ago

Changed the def get_dhw(self): to def get_dhw_state(self):

lukewest commented 3 years ago

Fixed the documentation too

lukewest commented 3 years ago

Thanks for the pointers.

I added the code as you suggested and I’m still getting the problem.

Code: up = EvohomeClient(username, password) ec = EvohomeClient(username, password, refresh_token=up.refresh_token, debug=True)

dhw = ec.locations[0]._gateways[0]._control_systems[0].hotwater.get_dhw_state()

temp = dhw['temperatureStatus']['temperature'] status = dhw['stateStatus']['state'] mode = dhw['stateStatus']['mode']

print("temperature {}".format(temp)) print("status {}".format(status)) print("mode {}".format(mode))

Call 1: [09:18:55] openhabian@baldur:~/openhab2/scripts$ ./lwsmall.py DEBUG:evohomeclient2:Debug mode is explicitly enabled. DEBUG:evohomeclient2:No/Expired/Invalid access_token, re-authenticating. DEBUG:evohomeclient2:Authenticating with the refresh_token…

Call 2: Traceback (most recent call last): … evohomeclient2.AuthenticationError: Unable to obtain an Access Token, hint: {"error":"attempt_limit_exceeded"}

Call 3: [09:19:19] openhabian@baldur:~/openhab2/scripts$ ./lwsmall.py DEBUG:evohomeclient2:Debug mode is explicitly enabled. DEBUG:evohomeclient2:No/Expired/Invalid access_token, re-authenticating. DEBUG:evohomeclient2:Authenticating with the refresh_token...

So it is trying to use the token, but obviously not.

L

lukewest commented 3 years ago

David,

I did look at Home Assistant.

My automation goal is to be able to graph my energy usage in the house. 1) When my central heating system is running (I’m using EvoHome throughout). As there is nothing which provides this through an API, I need to see each zone, then use the temp vs "set temp" to determine if the central heating is running for the heating. I also want to know if the hot water is on, and its temperature is below the required temp. Plus (nice to have) is a graph of temps in each room, external temp, etc. 2) I plan to integrate a current sensor into the system so that I can measure current usage. Preferably for a number of circuits.

Then I want to add in some customisations, like “make it warmer in the study zone for two hours”

OpenHab can do this (it is very fiddly)

Can I do this with Home Assistant?

L

On 8 Oct 2020, at 09:11, David Bonnes notifications@github.com wrote:

@zxdavb commented on this pull request.

If I have a script which logs in and gets the hotwater status..

how do I save the token how do I reuse the saved token "next" time from evohomeclient2 import EvohomeClient

username = "username@gmail.com" password = "P@ssw0rd!!"

c = EvohomeClient(username, password)

d = EvohomeClient(username, password, refresh_token=c.refresh_token) In short, use the refresh token.

At the moment OpenHab calls the script every 5 minutes, which means I'm on the watch list and trigger the Honeywell auth connection limit

I can't comment for OpenHAB (I'm Home Assistant), but if their binding does not use refresh tokens / access tokens https://github.com/openhab/openhab-addons/blob/main/bundles/org.openhab.binding.evohome/src/main/java/org/openhab/binding/evohome/internal/api/ApiAccess.java, then you'll always be having difficulty.

You may not want to hear this, but evohome on Home Assistant https://www.home-assistant.io/integrations/evohome/ definitely behaves itself seems to have many more features than on OpenHAB https://www.openhab.org/addons/bindings/evohome/, including support for DHW.

I understand that Domoticz also behaves itself.

In evohomeclient2/hotwater.py https://github.com/watchforstock/evohome-client/pull/113#discussion_r501245653:

     else:
  • data = {
  • "Mode": "TemporaryOverride",
  • "State": "Off",
  • "UntilTime": until.strftime("%Y-%m-%dT%H:%M:%SZ"),
  • }
  • data = {"Mode": "TemporaryOverride",
  • "State": "Off",
  • "UntilTime": until.strftime('%Y-%m-%dT%H:%M:%SZ')} This isn't my repo, but could I suggest you pass this PR through black for formatting?

You can just use the default settings for black.

In evohomeclient2/hotwater.py https://github.com/watchforstock/evohome-client/pull/113#discussion_r501246192:

self._set_dhw(data) + +

  • def get_dhw(self):
  • """Gets the DHW status."""
  • url = (
  • "https://tccna.honeywell.com/WebAPI/emea/api/v1/"
  • "domesticHotWater/%s/status?" % self.dhwId
  • )
  • response = requests.get( url, headers=self.client._headers())
  • data = response.json()
  • return data Could you add the JSON that this returns here?

See above.

In evohomeclient2/hotwater.py https://github.com/watchforstock/evohome-client/pull/113#discussion_r501261269:

self._set_dhw(data) + +

  • def get_dhw(self): Actually, the dicts/JSON seem identical (not that there is anything wrong with that):

{ 'dhwId': '3933910', 'temperatureStatus': { 'temperature': 17.0, 'isAvailable': True }, 'stateStatus': { 'state': 'On', 'mode': 'FollowSchedule' }, 'activeFaults': [] } — You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/watchforstock/evohome-client/pull/113#pullrequestreview-504184354, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAA5JV4OWS5YJR46JWLLMPLSJVX4HANCNFSM4SHAQQDA.

zxdavb commented 3 years ago

@lukewest This thread has gone off the rails. Please tidy up your posts as a curtesy to the community (e.g. remove the duplicate text).

Everything you want is in HA. Specifically, for heat demand, please see: https://community.home-assistant.io/t/honeywell-ch-dhw-via-rf-hgi80-hgs80-includes-evohome/151584

zxdavb commented 3 years ago

Actually, I can confidently say that everything that can be had from evohome is available (or will shortly be available) in Home Assistant.

zxdavb commented 3 years ago

@watchforstock This PR, although serving some clear utility, provides no more information than that already available in Location.status()

lukewest commented 3 years ago

I've cleaned up the comments. thx L

On 8 Oct 2020, at 10:37, David Bonnes notifications@github.com wrote:

@lukewest https://github.com/lukewest This thread has gone off the rails. Please tidy up your posts as a curtesy to the community (e.g. remove the duplicate text).

Everything you want is in HA. Specifically, for heat demand, please see: https://community.home-assistant.io/t/honeywell-ch-dhw-via-rf-hgi80-hgs80-includes-evohome/151584/388 https://community.home-assistant.io/t/honeywell-ch-dhw-via-rf-hgi80-hgs80-includes-evohome/151584/388 — You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/watchforstock/evohome-client/pull/113#issuecomment-705453915, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAA5JV7XLOLDPGJL35Q77Q3SJWB6BANCNFSM4SHAQQDA.

lukewest commented 3 years ago

I feel it has merit in that it is grouped in the logical place for it - namely the DHW system,. We have setters there, I added a getter.

Your call.

L

On 8 Oct 2020, at 12:20, David Bonnes notifications@github.com wrote:

@watchforstock https://github.com/watchforstock This PR, although serving some clear utility, provides no more information than that already available in Location.status()

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/watchforstock/evohome-client/pull/113#issuecomment-705503882, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAA5JV5QL2LAIVRF7HLYH53SJWOAHANCNFSM4SHAQQDA.