Skip to content
This repository has been archived by the owner on Feb 21, 2023. It is now read-only.

Login error: Please check your username/password. #28

Closed
plaurent-dev opened this issue Apr 1, 2020 · 31 comments · Fixed by #29
Closed

Login error: Please check your username/password. #28

plaurent-dev opened this issue Apr 1, 2020 · 31 comments · Fixed by #29
Assignees

Comments

@plaurent-dev
Copy link

Hi there,

It seems i have a login error. (Tried within homeassistant and using python)

Any idea what i'm doing wrong ?

Regard,

pierre

import requests
from pylinky import LinkyClient
from pylinky.client import LOGIN_URL
import json

username = "mail"
password = "password"

client = LinkyClient(username, password)
session = requests.session()
client = LinkyClient(username, password, session=session)

try:
    client.login()
    client.fetch_data()
except BaseException as exp:
    print(exp)
finally:
    client.close_session()
print(json.dumps(client.get_data(), indent=2))
@plaurent-dev
Copy link
Author

plaurent-dev commented Apr 1, 2020

URL is https://espace-client-connexion.enedis.fr/auth/UI/Login but not longer available.
https://mon-compte.enedis.fr/auth/XUI/#login/&realm=/enedis seems to be the right one.
There is a Captcha also.

@Pirionfr Pirionfr self-assigned this Apr 1, 2020
@Pirionfr
Copy link
Owner

Pirionfr commented Apr 2, 2020

Yes the captcha will be a problem

@Quentame
Copy link
Collaborator

Quentame commented Apr 5, 2020

Hi people 😊 !

It seems that some of the recent Linky issues from Home Assistant are coming from this.

I have no issues with my account, maybe because it was created before the Enedis website refactor ... don't know.

Here to help if needed !

Will update Home Assistant if needed.

Thanks.

@Pirionfr
Copy link
Owner

Pirionfr commented Apr 5, 2020

I asked for an account in https://datahub-enedis.fr/data-connect/ . I will see if we can use it

@Quentame
Copy link
Collaborator

Quentame commented Apr 5, 2020

Me too 😜

@mixoum
Copy link

mixoum commented Apr 8, 2020

So, have you tried using this new account ?

Thks

@plaurent-dev
Copy link
Author

I did the same.
I'm not yet in production mode but i can get some datas from api.
Some examples of what i get when consuming.

@Pirionfr @Quentame,
Did you succeed on your side ?
I would like to use pyLinky in HomeAssistant but i'm stuck on how to unmarshall datas.
May i take part on this project ?

Regards,
pierre


200
[{"customer":{"customer_id":"-346421124","usage_points":[{"usage_point":{"usage_point_id":"11453290002823","usage_point_status":"com","meter_type":"AMM","usage_point_addresses":{"street":"40 rue de Penthièvre","locality":"","postal_code":"75008","insee_code":"75108","city":"Paris","country":"France","geo_points":{"latitude":"48.872452","longitude":"2.312991","altitude":"35"}}}}]}}]
"[{"customer":{"customer_id":"-346421124","usage_points":[{"usage_point":{"usage_point_id":"11453290002823","usage_point_status":"com","meter_type":"AMM","usage_point_addresses":{"street":"40 rue de Penthi\u00c3\u00a8vre","locality":"","postal_code":"75008","insee_code":"75108","city":"Paris","country":"France","geo_points":{"latitude":"48.872452","longitude":"2.312991","altitude":"35"}}}}]}}]"

