philippelt / netatmo-api-python

Netatmo connect API python client (for Netatmo information, see https://dev.netatmo.com)
GNU General Public License v3.0
186 stars 118 forks source link

Unable to pull temperature from Netatmo weatherstation #60

Closed djerveren closed 11 months ago

djerveren commented 11 months ago

Hello there. I'm sorry if this turns out to be a support ticket, but I'm kind of at a loss here.

Before the Netatmo API auth changes, I was able to use a simple bash script to pull indoors and outdoors temperature data from my weatherstation. When that broke, I didn't have the energy to troubleshoot, so I figured I'd try to find something that had already been written, and I stumbled on this project.

I cloned your repository, created a new token in my pre-existing app, populated ~/.netatmo.credentials, installed your library with pip and made an attempt to run some of your sample scripts. The one I was interested in, in particular, was samples/simpleLastData as it appears to show the values I'm after, but when I run it, I get:

$ ./samples/simpleLastData 
Traceback (most recent call last):
  File "/home/daniel/source/netatmo-api-python/./samples/simpleLastData", line 16, in <module>
    ( devList.lastData()['internal']['Temperature'],
      ^^^^^^^^^^^^^^^^^^
  File "/home/daniel/.local/lib/python3.11/site-packages/lnetatmo.py", line 348, in lastData
    lastD[s['module_name']] = ds.copy()
          ~^^^^^^^^^^^^^^^
KeyError: 'module_name'

Sadly, I don't know anything about Python programming, so I don't even know where to start troubleshooting this, but it seems to at least authenticate properly though, because if I run the samples/printAllLastData script, it does print correct values at the top, before spitting out the traceback:

$ ./samples/printAllLastData 
Station owner :  <my@email>
Data units    :  metric

STATION : <correct street address>

Traceback (most recent call last):
  File "/home/daniel/source/netatmo-api-python/./samples/printAllLastData", line 30, in <module>
    for module, moduleData in weather.lastData(station=station, exclude=3600).items() :
                              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
TypeError: WeatherStationData.lastData() got an unexpected keyword argument 'station'

In my bash script, I was able to pull the values and populate an array with:

mapfile -t temp_data < <(curl -s --get "$stat_url" \
    -d access_token="$access_token" \
    -d device_id="$device_id" |jq -r \
    '"\(.body.devices[0].dashboard_data.Temperature)
\(.body.devices[0].modules[0].dashboard_data.Temperature)
\(.body.devices[0].modules[0].dashboard_data.temp_trend)"')

Any ideas why things are breaking with your library?

philippelt commented 11 months ago

Hello,

in the case of simpleLastData, the error means that the module name (here "internal") is unknown. This is just a name that you can define for each of your devices in the Netatmo web interface. It's easier to remember that a temperature module is named "Bedroom" rather than "76:03:24:12:56:35" 😁

You must set names for your modules in the web interface and reuse the same names in your code.

For the second example, it's related to a recent update of the library that has not yet been published to pypi. You should pick the library directly from github and test again. Sorry for the late update.

djerveren commented 11 months ago

Ah, awesome! Everything working as intended now:

$ ./samples/simpleLastData 
Current temperature (inside/outside): 21.3 / 17.1 °C

Many thanks. Close this. :)