call API via Python

cgoetz

Hello,

Im trying to ask my netatmo weatherstation for data using the API with a python script.

But it does not work.

Is someone using it the same way and can help me?

Thanks in advance for any help

0

Comments

8 comments

  • Comment author
    mailpublic35

    Hello,
    How the implementation of token access and refresh is implemented?
    May you share the python script?
    Phil [ just a user ]

    0
  • Comment author
    cgoetz

    Hi,

    I used this one, took the infos from dev.netatmo.com, but it doesnt work.

    import requests

    # Zugangsdaten
    client_id = 'DEIN_CLIENT_ID'
    client_secret = 'DEIN_CLIENT_SECRET'
    username = 'DEINE_NETATMO_EMAIL'
    password = 'DEIN_NETATMO_PASSWORT'

    # Authentifizieren und Token holen
    auth_url = 'https://api.netatmo.com/oauth2/token'
    auth_payload = {
        'grant_type': 'password',
        'client_id': client_id,
        'client_secret': client_secret,
        'username': username,
        'password': password,
        'scope': 'read_station'
    }

    auth_response = requests.post(auth_url, data=auth_payload)
    auth_data = auth_response.json()
    access_token = auth_data['access_token']

    # Wetterdaten abrufen
    station_url = 'https://api.netatmo.com/api/getstationsdata'
    headers = {'Authorization': f'Bearer {access_token}'}
    station_response = requests.get(station_url, headers=headers)
    station_data = station_response.json()

    # Beispiel: Temperatur ausgeben
    for device in station_data['body']['devices']:
        print("Hauptstation:", device['station_name'])
        dashboard_data = device['dashboard_data']
        print("Innen-Temperatur:", dashboard_data['Temperature'], "°C")

        for module in device['modules']:
            print(f"Modul: {module['module_name']}")
            mod_data = module['dashboard_data']
            if 'Temperature' in mod_data:
            if 'Temperature' in mod_data:
                print("Außen-Temperatur:", mod_data['Temperature'], "°C")

     

    Thanks for any help :-)

    Claude

    0
  • Comment author
    mailpublic35

    Hello Claude,

    Thanks for sharing.

    Since end of 2022, it it no more possible to obtain a token with a username and a password.
    I shared via github, what I use every day.
    - script in php to manage token  (https://github.com/Phil353556/netatmo-manage-tokens)
    - script in php to manage netatmo floodlight (https://github.com/Phil353556/netatmo-floodlight)
    I hope it can help you
    Phil

    0
  • Comment author
    cgoetz

    Dear Phil,

    I'm sorry, but I can't figure it out. Unfortunately, I'm not a programmer and have only limited knowledge of it. I can handle Python a little, but PHP isn't my thing.

    Thanks for trying, though.

    :-)

    0
  • Comment author
    mailpublic35

    Ok
    I understand
    What you can do is:
    -take the php script  (the manage token one)
    -ask  lumo.proton.me, or whatever the LLM you want;, to translate it into python
    and you're done :-)
    Phil

    0
  • Comment author
    cgoetz

    Hey,

    i will try it, thanks for your idea

    Take you informed if it works :-)

    Claude

    1
  • Comment author
    lars

    Get inspiration here. It works. 

    https://github.com/philippelt/netatmo-api-python

    0
  • Comment author
    cgoetz

    I tryied now several ways, but no one worked.

    Anyway i put my netatmo to trash and buy another product, which is more communicativ.

    Thanks for all your help.

    Br

    0

Please sign in to leave a comment.