CONSUMPTION_LOAD_CURVE______
200
{"meter_reading":{"usage_point_id":"11453290002823","start":"2020-04-07","end":"2020-04-08","quality":"BRUT","reading_type":{"measurement_kind":"power","unit":"W","aggregate":"average"},"interval_reading":[{"value":"247","date":"2020-04-08 00:00:00","interval_length":"PT30M","measure_type":"B"},{"value":"357","date":"2020-04-08 00:30:00","interval_length":"PT30M","measure_type":"B"},{"value":"224","date":"2020-04-08 01:00:00","interval_length":"PT30M","measure_type":"B"},{"value":"205","date":"2020-04-08 01:30:00","interval_length":"PT30M","measure_type":"B"},{"value":"469","date":"2020-04-08 02:00:00","interval_length":"PT30M","measure_type":"B"},{"value":"773","date":"2020-04-08 02:30:00","interval_length":"PT30M","measure_type":"B"},{"value":"746","date":"2020-04-08 03:00:00","interval_length":"PT30M","measure_type":"B"},{"value":"545","date":"2020-04-08 03:30:00","interval_length":"PT30M","measure_type":"B"},{"value":"600","date":"2020-04-08 04:00:00","interval_length":"PT30M","measure_type":"B"},{"value":"579","date":"2020-04-08 04:30:00","interval_length":"PT30M","measure_type":"B"},{"value":"492","date":"2020-04-08 05:00:00","interval_length":"PT30M","measure_type":"B"},{"value":"444","date":"2020-04-08 05:30:00","interval_length":"PT30M","measure_type":"B"},{"value":"397","date":"2020-04-08 06:00:00","interval_length":"PT30M","measure_type":"B"},{"value":"432","date":"2020-04-08 06:30:00","interval_length":"PT30M","measure_type":"B"},{"value":"243","date":"2020-04-08 07:00:00","interval_length":"PT30M","measure_type":"B"},{"value":"386","date":"2020-04-08 07:30:00","interval_length":"PT30M","measure_type":"B"},{"value":"435","date":"2020-04-08 08:00:00","interval_length":"PT30M","measure_type":"B"},{"value":"339","date":"2020-04-08 08:30:00","interval_length":"PT30M","measure_type":"B"},{"value":"392","date":"2020-04-08 09:00:00","interval_length":"PT30M","measure_type":"B"},{"value":"363","date":"2020-04-08 09:30:00","interval_length":"PT30M","measure_type":"B"},{"value":"209","date":"2020-04-08 10:00:00","interval_length":"PT30M","measure_type":"B"},{"value":"187","date":"2020-04-08 10:30:00","interval_length":"PT30M","measure_type":"B"},{"value":"825","date":"2020-04-08 11:00:00","interval_length":"PT30M","measure_type":"B"},{"value":"375","date":"2020-04-08 11:30:00","interval_length":"PT30M","measure_type":"B"},{"value":"323","date":"2020-04-08 12:00:00","interval_length":"PT30M","measure_type":"B"},{"value":"364","date":"2020-04-08 12:30:00","interval_length":"PT30M","measure_type":"B"},{"value":"2497","date":"2020-04-08 13:00:00","interval_length":"PT30M","measure_type":"B"},{"value":"2581","date":"2020-04-08 13:30:00","interval_length":"PT30M","measure_type":"B"},{"value":"2747","date":"2020-04-08 14:00:00","interval_length":"PT30M","measure_type":"B"},{"value":"1380","date":"2020-04-08 14:30:00","interval_length":"PT30M","measure_type":"B"},{"value":"635","date":"2020-04-08 15:00:00","interval_length":"PT30M","measure_type":"B"},{"value":"311","date":"2020-04-08 15:30:00","interval_length":"PT30M","measure_type":"B"},{"value":"271","date":"2020-04-08 16:00:00","interval_length":"PT30M","measure_type":"B"},{"value":"293","date":"2020-04-08 16:30:00","interval_length":"PT30M","measure_type":"B"},{"value":"531","date":"2020-04-08 17:00:00","interval_length":"PT30M","measure_type":"B"},{"value":"398","date":"2020-04-08 17:30:00","interval_length":"PT30M","measure_type":"B"},{"value":"330","date":"2020-04-08 18:00:00","interval_length":"PT30M","measure_type":"B"},{"value":"376","date":"2020-04-08 18:30:00","interval_length":"PT30M","measure_type":"B"},{"value":"408","date":"2020-04-08 19:00:00","interval_length":"PT30M","measure_type":"B"},{"value":"430","date":"2020-04-08 19:30:00","interval_length":"PT30M","measure_type":"B"},{"value":"217","date":"2020-04-08 20:00:00","interval_length":"PT30M","measure_type":"B"},{"value":"412","date":"2020-04-08 20:30:00","interval_length":"PT30M","measure_type":"B"},{"value":"420","date":"2020-04-08 21:00:00","interval_length":"PT30M","measure_type":"B"},{"value":"2023","date":"2020-04-08 21:30:00","interval_length":"PT30M","measure_type":"B"},{"value":"1654","date":"2020-04-08 22:00:00","interval_length":"PT30M","measure_type":"B"},{"value":"1072","date":"2020-04-08 22:30:00","interval_length":"PT30M","measure_type":"B"},{"value":"987","date":"2020-04-08 23:00:00","interval_length":"PT30M","measure_type":"B"},{"value":"353","date":"2020-04-08 23:30:00","interval_length":"PT30M","measure_type":"B"}]}}

