home-assistant / core

:house_with_garden: Open source home automation that puts local control and privacy first.
https://www.home-assistant.io
Apache License 2.0
72.54k stars 30.35k forks source link

The Netatmo API returned b'{"error":{"code":21,"message":"Invalid home_id"}}' (400) #107995

Closed codyc1515 closed 5 months ago

codyc1515 commented 9 months ago

The problem

Receiving an error intermittently in the system logs. Sometimes my devices are going unavailable too. Some devices are my own and some shared from another account in a separate home. The error is happening repeatedly.

What version of Home Assistant Core has the issue?

core-2024.1.3

What was the last working version of Home Assistant Core?

No response

What type of installation are you running?

Home Assistant OS

Integration causing the issue

Netatmo

Link to integration documentation on our website

https://www.home-assistant.io/integrations/netatmo/

Diagnostics information

No response

Example YAML snippet

No response

Anything in the logs that might be useful for us?

2024-01-14 06:47:21.409 DEBUG (MainThread) [pyatmo.auth] The Netatmo API returned b'{"error":{"code":21,"message":"Invalid home_id"}}' (400)
2024-01-14 06:47:21.410 DEBUG (MainThread) [homeassistant.components.netatmo.data_handler] 400 - Bad request - Invalid home_id (21) when accessing 'https://api.netatmo.com/api/homestatus'

Additional information

No response

home-assistant[bot] commented 9 months ago

Hey there @cgtobi, mind taking a look at this issue as it has been labeled with an integration (netatmo) you are listed as a code owner for? Thanks!

Code owner commands Code owners of `netatmo` can trigger bot actions by commenting: - `@home-assistant close` Closes the issue. - `@home-assistant rename Awesome new title` Renames the issue. - `@home-assistant reopen` Reopen the issue. - `@home-assistant unassign netatmo` Removes the current integration label and assignees on the issue, add the integration domain after the command. - `@home-assistant add-label needs-more-information` Add a label (needs-more-information, problem in dependency, problem in custom component) to the issue. - `@home-assistant remove-label needs-more-information` Remove a label (needs-more-information, problem in dependency, problem in custom component) on the issue.

(message by CodeOwnersMention)


netatmo documentation netatmo source (message by IssueLinks)

codyc1515 commented 8 months ago
  1. This error is happening every 5 minutes.
  2. I have my primary home on the same Netatmo account and some devices shared to me from another home.
  3. When I am trying to access my primary home using the Netatmo developer console, I receive no API errors.
  4. I highly suspect that the Invalid home_id error is related to me having devices exposed from another home on the same account and the integration is getting confused between the two homes somewhere.
codyc1515 commented 8 months ago

107996 appears to be caused by the same issue.

codyc1515 commented 8 months ago

I had no response in over a week and, sadly, had no traction with #102751 either which would have made this a lot easier.

So, I added some more debug logging myself (including in the pyatmo library). I can now clearly see that - as I originally suspected - the issue is caused by the integration picking up the home_id from the wrong account.

2024-01-22 22:06:02.138 INFO (MainThread) [homeassistant.components.camera] Setting up netatmo.camera
2024-01-22 22:06:02.138 INFO (MainThread) [homeassistant.components.climate] Setting up netatmo.climate
2024-01-22 22:06:02.140 INFO (MainThread) [homeassistant.components.cover] Setting up netatmo.cover
2024-01-22 22:06:02.145 INFO (MainThread) [homeassistant.components.light] Setting up netatmo.light
2024-01-22 22:06:02.146 INFO (MainThread) [homeassistant.components.select] Setting up netatmo.select
2024-01-22 22:06:02.147 INFO (MainThread) [homeassistant.components.sensor] Setting up netatmo.sensor
2024-01-22 22:06:02.148 INFO (MainThread) [homeassistant.components.switch] Setting up netatmo.switch
2024-01-22 22:06:02.148 DEBUG (MainThread) [pyatmo.auth] https://api.netatmo.com/api/getpublicdata
2024-01-22 22:06:02.148 DEBUG (MainThread) [pyatmo.auth] {'lat_ne': xxx.xxx, 'lon_ne': xxx.xxx, 'lat_sw': xxx.xxx, 'lon_sw': xxx.xxx, 'filtering': 'false'}
2024-01-22 22:06:03.382 DEBUG (MainThread) [homeassistant.components.netatmo.data_handler] Publisher DeviceType.public-22038175-36e1-4188-9844-032cfae58238 added
2024-01-22 22:06:03.404 DEBUG (MainThread) [pyatmo.auth] https://api.netatmo.com/api/getstationsdata
2024-01-22 22:06:03.404 DEBUG (MainThread) [pyatmo.auth] {'get_favorites': 'true'}
2024-01-22 22:06:04.640 DEBUG (MainThread) [homeassistant.components.netatmo.data_handler] Publisher weather added
2024-01-22 22:06:04.640 DEBUG (MainThread) [pyatmo.auth] https://api.netatmo.com/api/gethomecoachsdata
2024-01-22 22:06:04.640 DEBUG (MainThread) [pyatmo.auth] None
2024-01-22 22:06:05.836 DEBUG (MainThread) [pyatmo.helpers] Server response: {'body': {'devices': [], 'user': {'mail': 'xxx@xxx.com', 'administrative': {'lang': 'en', 'reg_locale': 'en-XX', 'country': 'XX', 'unit': 0, 'windunit': 0, 'pressureunit': 0, 'feel_like_algo': 0}}}, 'status': 'ok', 'time_exec': 0.023700952529907227, 'time_server': 1705914365}
2024-01-22 22:06:05.837 DEBUG (MainThread) [homeassistant.components.netatmo.data_handler] No device data available
2024-01-22 22:06:05.837 DEBUG (MainThread) [homeassistant.components.netatmo.data_handler] Publisher air_care added
2024-01-22 22:06:05.837 DEBUG (MainThread) [pyatmo.auth] https://api.netatmo.com/api/homestatus
2024-01-22 22:06:05.837 DEBUG (MainThread) [pyatmo.auth] {'home_id': '5e20fac15eb8d115204cda90'}
2024-01-22 22:06:07.008 DEBUG (MainThread) [pyatmo.auth] The Netatmo API returned b'{"error":{"code":21,"message":"Invalid home_id"}}' (400)
2024-01-22 22:06:07.009 DEBUG (MainThread) [homeassistant.components.netatmo.data_handler] 400 - Bad request - Invalid home_id (21) when accessing 'https://api.netatmo.com/api/homestatus'
2024-01-22 22:06:07.009 DEBUG (MainThread) [homeassistant.components.netatmo.data_handler] Publisher home-5e20fac15eb8d115204cda90 added
2024-01-22 22:06:07.010 DEBUG (MainThread) [homeassistant.components.netatmo.data_handler] Publisher weather removed
2024-01-22 22:06:07.010 DEBUG (MainThread) [homeassistant.components.netatmo.data_handler] Publisher air_care removed

