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
73.51k stars 30.71k forks source link

RESTful sensor stops working after some time #122122

Open stohn opened 3 months ago

stohn commented 3 months ago

The problem

I use RESTful sensor to query a (HTTP-BasicAuth protected) REST service from a device in my network and it works nice... until RESTful sensor stops working (it does not show anything in "data fetched"). Sometimes the RESTful sensor works for days, sometimes only for hours. When it stopped working all following requests will always have an empty response.

When HA RESTful sensor is in the "bad state" I verified that the REST service itself is still reachable. I used curl on HA cli and got the data without any problem.

As soon as I restart REST ENTITIES in the HA developer menu, RESTful sensor starts working again... until some time later it starts to have the same problem.

I turned on debug logging:

logger:
  default: info
  logs:
    homeassistant.components.rest: debug

but there is only very limited debug information in the logs (see below).

My theory so far is that indeed the REST service might have produced an error ONCE, but for some reason the error is not cleared completely inside of RESTful sensor so all subsequent requests fail.

=> Is there anything to try to get more information for how to solve the problem or fix the bug?

Thanks in advance for looking into this and also MANY MANY thanks for this great piece of open source software.

What version of Home Assistant Core has the issue?

core-2024.7.2

What was the last working version of Home Assistant Core?

never

What type of installation are you running?

Home Assistant OS

Integration causing the issue

RESTful sensor

Link to integration documentation on our website

No response

Diagnostics information

2024-07-18 03:35:03.659 DEBUG (MainThread) [homeassistant.components.rest.data] Updating from http://192.168.169.33/api/rest/2800
2024-07-18 03:35:03.758 DEBUG (MainThread) [homeassistant.components.rest.data] Data fetched from resource: {"data": "cce40000"}
2024-07-18 03:36:03.660 DEBUG (MainThread) [homeassistant.components.rest.data] Updating from http://192.168.169.33/api/rest/2800
2024-07-18 03:36:03.759 DEBUG (MainThread) [homeassistant.components.rest.data] Data fetched from resource: {"data": "cce40000"}
2024-07-18 03:37:03.661 DEBUG (MainThread) [homeassistant.components.rest.data] Updating from http://192.168.169.33/api/rest/2800
2024-07-18 03:37:05.279 DEBUG (MainThread) [homeassistant.components.rest.data] Data fetched from resource: 
2024-07-18 03:38:03.662 DEBUG (MainThread) [homeassistant.components.rest.data] Updating from http://192.168.169.33/api/rest/2800
2024-07-18 03:38:05.280 DEBUG (MainThread) [homeassistant.components.rest.data] Data fetched from resource: 
...
2024-07-18 12:05:04.184 DEBUG (MainThread) [homeassistant.components.rest.data] Updating from http://192.168.169.33/api/rest/2800
2024-07-18 12:05:05.786 DEBUG (MainThread) [homeassistant.components.rest.data] Data fetched from resource: 
2024-07-18 12:06:04.185 DEBUG (MainThread) [homeassistant.components.rest.data] Updating from http://192.168.169.33/api/rest/2800
2024-07-18 12:06:05.789 DEBUG (MainThread) [homeassistant.components.rest.data] Data fetched from resource: 
2024-07-18 12:07:04.185 DEBUG (MainThread) [homeassistant.components.rest.data] Updating from http://192.168.169.33/api/rest/2800
2024-07-18 12:07:05.789 DEBUG (MainThread) [homeassistant.components.rest.data] Data fetched from resource: 

*RESTART OF REST SERVICES*

2024-07-18 12:07:53.208 INFO (MainThread) [homeassistant.components.sensor] Setting up rest.sensor
2024-07-18 12:07:53.209 DEBUG (MainThread) [homeassistant.components.rest.data] Updating from http://192.168.169.33/api/rest/2800
2024-07-18 12:07:53.312 DEBUG (MainThread) [homeassistant.components.rest.data] Data fetched from resource: {"data": "c6e50000"}
2024-07-18 12:08:53.315 DEBUG (MainThread) [homeassistant.components.rest.data] Updating from http://192.168.169.33/api/rest/2800
2024-07-18 12:08:53.411 DEBUG (MainThread) [homeassistant.components.rest.data] Data fetched from resource: {"data": "c6e50000"}
...

Example YAML snippet

sensor:
  - platform: rest
    name: "Water consumed"
    unique_id: judo_water_consumed
    device_class: water
    state_class: total_increasing
    scan_interval: 60
    resource: http://192.168.169.33/api/rest/2800
    method: GET
    authentication: basic
    username: "secretuser"
    password: "secretpassword"
    value_template: >-
      {% if value_json is defined %}
        {{((value_json.data[6:8] + value_json.data[4:6] + value_json.data[2:4] + value_json.data[0:2]) | int(base=16) )/1000}}
      {% else %}
        {{ states("sensor.water_consumed") }}
      {% endif %}
    unit_of_measurement: m³

Anything in the logs that might be useful for us?

The log shows the sensor was working until "2024-07-18 03:36:03.759", the next request 1 minute later from "2024-07-18 03:37:03.661" failed (nothing was changed during this time, everybody was sleeping ;-))

One observation is that usually the REST response comes in within 100 msec, the failure is triggered after 2500 msec (a timeout?) All subsequent requests fail after 1500 msec (another condition?)

Additional information

No response

home-assistant[bot] commented 3 months ago

rest documentation rest source

tomlut commented 3 months ago

Pretty much a duplicate of this: https://github.com/home-assistant/core/issues/121829

I have implemented an automation to force a reload of the rest integration to get it going again.

jprates commented 3 months ago

I'm having similar issues, please see here:

https://community.home-assistant.io/t/rest-burst-requests-on-latest-version-and-maybe-previous-one/755018/1

I don't know if I should open a new issue here or just hang on one of your issues as it seems to me the root cause must probably is the same.

What do you guys think? @stohn , @tomlut ?

ausfas commented 1 month ago

Having the same issue when calling Solax API via REST :(