"{"meter_reading":{"usage_point_id":"11453290002823","start":"2020-04-07","end":"2020-04-08","quality":"BRUT","reading_type":{"measurement_kind":"power","unit":"W","aggregate":"average"},"interval_reading":[{"value":"247","date":"2020-04-08 00:00:00","interval_length":"PT30M","measure_type":"B"},{"value":"357","date":"2020-04-08 00:30:00","interval_length":"PT30M","measure_type":"B"},{"value":"224","date":"2020-04-08 01:00:00","interval_length":"PT30M","measure_type":"B"},{"value":"205","date":"2020-04-08 01:30:00","interval_length":"PT30M","measure_type":"B"},{"value":"469","date":"2020-04-08 02:00:00","interval_length":"PT30M","measure_type":"B"},{"value":"773","date":"2020-04-08 02:30:00","interval_length":"PT30M","measure_type":"B"},{"value":"746","date":"2020-04-08 03:00:00","interval_length":"PT30M","measure_type":"B"},{"value":"545","date":"2020-04-08 03:30:00","interval_length":"PT30M","measure_type":"B"},{"value":"600","date":"2020-04-08 04:00:00","interval_length":"PT30M","measure_type":"B"},{"value":"579","date":"2020-04-08 04:30:00","interval_length":"PT30M","measure_type":"B"},{"value":"492","date":"2020-04-08 05:00:00","interval_length":"PT30M","measure_type":"B"},{"value":"444","date":"2020-04-08 05:30:00","interval_length":"PT30M","measure_type":"B"},{"value":"397","date":"2020-04-08 06:00:00","interval_length":"PT30M","measure_type":"B"},{"value":"432","date":"2020-04-08 06:30:00","interval_length":"PT30M","measure_type":"B"},{"value":"243","date":"2020-04-08 07:00:00","interval_length":"PT30M","measure_type":"B"},{"value":"386","date":"2020-04-08 07:30:00","interval_length":"PT30M","measure_type":"B"},{"value":"435","date":"2020-04-08 08:00:00","interval_length":"PT30M","measure_type":"B"},{"value":"339","date":"2020-04-08 08:30:00","interval_length":"PT30M","measure_type":"B"},{"value":"392","date":"2020-04-08 09:00:00","interval_length":"PT30M","measure_type":"B"},{"value":"363","date":"2020-04-08 09:30:00","interval_length":"PT30M","measure_type":"B"},{"value":"209","date":"2020-04-08 10:00:00","interval_length":"PT30M","measure_type":"B"},{"value":"187","date":"2020-04-08 10:30:00","interval_length":"PT30M","measure_type":"B"},{"value":"825","date":"2020-04-08 11:00:00","interval_length":"PT30M","measure_type":"B"},{"value":"375","date":"2020-04-08 11:30:00","interval_length":"PT30M","measure_type":"B"},{"value":"323","date":"2020-04-08 12:00:00","interval_length":"PT30M","measure_type":"B"},{"value":"364","date":"2020-04-08 12:30:00","interval_length":"PT30M","measure_type":"B"},{"value":"2497","date":"2020-04-08 13:00:00","interval_length":"PT30M","measure_type":"B"},{"value":"2581","date":"2020-04-08 13:30:00","interval_length":"PT30M","measure_type":"B"},{"value":"2747","date":"2020-04-08 14:00:00","interval_length":"PT30M","measure_type":"B"},{"value":"1380","date":"2020-04-08 14:30:00","interval_length":"PT30M","measure_type":"B"},{"value":"635","date":"2020-04-08 15:00:00","interval_length":"PT30M","measure_type":"B"},{"value":"311","date":"2020-04-08 15:30:00","interval_length":"PT30M","measure_type":"B"},{"value":"271","date":"2020-04-08 16:00:00","interval_length":"PT30M","measure_type":"B"},{"value":"293","date":"2020-04-08 16:30:00","interval_length":"PT30M","measure_type":"B"},{"value":"531","date":"2020-04-08 17:00:00","interval_length":"PT30M","measure_type":"B"},{"value":"398","date":"2020-04-08 17:30:00","interval_length":"PT30M","measure_type":"B"},{"value":"330","date":"2020-04-08 18:00:00","interval_length":"PT30M","measure_type":"B"},{"value":"376","date":"2020-04-08 18:30:00","interval_length":"PT30M","measure_type":"B"},{"value":"408","date":"2020-04-08 19:00:00","interval_length":"PT30M","measure_type":"B"},{"value":"430","date":"2020-04-08 19:30:00","interval_length":"PT30M","measure_type":"B"},{"value":"217","date":"2020-04-08 20:00:00","interval_length":"PT30M","measure_type":"B"},{"value":"412","date":"2020-04-08 20:30:00","interval_length":"PT30M","measure_type":"B"},{"value":"420","date":"2020-04-08 21:00:00","interval_length":"PT30M","measure_type":"B"},{"value":"2023","date":"2020-04-08 21:30:00","interval_length":"PT30M","measure_type":"B"},{"value":"1654","date":"2020-04-08 22:00:00","interval_length":"PT30M","measure_type":"B"},{"value":"1072","date":"2020-04-08 22:30:00","interval_length":"PT30M","measure_type":"B"},{"value":"987","date":"2020-04-08 23:00:00","interval_length":"PT30M","measure_type":"B"},{"value":"353","date":"2020-04-08 23:30:00","interval_length":"PT30M","measure_type":"B"}]}}"