home_id 5e20fac15eb8d115204cda90 is my friends account. He shares some devices to my account from his home.

We need to add some robust checks so that the original accounts home_id and the shared home_id are not mixed up.

codyc1515 commented 8 months ago

You may be able to reproduce the issue with /getstationsdata of:

{
  "body": {
    "devices": [
      {
        "_id": "70:ee:50:3d:17:b0",
        "date_setup": 1623810091,
        "last_setup": 1623810091,
        "type": "NAMain",
        "last_status_store": 1705915850,
        "module_name": "Indoor",
        "firmware": 202,
        "wifi_status": 56,
        "reachable": true,
        "co2_calibrating": false,
        "data_type": [
          "Temperature",
          "CO2",
          "Humidity",
          "Noise",
          "Pressure"
        ],
        "place": {
          "altitude": 26,
          "city": "XXXXXXXXXXX",
          "country": "XX",
          "timezone": "Pacific/XXXXXXXXXX",
          "location": [
            XXX.XXXXXXXXXXXXXX,
            XXX.XXXXXXXXXXXXXX
          ]
        },
        "station_name": "XXXXXXX XXX (Indoor)",
        "home_id": "5e20fac15eb8d115204cda90",
        "home_name": "XXXXXXX XXX",
        "read_only": true,
        "dashboard_data": {
          "time_utc": 1705915847,
          "Temperature": 20.3,
          "CO2": 670,
          "Humidity": 55,
          "Noise": 48,
          "Pressure": 992.1,
          "AbsolutePressure": 989.1,
          "min_temp": 19.2,
          "max_temp": 25,
          "date_max_temp": 1705894603,
          "date_min_temp": 1705834899,
          "temp_trend": "stable",
          "pressure_trend": "down"
        },
        "modules": [
          {
            "_id": "05:00:00:08:9f:4e",
            "type": "NAModule3",
            "module_name": "Smart Rain Gauge",
            "last_setup": 1625732872,
            "data_type": [
              "Rain"
            ],
            "battery_percent": 21,
            "reachable": true,
            "firmware": 14,
            "last_message": 1705915844,
            "last_seen": 1705915844,
            "rf_status": 61,
            "battery_vp": 4254,
            "dashboard_data": {
              "time_utc": 1705915844,
              "Rain": 0,
              "sum_rain_1": 0,
              "sum_rain_24": 4
            }
          },
          {
            "_id": "02:00:00:70:57:68",
            "type": "NAModule1",
            "module_name": "Outdoor Module",
            "last_setup": 1656733978,
            "data_type": [
              "Temperature",
              "Humidity"
            ],
            "battery_percent": 58,
            "reachable": true,
            "firmware": 53,
            "last_message": 1705915844,
            "last_seen": 1705915799,
            "rf_status": 60,
            "battery_vp": 5242,
            "dashboard_data": {
              "time_utc": 1705915799,
              "Temperature": 20.9,
              "Humidity": 77,
              "min_temp": 18.2,
              "max_temp": 26.7,
              "date_max_temp": 1705896419,
              "date_min_temp": 1705834895,
              "temp_trend": "down"
            }
          }
        ]
      }
    ],
    "user": {
      "mail": "xxx@xxx.com",
      "administrative": {
        "lang": "en",
        "reg_locale": "en-XX",
        "country": "XX",
        "unit": 0,
        "windunit": 0,
        "pressureunit": 0,
        "feel_like_algo": 0
      }
    }
  },
  "status": "ok",
  "time_exec": 0.06936407089233398,
  "time_server": 1705915968
}
codyc1515 commented 8 months ago

Still an issue:

2024-02-04 13:44:57.850 DEBUG (MainThread) [pyatmo.auth] The Netatmo API returned b'{"error":{"code":21,"message":"Invalid home_id"}}' (400)
2024-02-04 13:44:57.851 DEBUG (MainThread) [homeassistant.components.netatmo.data_handler] 400 - Bad request - Invalid home_id (21) when accessing 'https://api.netatmo.com/api/homestatus'
issue-triage-workflows[bot] commented 5 months ago

There hasn't been any activity on this issue recently. Due to the high number of incoming GitHub notifications, we have to clean some of the old issues, as many of them have already been resolved with the latest updates. Please make sure to update to the latest Home Assistant version and check if that solves the issue. Let us know if that works for you by adding a comment 👍 This issue has now been marked as stale and will be closed if no further activity occurs. Thank you for your contributions.