chasenicholl / homebridge-weatherflow-tempest

WeatherFlow Tempest Homebridge Plugin
Apache License 2.0
15 stars 2 forks source link

Response missing "obs" data, returning last cached response #5

Closed DMBlakeley closed 1 year ago

DMBlakeley commented 1 year ago

Describe Your Problem:

Several times per day I receive the error shown in the logs below. The plugin is configured as a Child Bridge and starts without issue. Data being reported seems correct. Would like to understand how to eliminate this error.

I also have a Home-Assistant plugin also polling the Weatherflow-Tempest data.

Logs:

[2/7/2023, 6:25:26 PM] [WeatherFlow Tempest Platform] Response missing "obs" data.
[2/7/2023, 6:25:26 PM] [WeatherFlow Tempest Platform] Returning last cached response.

Plugin Config:

{
    "name": "WeatherFlow Tempest Platform",
    "token": "05d8d2db-xxxx-xxxx-xxxx-xxxxxxxxxxxx",
    "station_id": 12345,
    "interval": 20,
    "sensors": [
        {
            "name": "Tempest Temperature",
            "sensor_type": "Temperature Sensor",
            "value_key": "air_temperature"
        },
        {
            "name": "Tempest Relative Humidity",
            "sensor_type": "Humidity Sensor",
            "value_key": "relative_humidity"
        },
        {
            "name": "Tempest Light Level",
            "sensor_type": "Light Sensor",
            "value_key": "brightness"
        },
        {
            "name": "Tempest Wind Speed",
            "sensor_type": "Fan",
            "value_key": "wind_avg"
        }
    ],
    "_bridge": {
        "username": "0E:5B:xx:xx:xx:xx",
        "port": 50691
    },
    "platform": "WeatherFlowTempest"
}

Screenshots:

Environment:

DMBlakeley commented 1 year ago

Now seeing additional error:

[2/9/2023, 5:19:18 PM] [WeatherFlow Tempest Platform] TypeError: Cannot read properties of undefined (reading 'air_temperature') at TemperatureSensor.getCurrentTemperature (/usr/local/lib/node_modules/homebridge-weatherflow-tempest/src/platformAccessory.ts:43:76) at Timeout._onTimeout (/usr/local/lib/node_modules/homebridge-weatherflow-tempest/src/platformAccessory.ts:29:75) at listOnTimeout (node:internal/timers:569:17) at processTimers (node:internal/timers:512:7)

Which repeats for each of the configured sensors.

chasenicholl commented 1 year ago

The first issue happens when the WeatherFlow Tempest REST API fails to respond - it's a networking error.

  1. Your Tempest hub temporarily disconnects from WiFi and subsequently discounts from the WeatherFlow servers.
  2. Your home internet happens to briefly disconnect (which would also cause the above).
  3. The WeatherFlow Tempest API itself fails to respond for whatever reason.

You can always trying manually calling the API and confirming your station responds with the correct JSON structure. There should be a top level key called obs that contains the "observation" data for station that this plugin relies on.

curl https://swd.weatherflow.com/swd/rest/observations/station/{insert your station id} --header "Authorization: Bearer {insert your token}"

As for your second exception I'm not sure yet, I'll take a look.

DMBlakeley commented 1 year ago

Hello Chase,

Thanks for making this plugin available and the detailed response.

In my home automation setup, I believe that #3 is the most likely for producing the error. My thoughts are:

My current theory is that with two different WeatherFlow apps polling the WeatherFlow server there is a pretty good chance that they could be sampling at the same time resulting in one app being rejected.

I am in the process of verifying this theory and understand best way to address. Will get back to you with my findings.

Regards, Doug

kskenyon commented 1 year ago

I had this error. I found the token had a trailing space and that was enough to reject the request and cause the obs missing error. Check that your token is copied exactly. Working fine ever since. KevinSent from my iPadOn Feb 27, 2023, at 12:02 AM, Doug B @.***> wrote: Hello Chase, Thanks for making this plugin available and the detailed response. In my home automation setup, I believe that #3 is the most likely for producing the error. My thoughts are:

I have no indiction from the Tempest app that the PWS is going off line. I checked that the suggested curl provided the expected JSON response for the obs key. I do, however, also have have an instance of Home-Assistant running with the WeatherFlow integration.

My current theory is that with two different WeatherFlow apps polling the WeatherFlow server there is a pretty good chance that they could be sampling at the same time resulting in one app being rejected. I am in the process of verifying this theory and understand best way to address. Will get back to you with my findings. Regards, Doug

—Reply to this email directly, view it on GitHub, or unsubscribe.You are receiving this because you commented.Message ID: @.***>

DMBlakeley commented 1 year ago

@kskenyon, thanks for the suggestion. Checked and the token has no trailing space. The error occurrence is pretty random and the Tempest data as viewed through homebridge or HomeKit is correct.

DMBlakeley commented 1 year ago

Hello Chase,

I have spent quite a bit of time trying to understand these errors.

I agree with you that the Response missing "obs" data is most likely a Server error. I added a check into the axios call in the getStationObservation function call to check that the Server is online before resolving. Error still happens occasionally but is handled in a clean manner so not really a big issue.

The second undefined error is really puzzling. The best hypothesis that I have come up with is that one sampling loop which is the Observation array. In parallel there are multiple sampling loops which are updating air_temperatuer, relative_humidity, brightness and wind_avg. If the parallel loops overlap the sampling loops you find yourself in an undefined condition.

I also have a homebridge plugin (homebridge-awair2) which takes a different approach of sampling and then updating. Believe this approach would address the issue but it is a pretty big change to your coding approach. I am certainly not a software engineer by any means and like the elegance of your approach but just cannot see a straight forward way to address.

Regards, Doug

DMBlakeley commented 1 year ago

I believe I have been able to address and found additional error in the process. Will be submitting a Pull Request this week for your consideration.

Regards, Doug

chasenicholl commented 1 year ago

@DMBlakeley thanks looking forward to reviewing it!

DMBlakeley commented 1 year ago

@chasenicholl I have submitted a change request to address the runtime errors. Changes are summarized in the CHANGE.MD file which I created. The second error noted above is now being trapped. I am not 100% sure of the root cause and my changes may trigger some thought on your part. A possible issue is that getStationCurrentObservation will create a nested subroutine until retry_count is exhausted.

Something else that needs to be addressed is that deleted Accessories are not removed if you delete or rename in the config file.

Looking forward to your feedback.

Regards, Doug