CONTRACTS____________________________
200
[{"customer":{"customer_id":"-346421124","usage_points":[{"usage_point":{"usage_point_id":"11453290002823","usage_point_status":"com","meter_type":"AMM","contracts":{"segment":"C5","subscribed_power":"6 kVA","last_activation_date":"27/08/2019","distribution_tariff":"BTINFCUST","offpeak_hours":"22h00 - 06h00","contract_type":"","contract_status":"SERVC","last_distribution_tariff_change_date":"18/10/2018"}}}]}}]
"[{"customer":{"customer_id":"-346421124","usage_points":[{"usage_point":{"usage_point_id":"11453290002823","usage_point_status":"com","meter_type":"AMM","contracts":{"segment":"C5","subscribed_power":"6 kVA","last_activation_date":"27/08/2019","distribution_tariff":"BTINFCUST","offpeak_hours":"22h00 - 06h00","contract_type":"","contract_status":"SERVC","last_distribution_tariff_change_date":"18/10/2018"}}}]}}]"

CONTACT_DATA____________________________
200
[{"customer":{"customer_id":"-346421124","contact_data":{"phone":"0725133720","email":"melissa@wanadoo.fr"}}}]
"[{"customer":{"customer_id":"-346421124","contact_data":{"phone":"0725133720","email":"melissa@wanadoo.fr"}}}]"

DAILY_CONSUMPTION_________________________
200
{"meter_reading":{"usage_point_id":"11453290002823","start":"2020-04-08","end":"2020-04-08","quality":"BRUT","reading_type":{"measurement_kind":"energy","measuring_period":"P1D","unit":"Wh","aggregate":"sum"},"interval_reading":[{"value":"15638","date":"2020-04-08"}]}}
"{"meter_reading":{"usage_point_id":"11453290002823","start":"2020-04-08","end":"2020-04-08","quality":"BRUT","reading_type":{"measurement_kind":"energy","measuring_period":"P1D","unit":"Wh","aggregate":"sum"},"interval_reading":[{"value":"15638","date":"2020-04-08"}]}}"

DAILY_CONSUMPTION_MAX_POWER________________
200
{"meter_reading":{"usage_point_id":"11453290002823","start":"2020-04-08","end":"2020-04-08","quality":"BRUT","reading_type":{"measurement_kind":"power","measuring_period":"P1D","unit":"VA","aggregate":"maximum"},"interval_reading":[{"value":"2816","date":"2020-04-08 14:27:00"}]}}
"{"meter_reading":{"usage_point_id":"11453290002823","start":"2020-04-08","end":"2020-04-08","quality":"BRUT","reading_type":{"measurement_kind":"power","measuring_period":"P1D","unit":"VA","aggregate":"maximum"},"interval_reading":[{"value":"2816","date":"2020-04-08 14:27:00"}]}}"

IDENTITY____________________
200
[{"customer":{"customer_id":"-346421124","identity":{"natural_person":{"title":"Mme","firstname":"Melisandre","lastname":"Ruais"}}}}]
"[{"customer":{"customer_id":"-346421124","identity":{"natural_person":{"title":"Mme","firstname":"Melisandre","lastname":"Ruais"}}}}]"


@Pirionfr
Copy link
Owner

Pirionfr commented Apr 9, 2020

yes

@Quentame
Copy link
Collaborator

Quentame commented Apr 9, 2020

I think PR are always welcomed 😊

@Quentame
Copy link
Collaborator

Quentame commented Apr 9, 2020

Not checked yet sorry

@Pirionfr
Copy link
Owner

Pirionfr commented Apr 9, 2020

I fact getting metrics is easy. my problem is more about oauth2.
how to handle Authorisation in a lib ?

@plaurent-dev
Copy link
Author

A quick version has been made on https://github.com/plaurent-django/pyLinky.git on branch feature/enedis
Test should be valid if you have your own id/secret
Code isn't clean at all, i just wanted to poc linky.

let me know if it can help.
I'm not used to play around with github/python (this is the first time i'm trying to participate in a project) so feel free to give me some advices.

In my opinion, that's the best way to progress.

@Pirionfr
Copy link
Owner

Getting the data is not the problem here. it's the Authorization Code Grant Flow and the redirect_url that we must have.

@oncleben31
Copy link
Collaborator

For autorisation I've understood HA has add a helper for managing oauth stuff. Not my expertise but perhaps something to investigate.

@lasconic
Copy link
Contributor

I did my own try here : https://github.com/lasconic/pyLinky/tree/enedis_api
I followed HA guidelines for OAuth2 library and requests: https://developers.home-assistant.io/docs/api_lib_auth. The AbstractAuth should make it easier to integrate with HA.
Getting our hand on a client_id/secret is quite involved, not sure many people will want to do that... My implementation currently works in the sandbox only. It lacks error handling but I wanted some feedback first.

One big question. The data available through this new API seems to be significantly different than the old one... What do we want to do in this library ?

  • Make it easy to access the raw API data and then change the current interface of the library and probably change the HA module features or do aggregation in the HA module ?
  • Or do we want to make several calls and try to keep the same interface, so we don't have to change the HA module ?

@lasconic
Copy link
Contributor

lasconic commented May 1, 2020

Just added the customers v3 API.
To address @Pirionfr concerns about the Grant Flow and the redirect URL, my "main" pushes the user to copy a link to a browser, authorize the app, and paste the redirection URL to the console. I used https://localhost when I submitted the app to enedis.
Another application using the library could do something different, and use a proper webpage. I guess HA would do that.

@Pirionfr
Copy link
Owner

Pirionfr commented May 2, 2020

I think, making easy to access the raw API data and then change the current interface of the library and probably change the HA module features or do aggregation in the HA module it's a good Idea.
What do you think ?

And create a wrapper for retro compatibility, after that migrate de HA module.

@lasconic
Copy link
Contributor

lasconic commented May 2, 2020

Well... Now I discovered that you need to have a company to be able to sign the contract with Enedis to get production credentials... So "easy access" to the API becomes relative. For example, most HA users who don't use the cloud service would not be able to use the module (except if they do have a company to sign the contract).
I would be ok to keep on working on it, but I'm not sure how useful it will be for most end users. Maybe, this library should keep on scrapping or reverse engineer the private API of mon-compte.enedis.fr instead of using the limited and hard to access public API

@Pirionfr
Copy link
Owner

Pirionfr commented May 3, 2020

It will be hard to scrap site because of captcha
we need nabucasa we have no other choice.

@Quentame
Copy link
Collaborator

Quentame commented May 3, 2020

The "Netatmo" code owner talked to me about OAuth, and it's the same, he did ask to Netatmo to get production credentials with HA. I can ask him more details or maybe other HA members.

OAuth is available for non Cloud users, see https://www.home-assistant.io/blog/2019/11/22/state-of-the-union/
But is there still an other way for people who want to use the lib outside of HA ?

I would prefer using the public API since it should be maintained, robust, documented, and stable (maybe also woking the night, if you know what I mean 😉)

Also, I heard we can now have multiple Linky meter for one account ?
Is hours values are today's values or yesterday's (as the old API) ?

So I agree with @Pirionfr we shoud break the current interface of the library to be more consistent with the new API.

In the HA config flow we can make a list of linky meters to configure, and select the one we want.


Sorry, I thought I would have more time, but I am working on 3 other HA integrations right now, so not having a lot of time.

I don't think I'll help a lot here, but tell me if you want some advice about the HA integration, or updating the HA integration.

@lasconic
Copy link
Contributor

lasconic commented May 4, 2020

Is there still an other way for people who want to use the lib outside of HA ?

Yes, they will need to be a company (personne morale) and sign the Enedis contract but then they can use the lib on the production env.

multiple Linky meter for one account

Indeed, you can have multiple "usage point".

Is hours values are today's values or yesterday's (as the old API) ?

The default is now 30 minutes apparently, but they collect the data in the morning for the whole previous day. The data is always available for full days... So you only get the data from the day before..

@lasconic
Copy link
Contributor

lasconic commented May 6, 2020

I updated my branch with a LinkyAPI class and LinkyClient is now a wrapper around this class and present a similar (if possible identical) interface to the current lib. It only considers the first 'usage point' for now, and it does the data aggregation for yearly, monthly, daily, hourly.
Since I didn't use this lib before it breaks, I had to do some guessing, and so I might be wrong. Maybe @Pirionfr or @Quentame could take a look and tell me if the output looks good or not ?
If it looks good, then the HA module will just need to be updated for the authentication together with Nabu Casa.

https://gist.github.com/lasconic/e0cde0e0268e127df543fd8b67244933

@Quentame
Copy link
Collaborator

Quentame commented May 7, 2020

Linked results looks identical as current version @lasconic, cool 😉
If we should have the year on day and month, could be better. HA handles it.

Maybe you should make a PR of it ?

Could try to integrate to HA next week, or maybe you want to ?

@lasconic
Copy link
Contributor

lasconic commented May 7, 2020

PR done : #29

I don't have a HA dev environment, so be my guest :)

@Pirionfr
Copy link
Owner

Pirionfr commented May 7, 2020

Good Job

@Pirionfr Pirionfr linked a pull request May 7, 2020 that will close this issue
@Pirionfr
Copy link
Owner

Pirionfr commented May 7, 2020

Version publish on pypi V0.5.0

@Quentame
Copy link
Collaborator

Quentame commented Jun 3, 2020

Hi !

I started to implement it in HA but got issues with OAuth (a auth window is openning, then close immediatly).

Also Enedis which repond to my application modification requests in about 5 days does not help.

If anyone would like to take a look:
https://github.com/hacf-fr/home-assistant-core/tree/linky/new-api

Thanks.

@Pirionfr Pirionfr reopened this Jun 5, 2020
@Pirionfr
Copy link
Owner

Pirionfr commented Jun 9, 2020

I will

@Quentame
Copy link
Collaborator

Quentame commented Jun 9, 2020

@Quentame
Copy link
Collaborator

Quentame commented Jun 9, 2020

Let's close this issue and follow here : home-assistant/core#33634 (comment)

@Pirionfr Pirionfr closed this as completed Jun 9, 2020
@Fanlabiz78
Copy link

Hi guys, looks like you solved the linky integration issue, didn't you? (not sure I understood what you did).
I never got to make it work with the previous version, that was embedded in standard ha distribution.
Always got the authentication failure and never could make it work, whatever I could configure in the linky integration section.
In the latest ha distribs (ha 0.115+), linky: integration in configuration.yaml does not work anymore.
Do you have a plan to include your corrections in a future ha distro?
What do we have to do to implement it "manually" in between (if possible) ?

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

7 participants